简体   繁体   中英

How to point to a directory in an R package?

I am making my first attempts to write a R package. I am loading one csv file from hard drive and I am hoping to bundle up my R codes and my csv files into one package later.

My question is how can I load my csv file when my pakage is generated, I mean right now my file address is something like c:\\R\\mydirectory....\\myfile.csv but after I sent it to someone else how can I have a relative address to that file?

Feel free to correct this question if it is not clear to others!

You can put your csv files in the data directory or in inst/extdata . See the Writing R Extensions manual - Section 1.1.5 Data in packages .

To import the data you can use, eg,

R> data("achieve", package="flexclust")

or

R> read.table(system.file("data/achieve.txt", package = "flexclust"))

Look at the R help for package.skeleton : this function

automates some of the setup for a new source package. It creates directories, saves functions, data, and R code files to appropriate places, and creates skeleton help files and a 'Read-and-delete-me' file describing further steps in packaging.

The directory structure created by package.skeleton includes a data directory. If you put your data here it will be distributed with the package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM