Daniel
Daniel

Reputation: 618

Render quarto documents in another directory using tar_quarto

I have a R workflow set up using {targets} and {tarchetypes} packages. A a certain point I use tarchetypes::tar_quarto() to render a document, which is placed in the same directory containing the quarto document.

How can I render the quarto document and place it in another directory?

Right now I have this code on my workflow, which will place the rendered document in report folder.

  tar_quarto(
    relatorio_suspeitos,
    'report/relatorio_suspeitos.qmd'
  ),

I'd like to have the .qmd file in one folder and the rendered output created in another folder (output/relatorio_suspeitos.pdf).

Upvotes: 0

Views: 106

Answers (1)

D3SL
D3SL

Reputation: 127

It is possible to do this but because {targets} is "opinionated" it's a headache. The problem is that the quarto document is completely disconnected from whatever configuration you set in the environment where you call tar_make().

By default quarto will treat its own location as its working directory and all {targets} functions will look for a _targets folder in that same directory, regardless of whatever else you may have configured.

so for example:

tar_config_set(
  script = "foo/scripts/bar.R", 
  store = "foo/data/bar",
  project = "bar"
)

Sys.setenv(TAR_PROJECT = "bar")
tar_make()

Your root directory is foo, scripts are in foo/scripts/, your store is set to foo/data/{project}, and assume your want your reports to output to foo/reports.

The pipeline itself will run fine. The quarto document will fail because it will look for _targets.yaml in foo/reports/ rather than foo, fail to find it, and then default to looking for the store at foo/reports/_targets.

The two ways you can make this work are to jump through hoops to set the root directory and load the right config file inside the quarto document, or to adjust your directory structure so each project's store is in the same folder as the report:

tar_config_set(
  script = "foo/scripts/bar.R", 
  store = "foo/reports/bar",
  project = "bar"
)

This option also has the benefit of allowing you to have multiple projects whose stores won't conflict with each other, since each report and store will be in a folder named for the project.

Upvotes: 0

Related Questions