plot()和do.call():如果不使用'...',如何将表达式传递给图标题? [英] plot() and do.call(): How to pass expressions to plot title when '...' is used otherwise?

查看:105
本文介绍了plot()和do.call():如果不使用'...',如何将表达式传递给图标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行以下代码时,获得Error in as.graphicsAnnot(text) : could not find function "bold".我该如何解决?

When run the following code, I obtain Error in as.graphicsAnnot(text) : could not find function "bold". How can I fix this?

my.qq <- function(x, main=expression(bold(italic(F)~~"Q-Q plot")),
                  margs=list(side=3, cex=par("cex.main"), font=par("font.main"),
                  adj=par("adj"), xpd=NA), ...)
{
    plot(qnorm(ppoints(n <- length(x))), sort(x), ...)
    do.call(mtext, c(list(main), margs))
}
x <- rnorm(100)
my.qq(x)
my.qq(x, main=substitute(bold(italic(F)[N(mu.,s2.)]~~"Q-Q plot"), list(mu.=0, s2.=1))) # fails

我的目标是使用列表margs将其他参数传递给mtext().通常用...完成,但是这些参数已经传递给plot().

My goal is to use the list margs to pass additional arguments to mtext(). That's normally done with ..., but those arguments are already passed to plot().

推荐答案

substitute在这种情况下将返回语言对象,而不是表达式.表达式expressionR中宽松地使用,但是在这里看来mtext需要一个类expression的对象.

substitute in this case returns an language object, not an expression. the expression expression is used loosely in R, however here it appears that mtext needs an object of class expression.

您可以通过将substitute(...)包装在as.expression()

my.qq(x, main=as.expression(substitute(bold(italic(F)[N(mu.,s2.)]~~"Q-Q plot"), list(mu.=0, s2.=1))))

或更简单地通过将表达式传递来替换(如对mtext的常规调用所要求的那样)

or more simply by passing an expression to substitute (as would be required in a normal call to mtext)

my.qq(x, main=substitute(expression(bold(italic(F)[N(mu.,s2.)]~~"Q-Q plot")), list(mu.=0, s2.=1)))

以上两个示例都将产生

Both the examples above will produce

substitute

当参数为expression(...)时,替换和引用通常会引起混淆.结果是对表达式构造函数的调用,需要使用eval进行评估以提供实际的表达式对象.

Substituting and quoting often cause confusion when the argument is expression(...). The result is a call to the expression constructor function and needs to be evaluated with eval to give the actual expression object.

但是在这种情况下不需要eval

however in this case eval is not required

这篇关于plot()和do.call():如果不使用'...',如何将表达式传递给图标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆