Giter Site home page Giter Site logo

Comments (1)

wlandau avatar wlandau commented on May 29, 2024 1

tar_render() needs to set knit_root_dir to getwd() in rmarkdown::render(). Reports need to run with the working directory at the project root (instead of the parent directory of the report) so tar_load() and tar_read() work as expected.

Unfortunately, rmarkdown and pandoc seem to have trouble finding the reference docx when knit_root_dir is set to something non-default. So maybe submit an issue to rmarkdown instead? Seems like reference_docx and knit_root_dir should be interoperable regardless of what tarchetypes does.

Here is a reprex using rmarkdown by itself without tarchetypes:

# Set up the files:
# * Rmd source.
# * docx reference.
# * RDS data file.
saveRDS(mtcars, "data.rds")
lines <- c(
  "---",
  "title: 'template'",
  "output: word_document",
  "---",
  "",
  "#heading 1",
  "testing"
)
dir.create("doc/")
writeLines(lines, "doc/template.Rmd")
rmarkdown::render("doc/template.Rmd", output_format = "word_document")
#> processing file: template.Rmd
#> output file: template.knit.md
#> /Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS template.knit.md --to docx --from markdown+autolink_bare_uris+tex_math_single_backslash --output template.docx --lua-filter /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --highlight-style tango
#> 
#> Output created: template.docx
lines <- c(
  "---",
  "title: 'Untitled'",
  "---",
  "",
  "```{r try}",
  "library(flextable)",
  "flextable(readRDS('data.rds'))", # Data file is relative to project root.
  "```"
)
writeLines(lines, "doc/test.Rmd")

# Render with correct root dir and reference at template.docx
library(rmarkdown)
render(
  "doc/test.Rmd",
  knit_root_dir = getwd(),
  output_format = word_document(reference_docx = "template.docx")
)
#> processing file: test.Rmd
#> Quitting from lines 6-8 (test.Rmd)
#> Error: could not find file 'template.docx'

# Render with correct root dir and reference at doc/template.docx
render(
  "doc/test.Rmd",
  knit_root_dir = getwd(),
  output_format = word_document(reference_docx = "doc/template.docx")
)
#> processing file: test.Rmd
#> output file: test.knit.md
#> /Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS test.knit.md --to docx --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.docx --lua-filter /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --highlight-style tango --reference-doc doc/template.docx
#> Error: pandoc document conversion failed with error 1

Created on 2021-06-24 by the reprex package (v2.0.0)

from tarchetypes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.