Help
DescriptionHello, I am trying to render a Quarto document with My goal is to use There are related issues and PRs, but I can't make them work in my reprex (#107 #110 #169 #198 #207). ReprexHere is a minimal reprex to render the document targets::tar_reprex(
pipeline = {
lines <- c("
---
title: 'Test report'
format:
html:
embed-resources: true
---
Current wd: `{r} getwd()`
```{r}
library(ggplot2)
mtcars |>
ggplot(aes(mpg,
wt)) +
geom_point()
```")
dir.create("reports")
writeLines(lines, "reports/report.qmd")
l <- list(
tarchetypes::tar_quarto(
report_single,
"reports/report.qmd",
quiet = FALSE,
debug = TRUE,
working_directory = "reports",
output_file = "report_base.html"
)
)
l
},
run = {
targets::tar_make()
fs::dir_tree(getwd())
}
)The output: the file is rendered to the working directory, but Quarto is not able to embed the resources since the file name doesn't match (so all resources are broken): The output file tree is: If I remove the tarchetypes::tar_quarto(
report_single,
"reports/report.qmd",
quiet = FALSE,
debug = TRUE,
working_directory = "reports"
)and I obtain a fully working HTML file: Quarto fallbackThere are no issues if use {quarto} and change the working directory manually before knitting: targets::tar_dir({
lines <- c("
---
title: 'Test report'
format:
html:
embed-resources: true
---
Current wd: `{r} getwd()`
```{r}
library(ggplot2)
mtcars |>
ggplot(aes(mpg,
wt)) +
geom_point()
```")
dir.create("reports")
writeLines(lines, "reports/report.qmd")
# setting wd() manually to reports/
#
# makes: reports/report_single.html
withr::with_dir("reports", {
quarto::quarto_render(
input = "report.qmd",
output_file = "report_single.html",
quiet = FALSE,
debug = TRUE
)
})
fs::dir_tree(getwd())
fs::file_show()
readline("Press a key...")
})This is the output: and the I think that the major difference is the management of the working directory. With {targets} it doesn't persist during rendering, so the resources can't be found. With {withr} and {quarto}, the file stays close to the resources. I'm a bit puzzled on how to continue. |
Replies: 1 comment 4 replies
|
The quickest workaround is to just move the .qmd into the project directory. Moving the output file ✅I can also move the report somewhere else f I add a project:
output-dir: reportsThe HTML is correctly rendered in the project directory, self-contained, and put inside Moving the output file, parametrized ❌It doesn't work with Reprex: targets::tar_reprex(
pipeline = {
lines <- c("
---
title: 'Test report'
format:
html:
embed-resources: true
---
Current wd: `{r} getwd()`
```{r}
library(ggplot2)
mtcars |>
ggplot(aes(mpg,
wt)) +
geom_point()
```")
dir.create("reports")
writeLines(lines, "report.qmd")
linesYaml <- c("
project:
output-dir: reports
")
writeLines(linesYaml, "_quarto.yml")
l <- list(
tarchetypes::tar_quarto_rep(
report_rep_root,
"report.qmd",
quiet = FALSE,
execute_params = data.frame(
param = c("par1", "par2")
) |>
dplyr::mutate(
output_file = paste0("report_", param, ".html")
)
)
)
l
},
run = {
targets::tar_make()
fs::file_show(getwd())
fs::dir_tree(getwd())
}
)Partial output: Files: |
Thanks for the reprexes. As of 06780c4, the example from #211 (comment) should work.