在带引号的表达式中使用data.table的。()快捷方式 [英] Using data.table's .() shortcut in quoted expressions
本文介绍了在带引号的表达式中使用data.table的。()快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些data.tables,其中包含名为 fn
的文件名。我想拆分基本名和扩展名:
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)
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 this all works fine and my question is very minor: Can I use an expression more like 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 "."
也就是说,我正在尝试交换 list()
表示。()
,就像在`[.data.table`
里面一样。
That is, I'm trying to swap list()
for .()
, as one can do inside `[.data.table`
.
我的报价
/ eval
这是一种尝试遵循 data.table FAQ 1.6中的建议。
My quote
/eval
stuff is an attempt at following recommendations in the data.table FAQ 1.6.
推荐答案
已修复
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
这篇关于在带引号的表达式中使用data.table的。()快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文