我有一个像这样运行的代码块:
library(SummarizedExperiment)
for (i in seq_along(sce_list))
{
r <- rowData(sce_list[[i]])$use
c <- colData(sce_list[[i]])$use
tt=(sce_list[[i]])[r,c]
assign(paste0("sce_",i,".qc"),tt)
}
我想将上述代码中的对象“ sce _”,i,“。qc” 存储在列表中,并通过循环访问它们。
原则上我想做的是:
创建函数:
sceDataDim <- function(sce){
print(paste(metadata(sce)$name[1], dim(sce)[1], "genes", dim(sce)[2], "cells"))
然后使用这样的功能
sceDataDim(sce_1.qc)
上面的代码工作正常。但是,当我尝试运行循环时,会遇到麻烦:
for (i in 1:4)
sceDataDim(paste0("sce_",i,".qc"))
error
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘metadata’ for signature ‘"character"’
有什么建议吗??
编辑:
dput(sce_list)
list(<S4 object of class structure("SingleCellExperiment", package = "SingleCellExperiment")>,
<S4 object of class structure("SingleCellExperiment", package = "SingleCellExperiment")>,
<S4 object of class structure("SingleCellExperiment", package = "SingleCellExperiment")>,
<S4 object of class structure("SingleCellExperiment", package = "SingleCellExperiment")>)
答案 0 :(得分:1)
您可以将mget
与ls
及其pattern
参数一起使用:
sce_1.qc <- "foo"
sce_2.qc <- "bar"
your_list <- mget(ls(pattern="sce_\\d+\\.qc"))
your_list
# $sce_1.qc
# [1] "foo"
#
# $sce_2.qc
# [1] "bar"
\d+
匹配数字序列