R语言实用技巧--用get函数配合dplyr包传参

使用场景,今天在做cellchat,需要提取一下几种细胞类型的id。目前的设置是这样。

R 复制代码
sce.all = seurat_obj
Idents(sce.all) = "CAFs"
celltype_sender=c("iCAF","myCAF")

如果正常写代码传参是这样

R 复制代码
sender_ids <- sce.all@meta.data %>% 
    filter(CAFs %in% celltype_sender) %>%
    rownames()

但是如果我想换一种细胞类型,CAFs就也要改,不够简洁。filter函数是不支持以下写法的,什么都筛选不出来

R 复制代码
celltype_sender_idents = "CAFs"
sender_ids <- sce.all@meta.data %>% 
    filter(celltype_sender_idents %in% celltype_sender) %>%
    rownames()

解决方案:

R 复制代码
sce.all = seurat_obj
Idents(sce.all) = "CAFs"
celltype_sender=c("iCAF","myCAF")
celltype_sender_idents = "CAFs"

sender_ids <- sce.all@meta.data %>% 
    filter(get(celltype_sender_idents) %in% celltype_sender) %>%
    rownames()

这样就可以在一开始把变量设置好,在后面优雅的传参了

相关推荐
有Li42 分钟前
通过渐进式域变换实现组织分类的无监督单域泛化文献速递/基于多模态的医学影像分割与理解
人工智能·学习·分类·数据挖掘·文献·医学生
kdxiaojie1 小时前
Linux 驱动研究 —— V4L2 (2)
linux·运维·笔记·学习
神秘的MT1 小时前
SQL Server 分页查询 ROW_NUMBER () OFFSET...FETCH游标(Cursor) 数据插入
数据库·sql·学习·c#·winform
~kiss~2 小时前
大模型的PEFT~ 参数高效微调 Parameter-Efficient Fine-Tuning
学习
minglie12 小时前
zynq中axi_dma的三个实验-第1课:PL搭建
学习
xianrenli383 小时前
Android14自动时区更新
android·学习·framework·aosp14·自动时区
MartinYeung53 小时前
[论文学习]Unsafe LLM-Based Search: AI搜索引擎安全风险的定量分析与缓解
人工智能·学习·搜索引擎
IDIOSF3 小时前
R语言 下载安装教程(附安装包)R语言4.5安装步骤(保姆级)
开发语言·其他·r语言
Biomamba生信基地3 小时前
《Nature Genetics》一作交流机会,18:00直播
生物信息学·nature·单细胞分析
LiaoWL1233 小时前
【SpringCloud合集-06】Spring Cloud Gateway网关学习笔记
笔记·学习·spring cloud