r-lib / pkgdown

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

Path issue in Quarto vignette / article #2722

Open olivroy opened 1 month ago

olivroy commented 1 month ago

I get an issue while trying to read external content in the vignettes folder with a Quarto article when building pkgdown.

Let's say my vignettes/ folder contains the following files

vignettes/article-quarto.qmd


---
title: "Title"
---

```{r}
#| label: setup
knitr::read_chunk("visual_test.R")
#| label: simple

vignette/article.Rmd

````Rmd
---
title: "Case Study: gtcars"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Case Study: gtcars}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r options, message=FALSE, warning=FALSE, include=FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(gt)
library(dplyr)
library(tibble)
knitr::read_chunk("visual_tests.R")
#| label: simple

vignettes/visual_tests.R

```r
# I would like to have those reused inside my articles / vignettes
## ----simple, echo=TRUE-------------------------------
1 + 1

I get an issue that Quarto can't find the path.

Running pkgdown::build_article("article-quarto", quiet = FALSE) errors, while it works with the Rmd article.

Error in `file()`:
! cannot open the connection
Backtrace:
  1. knitr::knit(..., tangle = TRUE)
  2. knitr:::process_file(text, output)
  5. knitr:::process_tangle(group)
  6. knitr:::tangle_block(x)
  9. knitr::read_chunk("knitr-chunks.R")
 10. xfun::read_utf8(path)
 11. base::readLines(con, encoding = "UTF-8", warn = FALSE)
 12. base::file(con, "r")
Warning message:
In file(con, "r") :
  cannot open file 'knitr-chunks.R': No such file or directory
Calls: build_articles ... eval -> read_chunk -> read_utf8 -> readLines -> file

Quitting from lines 18-19 [unnamed-chunk-2] (/var/folders/m5/623cy_fn5ts603hrw87n4_p40000gn/T//RtmpRNRUJv/file37963f0180c0.md)

I have confirmed that this is not an issue for a Rmd vignette. I am simply looking for a way to reuse things in a Quarto vignette.

Happy to provide a reprex with a self-contained directory if this isn't possible to reproduce easily

hadley commented 1 month ago

I think your issue is missing some text?

olivroy commented 1 month ago

Apologies. I edited my issue and opened a demo PR (#2723) in case that's useful.