简体   繁体   English

如何指向R包中的目录?

[英]How to point to a directory in an R package?

I am making my first attempts to write a R package. 我正在尝试编写R包。 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. 我正在从硬盘加载一个csv文件,我希望以后将我的R代码和我的csv文件捆绑到一个包中。

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? 我的问题是如何在生成pakage时加载我的csv文件,我的意思是现在我的文件地址类似于c:\\ R \\ mydirectory .... \\ myfile.csv但是在我发送给别人之后怎么可以我有一个该文件的相对地址?

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 . 您可以将csv文件放在data目录或inst/extdata See the Writing R Extensions manual - Section 1.1.5 Data in packages . 请参阅“ 编写R扩展”手册 - 第1.1.5节“数据包”

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 查看package.skeleton的R帮助:这个函数

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. 它创建目录,将函数,数据和R代码文件保存到适当的位置,并创建框架帮助文件和描述打包中进一步步骤的“读取和删除我”文件。

The directory structure created by package.skeleton includes a data directory. package.skeleton创建的目录结构包括一个data目录。 If you put your data here it will be distributed with the package. 如果您将数据放在此处,它将与包一起分发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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