r - R 打包中的 inst 和 extdata 文件夹

标签 r package

在文档中,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/

相关文章:

R Markdown : Prevent page break within code results

regex - 在 R 中使用正则表达式提取某些符号之间的文本

c++ - 在程序集名称中创建具有特殊字符的 NuGet 包

java - 包 View 中的 IntelliJ : Display . java 扩展

Python导入结构

将数值替换为组最小值

r - 如何触发 Shiny 的数据刷新?

R 以编程方式更改 IP 地址

windows - 如何在没有包管理器的情况下在 Windows 上安装 Node.js 包?

python - 无法在 conda meta.yaml 文件中指定 pip 依赖项