背景
-
我想用附加此包的包环境 without 来评估一组R函数
-
我想避免使用 package::
示例
数据
给定样本虚拟数据集:
# Data --------------------------------------------------------------------
tmpCSV <- tempfile(fileext = ".CSV", pattern = "mtcars_data_")
write.csv(x = mtcars[, 1:5], file = tmpCSV, row.names = FALSE)
# Confirm
# readLines(con = tmpCSV)[1]
阅读
库
我可以使用readr包中提供的read_csv函数来阅读它 .
library(readr)
dta <- read_csv(
file = tmpCSV,
col_types = cols(
mpg = col_double(),
cyl = col_integer(),
disp = col_integer(),
hp = col_integer(),
drat = col_double()
)
)
readr ::
也可以直接调用 readr::
函数:
# detach("package:readr", unload=TRUE)
dta <- readr::read_csv(
file = tmpCSV,
col_types = readr::cols(
mpg = readr::col_double(),
cyl = readr::col_integer(),
disp = readr::col_integer(),
hp = readr::col_integer(),
drat = readr::col_double()
)
)
问题
我想使用 eval/evalq
(如果可能的话)得到相同的结果 . 期望的语法类似于:
eval(expr = read_csv(
file = tmpCSV,
col_types = cols(
mpg = col_double(),
cyl = col_integer(),
disp = col_integer(),
hp = col_integer(),
drat = col_double()
)
),
# Naturally, the "" bit does not make sense
envir = "package::readr")
预期错误:
read_csv中的错误(file = tmpCSV,col_types = cols(mpg = col_double(),:找不到函数“read_csv”
注意事项
该任务主要涉及访问包函数而不加载包而不直接通过 :: 和 ::: 调用函数 . 概念等价物将使用 with
函数并引用没有 $
的数据框列:
with(mtcars, t.test(disp ~ am))
更好的例子:
with(mtcars, mpg[cyl == 8 & disp > 350])
1 回答
只需使用
with
?我想't understand why you don'想要使用::
.