r将字符串解释为列表元素

r将字符串解释为列表元素,r,ggplot2,R,Ggplot2,我生成一组图并将它们写入一个列表变量,如下所示 graphsListHolder <- list() 但是如果我像这样构造一个字符变量temp或者它的变体 temp <- "graphsListHolder[[3]], graphsListHolder[[5]]" 我明白了 Error in gList(list("graphsListHolder[[3]], graphsListHolder[[5]]", wrapvp = list( : only 'grobs' all

我生成一组图并将它们写入一个列表变量,如下所示

graphsListHolder <- list()
但是如果我像这样构造一个字符变量temp或者它的变体

temp <- "graphsListHolder[[3]], graphsListHolder[[5]]"
我明白了

Error in gList(list("graphsListHolder[[3]], graphsListHolder[[5]]", wrapvp = list( : 
  only 'grobs' allowed in "gList"
In addition: Warning message:
In grob$wrapvp <- vp : Coercing LHS to a list

我还尝试了evalparsetext=temp,但没有成功。

我不确定您想如何选择它们,但可以说您有一个所需元素的向量

x <- c(3,5)
试图将任意字符串转换为可执行代码通常不是一个好主意。在R中通常有更传统的选择

比如说

graphsListHolder<-Map(function(x) {
    ggplot(data.frame(x=1:10, y=x*1:10)) + geom_point(aes(x,y)) + ggtitle(x)}, 1:5)
x <- c(3,5)
grid.arrange(grobs=graphsListHolder[x])
Error in gList(list("graphsListHolder[[3]], graphsListHolder[[5]]", wrapvp = list( : 
  only 'grobs' allowed in "gList"
In addition: Warning message:
In grob$wrapvp <- vp : Coercing LHS to a list
x <- c(3,5)
grid.arrange(grobs=graphsListHolder[x])
graphsListHolder<-Map(function(x) {
    ggplot(data.frame(x=1:10, y=x*1:10)) + geom_point(aes(x,y)) + ggtitle(x)}, 1:5)
x <- c(3,5)
grid.arrange(grobs=graphsListHolder[x])