【问题标题】:How to remove the enclosing brackets when bquote contains multiple expressions?当 bquote 包含多个表达式时如何删除括号?
【发布时间】:2021-01-17 00:13:13
【问题描述】:
bquote({
  A <- 4
  print(A)
})

输出:

{
    A <- 4
    print(A)
}

我该怎么做才能使输出变得简单:

A <- 4
print(A)

【问题讨论】:

  • 那不再是一个有效的对象。

标签: r metaprogramming non-standard-evaluation


【解决方案1】:

正如@G.Grothendieck 在 cmets 中所说,您无法摆脱对象中的括号,但您可以通过以下方式获得该输出:

for (i in 2:3) {
   print(b[[i]])
}

或者,矫枉过正:

class(b) <- "foo"
print.foo <- function(x) for (i in 2:length(x)) print(x[[i]])
b

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 2020-02-14
    • 2021-10-03
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多