R中的here包如何解决路径问题?

我有以下一段代码,该代码用于从名为RawData的目录中获取4个csv文件,并使用rbind合并行,效果很好

library(data.table)

setwd("C:/Users/Gunathilakel/Desktop/Vera Wrap up Analysis/Vera_Wrapup_Analysis/RawData")  

myMergedData <- 
  do.call(rbind,lapply(list.files(path = getwd()),fread))

但是,我想确保此代码在另一台计算机上可重现,并决定放弃setwd。因此,我决定使用here包并执行相同的过程

library(here)


myMergedData <- 
  do.call(rbind,lapply(list.files(path = here("RawData")),fread))

当我运行上面的脚本时,它会显示以下消息

Taking input= as a system command ('Issued and Referral Charge-2019untildec25th.csv') and a variable has been used in the expression passed to `input=`. Please use fread(cmd=...). There is a security concern if you are creating an app,and the app could have a malicious user,and the app is not running in a secure environment; e.g. the app is running as root. Please read item 5 in the NEWS file for v1.11.6 for more information and for the option to suppress this message. 'Issued' is not recognized as an internal or external command,operable program or batch file.

zhaoyue1984 回答:R中的here包如何解决路径问题?

list.files调用将返回文件名Issued and Referral Charge-2019untildec25th.csv,但不包含其路径。您需要

list.files(path = here("RawData"),full.names = TRUE)

以便您也获得路径,并且fread将能够找到文件。

本文链接:https://www.f2er.com/2838665.html

大家都在问