Skip to content

fails if doc is in a subdirectory #1040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rmflight opened this issue Sep 5, 2022 · 3 comments · Fixed by #1084
Closed

fails if doc is in a subdirectory #1040

rmflight opened this issue Sep 5, 2022 · 3 comments · Fixed by #1084

Comments

@rmflight
Copy link

rmflight commented Sep 5, 2022

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
@rmflight
Copy link
Author

rmflight commented Sep 5, 2022

Forgot to add:

  • gt v 0.7.0
  • quarto v 1.2
  • R v 4.2.1, Linux, Ubuntu like OS (Pop!OS)

@gorkang
Copy link

gorkang commented Sep 5, 2022

This is probably related with: ropensci/targets#920 (comment)

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().

@rmflight
Copy link
Author

rmflight commented Sep 5, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment