简体   繁体   中英

For loop with function (from r package) issue

I'm trying to make many plots with the 'DoHeatmap' function in the Seurat package. I wrote a loop that should insert the new parameter on each iteration, but I'm running into scoping errors, from what I understand. Here is simple reproducible example...

library(Seurat)

data("pbmc_small")

a<-rep("pbmc_small",3)

for (i in 1:length(a)) {
DoHeatmap(object = a[i])
}

Any help would be great.

Maybe this wasn't a scoping issue after all, @Roland's comment put me on the right track. Here is an option that works well enough...

data("pbmc_small")

a<-rep("pbmc_small",3)

a<-list(pbmc_small,pbmc_small)
b<-c("groups","letter.idents","RNA_snn_res.0.8")

List<-list()
for (i in 1:length(a)) {
  for (ii in 1:length(b)) {
    print(i);print(ii)
    plot=DoHeatmap(object = a[[i]],group.by=b[ii])
    List[[length(List)+1]]<-plot 
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM