Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

package - inst and extdata folders in R Packaging

In the documentation, R suggests that raw data files (not Rdata nor Rda) should be placed in inst/extdata/

From the first paragraph in: 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.

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.

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?

Does everything in the /inst folder get pushed into the / of the package?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

More useful than using file.path would be to use system.file. Once your package is installed, you can grab your file like so:

fpath <- system.file("extdata", "my_raw_data.csv", package="my_package")

fpath will now have the absolute path on your HD to the file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...