build_site() fails to build knitr::markdown vignette with css
jangorecki opened this issue · comments
This basic minimal example package
https://github.com/jangorecki/mdpkg
that passed cleanly build and check in R
is failing during pkgdown build_site()
it is using knitr::knitr vignette engine.
fyi @yihui
usethis::use_pkgdown()
✔ Setting active project to '/mdpkg'
✔ Adding '^_pkgdown\\.yml$', '^docs$', '^pkgdown$' to '.Rbuildignore'
✔ Adding 'docs' to '.gitignore'
✔ Writing '_pkgdown.yml'
• Modify '_pkgdown.yml'
sh: 1: vi: not found
Warning message:
error in running command
cat _pkgdown.yml
url: ~
template:
bootstrap: 5
pkgdown::build_site()
-- Installing package into temporary library -----------------------------------
== Building pkgdown site =======================================================
Reading from: '/mdpkg'
Writing to: '/mdpkg/docs'
-- Initialising site -----------------------------------------------------------
Copying '../usr/local/lib/R/site-library/pkgdown/BS5/assets/link.svg' to 'link.svg'
Copying '../usr/local/lib/R/site-library/pkgdown/BS5/assets/pkgdown.js' to 'pkgdown.js'
-- Building home ---------------------------------------------------------------
Writing 'authors.html'
Writing '404.html'
-- Building function reference -------------------------------------------------
Writing 'reference/index.html'
Reading 'man/hello.Rd'
Writing 'reference/hello.html'
-- Building articles -----------------------------------------------------------
Writing 'articles/index.html'
Reading 'vignettes/vign.Rmd'
-- RMarkdown error -------------------------------------------------------------
--------------------------------------------------------------------------------
Error:
! in callr subprocess.
Caused by error in `map(.x, .f, ..., .progress = .progress)`:
! In index: 1.
ℹ See `$stdout` for standard output.
Type .Last.error to see the more details.
.Last.error
<callr_error/rlib_error_3_0/rlib_error/error>
Error:
! in callr subprocess.
Caused by error in `map(.x, .f, ..., .progress = .progress)`:
! In index: 1.
ℹ See `$stdout` for standard output.
---
Backtrace:
1. pkgdown::build_site()
2. pkgdown:::build_site_external(pkg = pkg, examples = examples, run_dont_run = run_dont_run, …
3. callr::r(function(..., cli_colors, pkgdown_internet) { …
4. callr:::get_result(output = out, options)
5. callr:::throw(callr_remote_error(remerr, output), parent = fix_msg(remerr[[3]]))
---
Subprocess backtrace:
1. pkgdown::build_site(...)
2. pkgdown:::build_site_local(pkg = pkg, examples = examples, run_dont_run = run_dont_run, …
3. pkgdown::build_articles(pkg, lazy = lazy, override = override, preview = FALSE)
4. purrr::walk(pkg$vignettes$name, build_article, pkg = pkg, quiet = quiet, …
5. purrr::map(.x, .f, ..., .progress = .progress)
6. purrr:::map_("list", .x, .f, ..., .progress = .progress)
7. purrr:::with_indexed_errors(i = i, names = names, error_call = .purrr_error_call, …
8. base::withCallingHandlers(expr, error = function(cnd) { …
9. purrr:::call_with_cleanup(map_impl, environment(), .type, .progress, …
10. local .f(.x[[i]], ...)
11. pkgdown:::render_rmarkdown(pkg, input = input, output = output_file, output_format = format, …
12. base::tryCatch(callr::r_safe(function(...) rmarkdown::render(...), …
13. base::tryCatchList(expr, classes, parentenv, handlers)
14. base::tryCatchOne(expr, names, parentenv, handlers[[1L]])
15. value[[3L]](cond)
16. rlang::abort("Failed to render RMarkdown", parent = cnd)
17. | rlang:::signal_abort(cnd, .file)
18. | base::signalCondition(cnd)
19. (function (cnd) …
20. cli::cli_abort(message, location = i, name = name, parent = cnd, …
21. | rlang::abort(message, ..., call = call, use_cli_format = TRUE, …
22. | rlang:::signal_abort(cnd, .file)
23. | base::signalCondition(cnd)
24. global (function (e) …
sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux trixie/sid
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.11.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.11.0
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
[4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
time zone: Etc/UTC
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] vctrs_0.6.5 cli_3.6.1 knitr_1.45 rlang_1.1.2
[5] xfun_0.41 processx_3.8.2 purrr_1.0.2 glue_1.6.2
[9] rprojroot_2.0.4 htmltools_0.5.7 ps_1.7.5 fansi_1.0.5
[13] rmarkdown_2.25 evaluate_0.23 tibble_3.2.1 fastmap_1.1.1
[17] yaml_2.3.7 lifecycle_1.0.4 memoise_2.0.1 compiler_4.3.2
[21] fs_1.6.3 pkgconfig_2.0.3 digest_0.6.33 R6_2.5.1
[25] utf8_1.2.4 pillar_1.9.0 callr_3.7.3 magrittr_2.0.3
[29] tools_4.3.2 withr_2.5.2 pkgdown_2.0.7 cachem_1.0.8
[33] desc_1.4.2
Sorry if I missed something obvious but shouldn't this be markdown::html_format
instead?
I no longer see this error with markdown::html_format
changing to html_format
did not help:
root@e2b15d9dae7f:/mdpkg# cat vignettes/vign.Rmd
---
title: "Title of a vignette"
output:
markdown::html_format
vignette: >
%\VignetteIndexEntry{Example vignette}
%\VignetteEngine{knitr::knitr}
\usepackage[utf8]{inputenc}
---
## Hello
library(mdpkg)
hello()
## Bye
Bye!
root@e2b15d9dae7f:/mdpkg# Rscript -e 'pkgdown::build_site()'
-- Installing package into temporary library -----------------------------------
== Building pkgdown site =======================================================
Reading from: '/mdpkg'
Writing to: '/mdpkg/docs'
-- Initialising site -----------------------------------------------------------
-- Building home ---------------------------------------------------------------
Writing '404.html'
-- Building function reference -------------------------------------------------
Reading 'man/hello.Rd'
-- Building articles -----------------------------------------------------------
Reading 'vignettes/vign.Rmd'
-- RMarkdown error -------------------------------------------------------------
--------------------------------------------------------------------------------
Error:
! in callr subprocess.
Caused by error in `map(.x, .f, ..., .progress = .progress)`:
! In index: 1.
---
Standard output:
== Building pkgdown site =======================================================
Reading from: '/mdpkg'
Writing to: '/mdpkg/docs'
-- Initialising site -----------------------------------------------------------
-- Building home ---------------------------------------------------------------
Writing '404.html'
-- Building function reference -------------------------------------------------
Reading 'man/hello.Rd'
-- Building articles -----------------------------------------------------------
Reading 'vignettes/vign.Rmd'
-- RMarkdown error -------------------------------------------------------------
--------------------------------------------------------------------------------
---
Backtrace:
1. pkgdown::build_site()
2. pkgdown:::build_site_external(pkg = pkg, examples = examples, run_dont_run = run_don…
3. callr::r(function(..., cli_colors, pkgdown_internet) { …
4. callr:::get_result(output = out, options)
5. callr:::throw(callr_remote_error(remerr, output), parent = fix_msg(remerr[[3]]))
---
Subprocess backtrace:
1. pkgdown::build_site(...)
2. pkgdown:::build_site_local(pkg = pkg, examples = examples, run_dont_run = run_dont_r…
3. pkgdown::build_articles(pkg, lazy = lazy, override = override, preview = FALSE)
4. purrr::walk(pkg$vignettes$name, build_article, pkg = pkg, quiet = quiet, …
5. purrr::map(.x, .f, ..., .progress = .progress)
6. purrr:::map_("list", .x, .f, ..., .progress = .progress)
7. purrr:::with_indexed_errors(i = i, names = names, error_call = .purrr_error_call, …
8. base::withCallingHandlers(expr, error = function(cnd) { …
9. purrr:::call_with_cleanup(map_impl, environment(), .type, .progress, …
10. local .f(.x[[i]], ...)
11. pkgdown:::render_rmarkdown(pkg, input = input, output = output_file, output_format =…
12. base::tryCatch(callr::r_safe(function(...) rmarkdown::render(...), …
13. base::tryCatchList(expr, classes, parentenv, handlers)
14. base::tryCatchOne(expr, names, parentenv, handlers[[1L]])
15. value[[3L]](cond)
16. rlang::abort("Failed to render RMarkdown", parent = cnd)
17. | rlang:::signal_abort(cnd, .file)
18. | base::signalCondition(cnd)
19. (function (cnd) …
20. cli::cli_abort(message, location = i, name = name, parent = cnd, …
21. | rlang::abort(message, ..., call = call, use_cli_format = TRUE, …
22. | rlang:::signal_abort(cnd, .file)
23. | base::signalCondition(cnd)
24. global (function (e) …
Execution halted
I don't have good ideas how to debug it further on my side. Did you used a docker image? I can try to use the same.
Did you used a docker image? I can try to use the same.
No, nothing in particular. Just built the package locally and used html_format
. Works fine for me. Does knitting the vignette only work?
OK, this time I forgot to install markdown package (oh, dependencies...), using devel=TRUE
shows more details. After installing markdown package it successfully built vignette.
It seems I simplified my problem too much, and because of wrong function used before, not html_format
it could have not been reproduced well.
I updated repo to not be over simplified, please try again to reproduce.
I does look that error comes from renderer not being able to find added css style, defined in yaml header.
pkgdown::build_site(devel=TRUE)
== Building pkgdown site =======================================================
Reading from: '/mdpkg'
Writing to: '/mdpkg/docs'
-- Initialising site -----------------------------------------------------------
-- Building home ---------------------------------------------------------------
Writing '404.html'
-- Building function reference -------------------------------------------------
Reading 'man/hello.Rd'
-- Building articles -----------------------------------------------------------
Reading 'vignettes/vign.Rmd'
-- RMarkdown error -------------------------------------------------------------
Warning message:
In file(con, "r") :
cannot open file 'css/toc.css': No such file or directory
--------------------------------------------------------------------------------
Error in `map()`:
ℹ In index: 1.
Caused by error in `render_rmarkdown()`:
! Failed to render RMarkdown
Caused by error:
! in callr subprocess.
Caused by error:
! cannot open the connection
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/purrr_error_indexed>
Error in `map()`:
ℹ In index: 1.
Caused by error in `render_rmarkdown()`:
! Failed to render RMarkdown
Caused by error:
! in callr subprocess.
Caused by error:
! cannot open the connection
---
Backtrace:
▆
1. └─pkgdown::build_site(devel = TRUE)
2. └─pkgdown:::build_site_local(...)
3. └─pkgdown::build_articles(...)
4. └─purrr::walk(...)
5. └─purrr::map(.x, .f, ..., .progress = .progress)
6. └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
7. ├─purrr:::with_indexed_errors(...)
8. │ └─base::withCallingHandlers(...)
9. ├─purrr:::call_with_cleanup(...)
10. └─pkgdown (local) .f(.x[[i]], ...)
11. └─pkgdown:::render_rmarkdown(...)
Gut feeling is that it should work because R CMD build .
finds and uses added css well.
I can reproduce, this looks like a duplicate of #1229
The solution there is to provide a custom CSS and use as_is
:
...
vignette: >
%\VignetteIndexEntry{Example vignette}
%\VignetteEngine{knitr::knitr}
\usepackage[utf8]{inputenc}
pkgdown:
as_is: true
---
However, this works with rmarkdown::html_vignette()
but not with markdown::html_format()
. Not an expert of pkgdown
so I can't help more on that
@etiennebacher Thanks for finding that out. Indeed.
I think we should aim for consistency to R CMD build
way of building vignettes, anyway. Otherwise each single use case like that will have to debug and eventually find out those issues here (unless won't give it up along the way).
Ultimately if it won't going to be addressed, there should be at least an option to specify that behavior in override
argument of build_site()
rather than expect users to modify their vignettes to work around limitations in pkgdown.
Anyway, doesn't work for markdown::html_format
...
For more context on the as_is
option mentioned by @etiennebacher: https://pkgdown.r-lib.org/reference/build_articles.html#output-formats
@jangorecki unfortunately because pkgdown has to use a different page template than vignettes (in order to add its own navigation structure), I don't think there's any particularly clean way to do what you want.