在data.table中使用“点点前缀”(..)时,被警告混淆

时间:2018-11-09 14:04:50

标签: r data.table

我想对data.table中的某些列求和,并在变量中指定这些列。然后,我使用..前缀(请参阅New Features data.table 1.10.2)来选择那些列。但是,这会导致警告:

mdt <- as.data.table(mtcars)
factorsGEN <- c("disp","hp","drat")
# This works but gives the warning below
mdt[ , score := rowSums(mdt[ , ..factorsGEN])]
#Warning message:
#  In `[.data.table`(mdt, , ..factorsGEN) :
#  Both 'factorsGEN' and '..factorsGEN' exist in calling scope. Please remove 
# the '..factorsGEN' variable in calling scope for clarity.

# This does not work, results in error because factorsGEN is not found
mdt[, score := rowSums(mdt[, factorsGEN])]

我得到一个警告,我不记得第一次写代码时得到的警告,因此它可能是对data.table代码进行更新的结果。谁能告诉我如何避免警告。我不知道。

0 个答案:

没有答案