如何结合do.call()plot()和expression() [英] How to combine do.call() plot() and expression()
问题描述
当我尝试将expression
与do.call
和plot
结合使用时出现错误.
I am getting an error when I try and combine using expression
with do.call
and plot
.
x <- 1:10
y <- x^1.5
我可以只使用plot
函数来获得想要的图:
I can get the plot I want by using only the plot
function:
plot(y~x,xlab=expression(paste("Concentration (",mu,"M)")))
但是,我想使用do.call
来实现我的绘图.我有很长的参数列表,它们以列表形式存储在p
中.但是,当我尝试将列表传递给do.call
时,出现以下错误:
However, I would like to implement my plot using do.call
. I have a really long list of parameters stored as a list, p
. However, when I try and pass the list to do.call
I get the following error:
p <- list(xlab=expression(paste("Concentration (",mu,"M)")))
do.call(plot,c(y~x,p))
Error in paste("Concentration (", mu, "M)") :
object 'mu' not found
我还尝试在传递给do.call
的args中明确定义公式. IE. do.call(plot,c(formula=y~x,p))
.我不明白为什么会收到错误消息-特别是因为以下内容没有给出错误消息:
I also tried defining the formula explicitly in the args passed to do.call
. ie. do.call(plot,c(formula=y~x,p))
. I do not understand why I am getting the error - especially because the following does not give an error:
do.call(plot,c(0,p))
(并在x轴上给出所需的mu字符).
(and gives the desired mu character in the xaxis).
推荐答案
do.call
在运行函数之前先评估参数;尝试将表达式包装在quote
:
do.call
evaluates the parameters before running the function; try wrapping the expression in quote
:
p <- list(xlab=quote(expression(paste("Concentration (",mu,"M)"))))
do.call("plot", c(y~x, p))
这篇关于如何结合do.call()plot()和expression()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!