将 Packrat(而不是 CRAN)中的 R 包源文件与 Travis-CI 结合使用 [英] Using R package source files in packrat (rather than CRAN) with Travis-CI

查看:21
本文介绍了将 Packrat(而不是 CRAN)中的 R 包源文件与 Travis-CI 结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 R 包,这是一个 RStudio 项目,我正在使用packrat 保留我的项目所依赖的包源的本地副本.

I'm working with an R package that is an RStudio project, and I'm using packrat to keep a local copy of the source of the packages I depend on for my project.

每次提交时,我都会 Travis-CI 检查我的 R 包,但每次 Travis 构建我的包它获取最新版本的依赖包,而不是我在 packrat/ 目录中的版本.

I've got Travis-CI checking my R package each time I make a commit, but each time Travis builds my package it gets the latest version of the dependent packages, rather than the versions I've got in my packrat/ directory.

我可以在 richfitz/wood 中看到他在他的 .travis 中似乎已经实现了这个目标.yml 文件:

I can see in richfitz/wood that he appears to have achieved this goal with this in his .travis.yml file:

env:
 USE_PACKRAT=1

和一个相当复杂的 make/packrat.mk 文件,这使得一切正常.

and a fairly complex make/packrat.mk file which makes it all work.

我的问题是配置我的项目(例如我的 .travis.yml 文件)以告诉 Travis 机器从我的 packrat/ github 上的目录,而不是 CRAN 上的目录?

My question is what is the simplest way to configure my project (e.g. my .travis.yml file) to tell the Travis machine to get the packages from my packrat/ directory on github, and not from CRAN?

推荐答案

经过多次反复试验和进一步阅读,似乎可以做到,使用 .travis.yml 这样的文件:

After much trial and error and further reading, it seems that this will do it, with a .travis.yml file like this:

# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
sudo: false
cache: packages
install:
  - R -e "0" --args --bootstrap-packrat
warnings_are_errors: false

上面文件中的关键行是:

The key lines in the above file are:

install:
  - R -e "0" --args --bootstrap-packrat

这将启动 R,并在本地 packrat 目录中构建 R 包,以便它们在 Travis 机器中可用.

This will start R, and builds the R packages in the local packrat directory so that they are available in the Travis machine.

之后,travis 将继续并尝试构建包,并且不需要联系 CRAN 来获取依赖项,因为它们已经可用(假设 packrat 按预期工作).

After that, travis will continue and attempt to build the package, and will not need contact CRAN to get the dependencies because they are already available (assuming packrat is working as expected).

我在这里发现了这个技巧:https://travis-ci.org/ChowHub/paper-pattern-similarity/builds/127262823https://github.com/rstudio/packrat/issues/158.我在这里工作:https://travis-ci.org/benmarwick/mjbtramp/builds/157747326

I discovered this trick here: https://travis-ci.org/ChowHub/paper-pattern-similarity/builds/127262823 and at https://github.com/rstudio/packrat/issues/158. I've got it working here: https://travis-ci.org/benmarwick/mjbtramp/builds/157747326

优势是我们可以在 travis 上使用我们在本地使用的完全相同的包进行构建.当我们在 travis 上构建时,我们不必从 CRAN 获取最新的包,现在我们可以更好地控制 travis 在我们的项目中构建的包版本.

The advantage of this is we can build on travis with the exact same packages that we're using locally. We don't have to get the latest packages from CRAN when we build on travis, now we can have more control of the package versions that travis builds with in our project.

缺点是在 travis 上的构建时间显着增加.我的一个项目在切换到 Packrat 后从 2-3 分钟缩短到 13-15 分钟.

The disadvantage is that the build time on travis is substantially increased. One of my projects went from 2-3 mins to 13-15 mins after switching to packrat.

更新 在下面 Noam 的问题和 Jim 的评论,看来我们可以像这样使用 cache: 缓存 Packrat 包:

UPDATE After Noam's question below and Jim's comment, it seems we can cache the packrat packages using cache: like this:

# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
sudo: false
cache:
  directories: $TRAVIS_BUILD_DIR/packrat/
  packages: true
install:
  - R -e "0" --args --bootstrap-packrat
warnings_are_errors: false

在我的用例中,这大大减少了时间,回到 1-2 分钟.

In my use-case, this has reduced the times substantially, back to 1-2 mins.

这篇关于将 Packrat(而不是 CRAN)中的 R 包源文件与 Travis-CI 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆