gt
gt copied to clipboard
fails if doc is in a subdirectory
If a document is in a sub-directory and the execute directory is not the sub-directory, then a quarto -> docx document with a gt
table will fail to render.
This is important in particular for targets
workflows, where to have access to the targets
environment, the document is rendered with the execute_dir
at the top level.
Or at least that is the config bit I modify to be able to test document renders outside of the actual targets
workflow.
I’ve created a repo here with the files that are rendered below.
Note that d2.qmd
and doc/d1.qmd
are essentially identical documents with the same code, just their physical location in the filesystem are slightly different, and they are generating very basic gt
tables.
Top Level Renders Fine
quarto::quarto_render("d2.qmd")
## [31m
##
## processing file: d2.qmd
## [39m
|
| | 0%
|
|........ | 11%
## inline R code fragments
##
##
|
|................ | 22%
## label: setup (with options)
## List of 1
## $ include: logi FALSE
##
##
|
|....................... | 33%
## ordinary text without R code
##
##
|
|............................... | 44%
## label: load-targets (with options)
## List of 1
## $ include: logi FALSE
##
##
|
|....................................... | 56%
## ordinary text without R code
##
##
|
|............................................... | 67%
## label: create_table
##
|
|...................................................... | 78%
## ordinary text without R code
##
##
|
|.............................................................. | 89%
## label: gt_it
##
|
|......................................................................| 100%
## ordinary text without R code
##
##
## [31moutput file: d2.knit.md
##
## [39m[1mpandoc [22m
## to: docx
## output-file: d2.docx
## default-image-extension: png
##
## [1mmetadata[22m
## title: Untitled Draft
## author: Report Author
## date: '`r format(Sys.time(), ''%d %B, %Y'')`'
##
## Output created: d2.docx
In A Sub-Directory With execute_dir as Top Level
quarto::quarto_render("doc/d1.qmd", execute_dir = getwd())
## [31m
##
## processing file: d1.qmd
## [39m
|
| | 0%
|
|........ | 11%
## inline R code fragments
##
##
|
|................ | 22%
## label: setup (with options)
## List of 1
## $ include: logi FALSE
##
##
|
|....................... | 33%
## ordinary text without R code
##
##
|
|............................... | 44%
## label: load-targets (with options)
## List of 1
## $ include: logi FALSE
##
##
|
|....................................... | 56%
## ordinary text without R code
##
##
|
|............................................... | 67%
## label: create_table
##
|
|...................................................... | 78%
## ordinary text without R code
##
##
|
|.............................................................. | 89%
## label: gt_it
## [31mQuitting from lines 51-58 (d1.qmd)
## Error in readLines(con, warn = FALSE) : cannot open the connection
## Calls: .main ... <Anonymous> -> enumerate_output_formats -> read_utf8 -> readLines
## [39m
## [31mExecution halted
## [39m
## Error in "processx::run(quarto_bin, args, echo = TRUE)": ! System command 'quarto' failed
In A Sub-Directory With No execute_dir
quarto::quarto_render("doc/d1.qmd")
## [31m
##
## processing file: d1.qmd
## [39m
|
| | 0%
|
|........ | 11%
## inline R code fragments
##
##
|
|................ | 22%
## label: setup (with options)
## List of 1
## $ include: logi FALSE
##
##
|
|....................... | 33%
## ordinary text without R code
##
##
|
|............................... | 44%
## label: load-targets (with options)
## List of 1
## $ include: logi FALSE
##
##
|
|....................................... | 56%
## ordinary text without R code
##
##
|
|............................................... | 67%
## label: create_table
##
|
|...................................................... | 78%
## ordinary text without R code
##
##
|
|.............................................................. | 89%
## label: gt_it
##
|
|......................................................................| 100%
## ordinary text without R code
##
##
## [31moutput file: d1.knit.md
##
## [39m[1mpandoc [22m
## to: docx
## output-file: d1.docx
## default-image-extension: png
##
## [1mmetadata[22m
## title: Untitled Draft
## author: Report Author
## date: '`r format(Sys.time(), ''%d %B, %Y'')`'
##
## Output created: d1.docx
Forgot to add:
- gt v 0.7.0
- quarto v 1.2
- R v 4.2.1, Linux, Ubuntu like OS (Pop!OS)
This is probably related with: https://github.com/ropensci/targets/discussions/920#discussioncomment-3527527
In that case, reverting to gt 0.6.0 made the problem disappear.
In that discussion, @wlandau proposes a specific change to solve the issue:
This can be fixed if https://github.com/rstudio/gt/blob/a585bd6a916cca767c7a2e3e72eda8f91c2f67f5/R/print.R#L27 uses knitr::current_input(dir = TRUE) instead of knitr::current_input().
I think it is likely related. However, the whole reason I was using gt 0.7.0 was for docx support, as I would really like quarto based documents to word documents, with table auto-numbering (flextable & quarto don't support that quite yet), in a targets workflow. So 0.6.0 is a no go.