【发布时间】:2021-02-03 16:58:10
【问题描述】:
非常感谢您对这个小难题的任何帮助。
我正在尝试从tidyquant 包中将参数传递给tq_transmute 函数;参数的值是一个函数,但是我想将它作为字符串传递(在下面示例的范围内,我将通过 Shiny selectInput 传递它)。
我已经尝试了所有我能想到的方法将字符串“apply.quarterly”转换为apply.quarterly 接受的对象mutate_fun 参数。注释行是我失败的尝试。
最终,我想将此概念扩展到其他参数,即FUN = max 到FUN = ‘max’。
library(tidyverse)
library(tidyquant)
library(rlang)
FANG %>%
group_by(symbol) %>%
tq_transmute(select = adjusted,
mutate_fun = apply.quarterly,
# mutate_fun = sym('apply.quarterly'),
# mutate_fun = syms('apply.quarterly'),
# mutate_fun = !!sym('apply.quarterly'),
# mutate_fun = !!!sym('apply.quarterly'),
# mutate_fun = eval(parse('apply.quarterly')),
# mutate_fun = eval(substitute('apply.quarterly')),
# mutate_fun = enquo('apply.quarterly'),
# mutate_fun = expr(!!enquo('apply.quarterly')),
# mutate_fun = quo('apply.quarterly'),
# mutate_fun = enquos('apply.quarterly'),
# mutate_fun = enquote('apply.quarterly'),
# mutate_fun = quote('apply.quarterly'),
# mutate_fun = substitute('apply.quarterly'),
# mutate_fun = parse('apply.quarterly'),
# mutate_fun = parse('apply.quarterly'),
# mutate_fun = ensym('apply.quarterly'),
# mutate_fun = rlang::as_function('apply.quarterly'),
# mutate_fun = rlang::as_closure('apply.quarterly'),
# mutate_fun = rlang::as_quosure('apply.quarterly'),
# mutate_fun = rlang::as_quosure('apply.quarterly'),
# mutate_fun = enexpr('apply.quarterly'),
# mutate_fun = enexprs('apply.quarterly'),
# mutate_fun = ensym('apply.quarterly'),
# mutate_fun = ensyms('apply.quarterly'),
# mutate_fun = eval_tidy('apply.quarterly'),
# mutate_fun = exprs('apply.quarterly'),
# mutate_fun = expr_deparse('apply.quarterly'),
# mutate_fun = expr_label('apply.quarterly'),
# mutate_fun = expr_label(substitute('apply.quarterly')),
# mutate_fun = expr_label(quote('apply.quarterly')),
# mutate_fun = parse_expr('apply.quarterly'),
# mutate_fun = quasiquotation('apply.quarterly'),
# mutate_fun = quotation('apply.quarterly'),
# mutate_fun = quotation('apply.quarterly'),
FUN = max,
col_rename = "max.close")
【问题讨论】:
标签: r tidyverse symbols tidyeval tidyquant