How to point to a directory in an R package?

心已入冬 提交于 2019-12-06 04:02:59

问题


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!


回答1:


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, e.g.,

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

or

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



回答2:


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.



来源:https://stackoverflow.com/questions/1886644/how-to-point-to-a-directory-in-an-r-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!