我怎样才能使 c return 成为一个表达式?

How can I make c return an expression?

c 的文档声称:

"The output type is determined from the highest type of the components in the hierarchy NULL < raw < logical < integer < double < complex < character < list < expression."

但是当我给它一个表达式时,我得到的显然是一个列表:

> c(1,quote(5+2),3)
[[1]]
[1] 1

[[2]]
5 + 2

[[3]]
[1] 3

> typeof(c(1,quote(5+2),3))
[1] "list"
> is.list(c(1,quote(5+2),3))
[1] TRUE

那么 return 表达式应该用于什么输入?我试图给它提供一个函数,但这似乎属于“ 而非矢量组件(例如名称和调用)被视为单元素列表 ” 规则,因此给了我一个列表。

quote() 不是 return 一个表达式,它 return 是多种不同的类型。在您的情况下,它 return 是 "language" 类型的东西(实际上是未评估的函数调用)。使用expression(5+2)得到一个表达式,它是包裹在特殊标记列表中的语言(或其他东西)。

例如,

> c(1,expression(5+2),3)
expression(1, 5 + 2, 3)