首页 > 解决方案 > 在 quo() 中使用字符串并在 rlang 包中获取字符串本身内部的表达式

问题描述

使用 rlang,我想获得 quo(just_an_example) 的结果,同时输入 quo("just_an_example")。这意味着我想获得

<quosure: global>
~just_an_example

但是当 quo() 中的表达式是字符串“just_an_example”时。任何帮助,将不胜感激。

标签: rstringtidyverseevaluation

解决方案


但是,我不确定该解决方案,因为我无法完全理解该问题,但即使您在rlang::quo函数内输入带引号的字符串,您似乎也希望获得相同的结果。我正在使用rlang_0.2.0.9001版本。

你可以试试这个:

 library(rlang)

quo(!!as.symbol("just_an_example"))

或者

quo(!!sym("just_an_example"))

输出

> quo(!!sym("just_an_example"))
<quosure>
  expr: ^just_an_example
  env:  global

推荐阅读