Using data.table's .() shortcut in quoted expressions

后端 未结 1 1985
陌清茗
陌清茗 2021-01-12 05:06

I have some data.tables containing file names as a var named fn. I want to split off basename and extension:

library(data.table)
library(tools)
         


        
相关标签:
1条回答
  • 2021-01-12 06:05

    Already fixed

    library(data.table)
    library(tools)
    
    DT1 = data.table(fn = c("gah.csv", "egad.csv"))
    
    do_split_fn_dot = quote(c("name", "ext") := .(file_path_sans_ext(fn), file_ext(fn)))
    DT1[, eval(do_split_fn_dot)]
    DT1
    #         fn   name    ext
    #1:  gah.csv    gah    csv
    #2: egad.csv   egad    csv
    
    0 讨论(0)
提交回复
热议问题