因为setkey
对subsitute
#>setkey
function (x, ..., verbose = getOption("datatable.verbose"), physical = TRUE)
{
if (is.character(x))
stop("x may no longer be the character name of the data.table. The possibility was undocumented and has been removed.")
cols = as.character(substitute(list(...))[-1])
if (!length(cols))
cols = colnames(x)
else if (identical(cols, "NULL"))
cols = NULL
setkeyv(x, cols, verbose = verbose, physical = physical)
}
我不能将字符串变量作为colname传递给setkey
而不将其视为表达式:
data = data.table(mtcars)
key = 'qsec'
setkey(data, key)
# Error in setkeyv(x, cols, verbose = verbose, physical = physical) :
# some columns are not in the data.table: key
setkey(data, 'qsec')
# Works as expected
有解决方法吗?