r-lib / pkgdown

Generate static html documentation for an R package
https://pkgdown.r-lib.org/
Other
709 stars 325 forks source link

The package `rsconnect` is required to find published tutorials #2227

Closed nathaneastwood closed 1 year ago

nathaneastwood commented 1 year ago

Approximately a week ago, my CICD pipeline to build the pkgdown site for an internal package started to fail with the following error:

+ R -q -e pkgdown::build_site() 
> pkgdown::build_site() 
Error in find_tutorials(path(path, "inst", "tutorials")) : 
  The package `rsconnect` is required to find published tutorials 
Calls: <Anonymous> ... package_tutorials -> find_tutorials -> check_installed 
Execution halted 
script returned exit code 1

As far as I can tell, there have been no relevant updates to pkgdown itself or to rlang::check_installed(), however there are updates in rlang and specific mentions to check_installed() in the NEWS.md file for rlang. Given that rsconnect is listed in Suggests, I wouldn't expect this error to appear. For now, I have altered my pipeline to install.packages("pkgdown", dependencies = TRUE) which will ensure rsconnect is installed which "fixes" my problem.

dipterix commented 1 year ago

Same issues here. However, I don't want to publish my tutorial with rsconnect. Is there any way to fix?

dipterix commented 1 year ago

One "hack" is, in your pkgdown.yaml, replace the block pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) with the followings. This will prevent pkgdown from building tutorials

      - name: Build site
        run: |
          # pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
          ns <- asNamespace("pkgdown")
          env <- new.env(parent = ns)
          for(nm in names(ns)) {
            if(is.function(ns[[nm]]) && !inherits(ns[[nm]], "memoised")) {
              f <- ns[[nm]]
              environment(f) <- env
              env[[nm]] <- f
            }
          }
          env$build_tutorials <- function(...){}
          env$find_tutorials <- function(...){ return(character()) }
          env$build_site(new_process = FALSE, install = FALSE, pkg = ".")
          shell: Rscript {0}
maelle commented 1 year ago

@nathaneastwood a workaround would be to explicitly list the tutorials in the pkgdown config

https://github.com/r-lib/pkgdown/blob/5bb671b1a8bac8e926479868681936f7c9ee41b3/R/build-tutorials.R#L66-L67

nathaneastwood commented 1 year ago

I don't have any tutorials.

maelle commented 1 year ago

oh! even worse then, sorry.

hadley commented 1 year ago

find_tutorials() is only run if inst/tutorials or vignettes/tutorials exists, so I'd suggest not using those directory names.

dipterix commented 1 year ago

find_tutorials() is only run if inst/tutorials or vignettes/tutorials exists, so I'd suggest not using those directory names.

Gotcha. However, when I tried so, RStudio cannot find the tutorials nested within the package.

I guess learnr:::available_tutorials_for_package only checks inst/tutorials.

https://github.com/rstudio/learnr/blob/7f26e8431eaedde64076be5fbd24514816915c14/R/available_tutorials.R#L64-L69

  tutorials_dir <- system.file("tutorials", package = package)
  if (!file.exists(tutorials_dir)) {
    return(an_error(
      "No tutorials found for package: \"", package, "\""
    ))
  }

Maybe learnr could add paths (such as inst/tutorials_offline) to its search path as well? Tutorials added to this path will not be detected by pkgdown:::find_tutorials()?

Alternatively, is it possible to skip building tutorials when rsconnect is missing, or the authors choose not to publish their tutorials?

nathaneastwood commented 1 year ago

Alternatively, is it possible to skip building tutorials when rsconnect is missing, or the authors choose not to publish their tutorials?

This seems sensible to me. I discovered that a colleague of mine had actually added a folder named tutorials to the inst folder which is likely why my CICD pipeline was failing. I have had to rename this folder to avoid this issue which is fine, but I feel I shouldn't be restricted to certain folder names by a package.

hadley commented 1 year ago

@nathaneastwood pkgdown works by convention so it's a fundamental property of the package that certain folder names are out of bounds.