我有一些R代码,我想与我办公室里的其他人分享,也可以在我们的服务器上定期运行.我们都有
Windows 7桌面,服务器运行Red Hat Enterprise
Linux.
我一直在浏览文档,而且我被困住了.以下所有内容都没有完成所有必要步骤,详细说明正确的文件夹结构,或者告诉我如何构建Linux软件包,或者在Linux上构建Windows软件包.
> http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf
> http://cran.r-project.org/doc/manuals/R-admin.html#Setting-up-a-package-repository
> Creating a local R package repository
所以我的代码在git中.
$mkdir ~/daveStuff $cd ~/daveStuff $git init $git remote add origin git@davez0r.co:/opt/git/daveStuff.git $git pull origin master
现在在我的主目录中我有这个文件夹结构:
daveStuff |-- DESCRIPTION |-- R |-- stuff.R |-- exec |-- script.R
我的描述文件如下所示:
Package: daveStuff Type: Package Title: What the package does (short line) Version: 1.0 Date: 2014-02-03 Author: Who wrote it Maintainer: Who to complain to <yourfault@somewhere.net> Description: More about what it does (maybe more than one line) License: What license is it under?
我在我的一台服务器上运行apache.所以我补充说:
/var/www/html/R/src/contrib/3.0/
这正确映射到以下内容,我在那里读取我放在那里的任何文件:
http://davez0r.co/R/src/contrib/3.0/
我希望能够做到以下几点,从Windows或Linux:
> install.packages("daveStuff",repos="http://davez0r.co/R",type="source") > library(daveStuff)
所以第一步是我需要将我的库变成一个包.
$cd ~ # one under the "daveStuff" directory $R CMD build daveStuff
这会创建一个zip文件:
~/daveStuff_1.0.tar.gz
现在我将该文件复制到我的存储库位置:
$cp ~/daveStuff_1.0.tar.gz /var/www/html/R/src/contrib/3.0/
现在,如果我这样:
> install.packages("daveStuff",type="source") Warning in install.packages : unable to access index for repository http://davez0r.co/R/src/contrib
它给了我错误消息,说它无法找到包.所以我创建了一个包清单:
$cd /var/www/html/R/src/contrib # one under where I put the archive $Rscript -e 'tools::write_PACKAGES(".",type="source",subdirs=TRUE)'
这给了我一个PACKAGES文件:
Package: daveStuff Version: 1.0 MD5sum: 817bbfedeb218ce0331dd7108408c5e6 NeedsCompilation: no Path: ./3.0
现在它在我尝试加载它时有效:
> install.packages("daveStuff",type="source")
尚未解决的问题:
>我丢失了exec目录中的脚本.
>我应该将它们包装在函数中并将它们包含在库中吗?
>我应该坚持使用源包吗?
>如何在Linux上创建Windows二进制包?
在我看来,你跳过了最后一步.
一个需要
>当地包裹(你有)
>用于Linux的Tarball和用于Windows的二进制包(不确定)
>本地存储库(您已启动)
>您的存储库中的元数据(您似乎错过了)
我通过一个简单的脚本在工作中进行类似的设置(一些Windows,很多Linux):
#!/bin/bash ## see e.g. ## http://cran.r-project.org/doc/manuals/R-admin.html\ ## #Setting-up-a-package-repository ## https://stackoverflow.com/questions/2905650/creating-a-local-cran-repository ver=3.00 rsync -vu *tar.gz /SomeServer/R/src/contrib/ rsync -vu *zip /SomeServer/R/bin/windows/contrib/${ver}/ cd /SomeServer/R/src/contrib/ r -e 'tools::write_PACKAGES(".",type="source")' cd /SomeServer/R/bin/windows/contrib/${ver}/ r -e 'tools::write_PACKAGES(".",type="win.binary")'
我在这里使用littler’s r二进制文件,你也可以使用Rscript.