【发布时间】:2017-11-21 18:35:55
【问题描述】:
以下代码在我的 Mac 上运行良好,使用 CRAN R:
delta_scores <- function(df, data_var) {
# Use Hadley's new non-standard evaluation helpers to compute differences in
# the symbol passed through data_var from Session 1 to 2. Assumes an ID column
# in df that groups units of measurement.
# For the RHS:
quo_data_var <- enquo(data_var)
# For the LHS, we need yet another step (basically a string)
name_data_var <- quo_name(quo_data_var)
df %>% select(ID, Session, !!quo_data_var) %>%
# NSE spread stopped working on my windows machine!
spread(Session, !!quo_data_var) %>%
# Note use of := instead of plain = to support NSE
transmute(ID=ID, !!name_data_var := `2`-`1`)
}
test_df <- data_frame(ID=c(1,2,3,1,2,3),
Session=c(1,1,1,2,2,2),
Measure=c(1,2,3,1,1,4))
delta_scores(test_df, Measure)
但是当我在 Windows、Microsoft R Open 3.4.2、dplyr 0.7.3 上运行它时,我得到:
Error: Invalid column specification
注意:将spread 替换为spread_('Session', name_data_var) 很容易修复。有趣的是,select 调用工作正常(我的真实数据框有很多列)。我担心 dplyr 的 NSE 无法在给定环境中工作的更大问题。
查看调试器堆栈跟踪令人生畏,我决定先在这里寻求帮助。非常感谢您对正在发生的事情的任何想法或有关如何调试它的想法!
【问题讨论】:
-
在
0.7.4上工作正常 -
原来是 tidyr 的问题(这是有道理的——这是定义传播的地方)。