quarto-dev / quarto-actions

GNU General Public License v2.0
228 stars 53 forks source link

Render and Publish action fails with Error in loadNamespace(x) : there is no package called ‘jsonlite’ when code-fold: true #74

Closed rjjanse closed 1 year ago

rjjanse commented 1 year ago

Publishing a Quarto website via GitHub using a publish.yml file in directory .github\flows returns the error Error in loadNamespace(x) : there is no package called ‘jsonlite’ and then fails. The jsonlite package is seemingly needed for the html option code-fold: true (error does not occur without code-fold: true).

Rendering on my local device works fine, only publishing via GitHub and using the publish.yml file fails. A current work-around I am using is rendering locally and using render: "false" under with in the Render and Publish section of the publish.yml file.

publish.yml
on:
  workflow_dispatch:
  push:
    branches: main

name: Quarto Publish

jobs:
  build-deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Check out repository
        uses: actions/checkout@v3

      - name: Set up Quarto
        uses: quarto-dev/quarto-actions/setup@v2

      - name: Install R
        uses: r-lib/actions/setup-r@v2
        with:
          r-version: '4.2.0'

      - name: Install R Dependencies
        uses: r-lib/actions/setup-renv@v2
        with:
          cache-version: 1

      - name: Render and Publish
        uses: quarto-dev/quarto-actions/publish@v2
        with:
          target: gh-pages
          render: "false"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
_quarto.yml
project:
  type: website

website:
  sidebar:
    style: "floating"
    search: true
    contents:
        - section: "Home"
          contents:
            - index.qmd
        - section: "Getting started"
          contents:
            - r.qmd
            - rstudio.qmd

format:
  html:
    code-fold: true
    code-line-numbers: true
    code-summary: "Answer"
    theme: solar
    toc: false
    fig-cap-location: margin

editor: source
engine: knitr

execute:
  freeze: auto
Render and Publish section of GitHub actions when failing:
Run quarto-dev/quarto-actions/publish@v2
Run git config --global user.email "quarto-github-actions-publish@example.com"
From https://github.com/rjjanse/rt
 * branch            gh-pages   -> FETCH_HEAD
 * [new branch]      gh-pages   -> origin/gh-pages
Rendering for publish:

[1/3] r.qmd
[2/3] rstudio.qmd
[3/3] index.qmd
Error in loadNamespace(x) : there is no package called ‘jsonlite’
Calls: .main ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted

R installation:
  Version: 4.2.0
  Path: /opt/R/4.2.0/lib/R
  LibPaths:
    - /home/runner/work/rt/rt/renv/library/R-4.2/x86_64-pc-linux-gnu
    - /home/runner/.cache/R/renv/sandbox/R-4.2/x86_64-pc-linux-gnu/b06d72e6
  rmarkdown: (None)

The rmarkdown package is not available in this R installation.
Install with install.packages("rmarkdown")

Error: Process completed with exit code 1.
cscheid commented 1 year ago

Can you give us a link to your repository? Thanks.

rjjanse commented 1 year ago

Can you give us a link to your repository? Thanks.

Here you go: https://github.com/rjjanse/rt

cscheid commented 1 year ago

Ok, so the issue isn't about code-fold vs not, it's that you added an executable code cell, which requires the knitr engine, which requires jsonlite. In that case, your actions also need to install rmarkdown and its dependencies (which will grab jsonlite).

Your action is using renv, but I don't see an renv lockfile in your repository, and so there's no way for github to know you need rmarkdown:

      - name: Install R Dependencies
        uses: r-lib/actions/setup-renv@v2
        with:
          cache-version: 1

We explain this here: https://github.com/quarto-dev/quarto-actions/blob/main/examples/example-03-dependencies.md#using-renv-to-manage-r-packages

I'm going to go ahead and close this since I'm pretty sure that's the problem. But feel free to reopen this if the issue persists after you configure gha to install the dependencies.