【发布时间】:2021-03-14 19:04:14
【问题描述】:
我以为我理解了 eval(parse(text = )) 但我收到了一个错误。我有一个名为 plotString 的字符串,它是使用 for 循环构造的。如果我打印出来,它看起来像这样:
plotString
[1] "emo_plot[[1]],sentiment_plot[[1]],emo_plot[[2]],sentiment_plot[[2]],emo_plot[[3]],sentiment_plot[[3]],emo_plot[[4]],sentiment_plot[[4]],emo_plot[[5]],sentiment_plot[[5]],emo_plot[[6]],sentiment_plot[[6]],emo_plot[[7]],sentiment_plot[[7]],emo_plot[[8]],sentiment_plot[[8]],emo_plot[[9]],sentiment_plot[[9]],emo_plot[[10]],sentiment_plot[[10]]"
最终目标是把它作为第一个参数放在
pairPlot <- ggarrange( eval(parse(text=plotString)) + rremove("x.text"), labels = c("A", "B", "C", "D"), ncol = 6, nrow = 4)
但只是简单地运行它
parse(text=plotString)
给出这个错误
Error in parse(text = plotString) : <text>:1:14: unexpected ','
1: emo_plot[[1]],
^
还有这个
eval(parse(text=plotString))
当然也一样
Error in parse(text = plotString) : <text>:1:14: unexpected ','
1: emo_plot[[1]],
^
还有这个
pairPlot <- ggarrange( eval(parse(text=plotString)) + rremove("x.text"), labels = c("A", "B", "C", "D"), ncol = 6, nrow = 4)
当然也一样
Error in parse(text = plotString) : <text>:1:14: unexpected ','
1: emo_plot[[1]],
^
我已经读到文本需要评估为 R 表达式,我猜 plotString 不是 R 表达式。如果这是问题所在,我怎样才能让 ggarrange() 中的加号(+)之前的条目类似于
emo_plot[[1]],sentiment_plot[[1]],emo_plot[[2]],sentiment_plot[[2]]
谢谢。
【问题讨论】:
标签: r parsing expression