解决 rgdal 包在 Travis build 上失败的问题

Resolve rgdal package failing on Travis build

我在我的 Travis 构建中成功使用了 rgdal R 包大约一年,几乎没有问题。

最近部署了 rgdal 版本 1.4-2,之前通过的构建开始失败并显示消息

In file included from inverser.c:5:0:   
/tmp/Rtmpysf7it/R.INSTALL748c54b7a89/rgdal/inst/include/projects.h:150:33: 
error: conflicting types for ‘projUV’  typedef struct { double u, v; } projUV;
                                 ^ 
In file included from inverser.c:3:0: /usr/include/proj_api.h:54:37:
 note: previous declaration of ‘projUV’ was here
     typedef struct { double u, v; } projUV;

我不确定 "old" proj_api.h 的来源以及如何在 Travis 环境中删除它。

我的 travis.yml 配置如下:

language: r
dist: trusty
sudo: false

cache:
  packages: yes

r_packages:
  - testthat
  - roxygen2
  - covr

addons:
  apt:
    packages:
      - gdal-bin
      - proj-bin
      - libgdal-dev
      - libgdal1-dev
      - libproj-dev
      - libgeos-dev
      - r-cran-ncdf4
      - libv8-3.14-dev
      - libprotobuf-dev
      - protobuf-compiler
      - libudunits2-dev
      - libnetcdf-dev
      - libjq-dev

before_install:
    - sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
    - sudo add-apt-repository -y ppa:opencpu/jq
    - sudo apt-get --yes --force-yes update -qq

after_success:
  - Rscript -e 'covr::coveralls()'

非常感谢有关如何解决此问题的任何建议

解决此问题的一种方法是使用旧版本的 rgdal。要安装特定版本的 rgdal 软件包,您可以将以下行添加到 DESCRIPTION 文件:

Remotes: cran/rgdal@1.3-9

这将安装和使用以前的版本 (1.3-9),即 1.4-2 之前发布的版本。这至少对我有用。

从这里得到灵感:https://travis-ci.community/t/travis-build-ignoring-r-package-version-in-description/2431/2

答案 2 是正确答案。我是 rgdal 维护者,并在邮件和推特上权威地回答了这个问题。当足够多的过时 PROJ 版本(4.9.3 之前,即 2016 年 9 月之前)的用户确认 1.4-3 解决了他们的问题时,我会将 1.4-3 提交给 CRAN。我不会也永远不会遵循 SO,但是如果你做了正确的事情并发布到 R-sig-geo,你就会引起我的注意。

我建议对仍在使用 PROJ 4.8.0 的任何系统施加巨大压力以进行升级。该版本于 2012 年 3 月 13 日发布,今天是它的 7 岁生日,确实值得回收它的部分。

只是为了阐明如何告诉 Travis 从 R-Forge 安装,正如 Edzer 和 Roger 所建议的那样。我相信您可以在 .travis.yml 中的任何位置添加以下内容:

repos: 
  CRAN: https://cran.rstudio.com
  rforge: http://R-Forge.R-project.org

有关详细信息,请参阅 Travis R configuration docs

或者你可以在 before_install 块中 运行 R 命令,像这样:

before_install:
  - R -e 'install.packages("rgdal", repos=c("http://R-Forge.R-project.org", "http://cran.rstudio.com"))'

如果不那么整洁,可能会更明显一些。