I have some data.tables containing the file names as a variable called fn . I want to separate the base name and extension:
library(data.table) library(tools) DT1 = data.table(fn = c("gah.csv", "egad.csv")) DT2 = data.table(fn = c("gah.xlsx", "egad.xlsx")) DT3 = data.table(fn = c("boo.txt", "ya.foo")) do_split_fn = quote(c("name", "ext") := list(file_path_sans_ext(fn), file_ext(fn))) DT1[, eval(do_split_fn)] DT2[, eval(do_split_fn)] DT3[, eval(do_split_fn)]
So all this works great, and my question is very minor: can I use an expression similar to this?
do_split_fn_dot = quote(c("name", "ext") := .(file_path_sans_ext(fn), file_ext(fn))) DT1[, eval(do_split_fn_dot)] # Error in eval(expr, envir, enclos) : could not find function "."
That is, I'm trying to change list() to .() , How can this be done inside '[.data.table' .
My quote / eval stuff is an attempt to follow the recommendations in the Data.table 1.6 1.6 FAQ .
Frank source share