通过 pkgdown R 将带有 sf(geos 依赖项)的包推送到 github 页面时出错

问题描述 投票:0回答:1

我正在尝试将一个包放在 github 页面上。但是,我这样做时总是遇到同样的错误。

Writing `articles/index.html`
Reading vignettes/PACKAGE_VIGNETTE.Rmd
Error in `.f()`:
! Failed to render
  'vignettes/PACKAGE_VIGNETTE.Rmd'.
✖ Quitting from lines 373-380 [Grid Based Samples]
  (VIGNETTE.Rmd)
Caused by error:
! st_concave_hull requires GEOS >= 3.11
Backtrace:

(请注意,我编造了上面的插图名称来概括问题,如果它们不匹配 - 这与错误无关)。

我能够获取预览站点,并且一切都运行正常(包括与错误相关的代码),这也通过了

rcmdcheck::rcmdcheck

我尝试了两种方法来绕过这个问题。

  1. 将 sf 包描述(我没想到会起作用,但是......)中的系统要求复制到我的包描述中。

  2. 简单地将 sf::st_concave_hull 替换为 geos 等效项。然而,这需要更多的工作来切换,而且我宁愿不添加单个功能的包

除此之外,我没有太多运气找到解决方案。 这里 Hadley 提到,由于与 sf 一起安装了多少其他软件,因此可以从某些测试中跳过 sf。但是我不确定 pkgdown::build_site() 是否允许这样做 - 我不知道它会如何。

任何帮助或见解将不胜感激。

r github-actions github-pages spatial pkgdown
1个回答
0
投票

@kadyb 和 Ezder 提供了解决方案。为了在 github 操作期间完成这项工作,需要合适的 geos 源并从源安装 sf。默认情况下,Mac 和 Windows 已处理此问题,但 Linux 还需要做更多工作。

在.github/worflows目录中,您最多需要修改2个文件,一个用于构建pkgdown网站,另一个用于测试。

R-CMD-check.yaml 需要编辑为:

# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

name: R-CMD-check.yaml

permissions: read-all

jobs:
  R-CMD-check:
    runs-on: ${{ matrix.config.os }}

    name: ${{ matrix.config.os }} (${{ matrix.config.r }})

    strategy:
      fail-fast: false
      matrix:
        config:
          - {os: macos-latest,   r: 'release'}
          - {os: windows-latest, r: 'release'}
          - {os: ubuntu-latest,   r: 'devel', http-user-agent: 'release'}
          - {os: ubuntu-latest,   r: 'release'}
          - {os: ubuntu-latest,   r: 'oldrel-1'}

    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
      R_KEEP_PKG_SOURCE: yes

    steps:
      - uses: actions/checkout@v4

      - uses: r-lib/actions/setup-pandoc@v2

      - uses: r-lib/actions/setup-r@v2
        with:
          r-version: ${{ matrix.config.r }}
          http-user-agent: ${{ matrix.config.http-user-agent }}
          use-public-rspm: true

      - uses: r-lib/actions/setup-r-dependencies@v2
        with:
          extra-packages: any::rcmdcheck
          needs: check
          
      - name: Update GEOS
        if: runner.os == 'Linux'
        run: |
          sudo apt-get install software-properties-common
          sudo add-apt-repository ppa:ubuntugis/ppa
          sudo apt-get update
          sudo apt-get install libgeos-dev

      - name: Commpile sf from source
        if: runner.os == 'Linux'
        run: install.packages("sf", type = "source", repos = "https://cran.rstudio.com/")
        shell: Rscript {0}

      - uses: r-lib/actions/check-r-package@v2
        with:
          upload-snapshots: true
          build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'

并且允许网站呈现的 pkgdown.yaml 也需要更新:

# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]
  release:
    types: [published]
  workflow_dispatch:

name: pkgdown.yaml

permissions: read-all

jobs:
  pkgdown:
    runs-on: ubuntu-latest
    # Only restrict concurrency for non-PR jobs
    concurrency:
      group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4

      - uses: r-lib/actions/setup-pandoc@v2

      - uses: r-lib/actions/setup-r@v2
        with:
          use-public-rspm: true

      - uses: r-lib/actions/setup-r-dependencies@v2
        with:
          extra-packages: any::pkgdown, local::.
          needs: website
          
      - name: Update GEOS
        if: runner.os == 'Linux'
        run: |
          sudo add-apt-repository ppa:ubuntugis/ppa
          sudo apt-get update
          sudo apt-get install libgeos-dev

      - name: Commpile sf from source
        if: runner.os == 'Linux'
        run: install.packages("sf", type = "source", repos = "https://cran.rstudio.com/")
        shell: Rscript {0}

      - name: Build site
        run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
        shell: Rscript {0}

      - name: Deploy to GitHub pages 🚀
        if: github.event_name != 'pull_request'
        uses: JamesIves/[email protected]
        with:
          clean: false
          branch: gh-pages
          folder: docs

两者发生的事情是添加了:

      - name: Update GEOS
        if: runner.os == 'Linux'
        run: |
          sudo add-apt-repository ppa:ubuntugis/ppa
          sudo apt-get update
          sudo apt-get install libgeos-dev

      - name: Commpile sf from source
        if: runner.os == 'Linux'
        run: install.packages("sf", type = "source", repos = "https://cran.rstudio.com/")
        shell: Rscript {0}

这允许合适的 GEOS 安装和源代码。

© www.soinside.com 2019 - 2024. All rights reserved.