R Packaging 中的 inst 和 extdata 文件夹 [英] inst and extdata folders in R Packaging
问题描述
在文档中,R 建议将原始数据文件(不是 Rdata 或 Rda)放在 inst/extdata/
In the documentation, R suggests that raw data files (not Rdata nor Rda) should be placed in inst/extdata/
从第一段开始:http://cran.r-project.org/doc/manuals/R-exts.html#Data-in-packages
data 子目录用于存放数据文件,要么可用通过延迟加载或使用 data() 加载.(选择由描述文件中的‘LazyData’字段:默认不做所以.)它不应该用于包所需的其他数据文件,并且约定已经成长为使用目录 inst/extdata文件.
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.
因此,我已将所有原始数据移动到此文件夹中,但是当我构建并重新加载包然后尝试使用(例如)访问函数中的数据时:
So, I have moved all of my raw data into this folder, but when I build and reload the package and then try to access the data in a function with (for example):
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+
我收到无法打开文件"错误.
I get the "cannot open file" error.
但是,看起来包目录中有一个名为 /extdata
的文件夹,其中包含文件(构建后和安装)./inst
文件夹发生了什么?
However, it does look like there is a folder called /extdata
in the package directory with the files in it (post-build and install). What's happening to the /inst
folder?
/inst 文件夹中的所有内容是否都被推送到包的 /
中?
Does everything in the /inst folder get pushed into the /
of the package?
推荐答案
你们俩都非常亲密,基本上都有这个.'Writing R Extensions' 的正式参考是:
You were both very close and essentially had this. A formal reference from 'Writing R Extensions' is:
1.1.3 包子目录
[...]
inst
子目录的内容会被递归复制到安装目录.inst
的子目录不应干扰 R 使用的那些(目前,R
、data
、demo
、exec
、libs
、man
、help
、html
和 Meta
,以及更早的版本使用 latex
、R-ex
).inst
的复制发生在 src
之后构建它的 Makefile
可以创建要安装的文件.之前R 2.12.2,文件安装在 POSIX 平台上,具有包源中的权限,因此应注意确保这些都不是太严格: R CMD build
将适合调整.要从安装中排除文件,可以指定一个顶级文件 .Rinstignore
中的排除模式列表源目录.这些模式应该是类似 Perl 的常规模式表达式(有关详细信息,请参阅 R 中 regexp
的帮助),每行一个,与文件和目录路径匹配(10),例如doc/.*[.]png$
将排除 inst/doc
中的所有PNG文件(小写)扩展名.
The contents of the inst
subdirectory will be copied recursively
to the installation directory. Subdirectories of inst
should not
interfere with those used by R (currently, R
, data
, demo
,
exec
, libs
, man
, help
, html
and Meta
, and earlier versions
used latex
, R-ex
). The copying of the inst
happens after src
is built so its Makefile
can create files to be installed. Prior to
R 2.12.2, the files were installed on POSIX platforms with the permissions in the package sources, so care should be taken to ensure
these are not too restrictive: R CMD build
will make suitable
adjustments. To exclude files from being installed, one can specify a
list of exclude patterns in file .Rinstignore
in the top-level
source directory. These patterns should be Perl-like regular
expressions (see the help for regexp
in R for the precise details),
one per line, to be matched(10) against the file and directory paths,
e.g. doc/.*[.]png$
will exclude all PNG files in inst/doc
based on
the (lower-case) extension.
这篇关于R Packaging 中的 inst 和 extdata 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!