r - 在 R 中,如何使用 quote 或 bquote 引用注释?

标签 r metaprogramming non-standard-evaluation

quote(# this is a comment)

我怎样才能做类似上面的事情?

最佳答案

quote() 在其 wholeSrcref 属性中捕获原始代码,该属性保留注释:

x <- quote({
    ## This is a comment
})

src <- attributes(x)$wholeSrcref          # <--- preserves the comment

但是,这会返回 srcref 类的对象,而不是可以传递给 eval() 的真实表达式。根据您想要执行的操作,您可能会发现 these functions for manipulating srcref objects有用。例如,

as.character(src)[2]
[1] "    ## This is a comment"

关于r - 在 R 中,如何使用 quote 或 bquote 引用注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64905464/

相关文章:

r - 为什么并行 MKL 不比 R 3.6 中的串行快?

r data.table 更新join中的多列

C++ 模板类型特征问题

r - 如何在函数中将 "everything possible"传递给 by?

r - 在 ggplot2 中的图形下方添加值表

r - 在给定条件下转置/ reshape 列中的行

clojure - 在 Clojure 代码中嵌入任意对象

c++ - 元编程中最后递归的问题

r - 在具有向量值参数的非标准评估的函数中使用 `facet_wrap`

r - dplyr NSE : Centering multiple columns in a dataframe