在文档中,R 建议将原始数据文件(不是 Rdata 或 Rda)放置在 inst/extdata/
从第一段开始:http://cran.r-project.org/doc/manuals/R-exts.html#Data-in-packages
The data subdirectory is for data files, either to be made available via lazy-loading or for loading using data(). (The choice is made by the ‘LazyData’ field in the DESCRIPTION file: the default is not to do so.) It should not be used for other data files needed by the package, and the convention has grown up to use directory inst/extdata for such files.
因此,我已将所有原始数据移至此文件夹中,但是当我构建并重新加载包,然后尝试使用(例如)访问函数中的数据时:
read.csv(file=paste(path.package("my_package"),"/inst/extdata/my_raw_data.csv",sep=""))
# .path.package is now path.package in R 3.0+
我收到“无法打开文件”错误。
但是,包目录中看起来确实有一个名为 /extdata
的文件夹,其中包含文件(构建后和安装后)。 /inst
文件夹发生了什么?
/inst 文件夹中的所有内容是否都会推送到包的 /
中?
最佳答案
比使用file.path
更有用的是使用system.file
。安装软件包后,您可以像这样获取文件:
fpath <- system.file("extdata", "my_raw_data.csv", package="my_package")
fpath
现在将拥有硬盘上该文件的绝对路径。
关于r - R 打包中的 inst 和 extdata 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13463103/