MilesMcBain / tflow

An opinionated lightweight template for smooth targets flows.
Other
90 stars 9 forks source link

set root directory in use_rmd() so tar_load() works #4

Closed Aariq closed 3 years ago

Aariq commented 3 years ago

If an .Rmd file inside a directory (like the default for use_rmd("analysis") has tar_load() in it, I get the following error:

Error: utility functions like tar_read() and tar_progress() require a _targets/ data store produced by tar_make() or similar.

This happens when knitting, running chunks, or running tar_render("doc/analysis.Rmd"), even though tar_load() works in the console.

Reproducible code and workarounds here: https://github.com/ropensci/targets/issues/230

For what it's worth, only one of the workarounds in that issue actually worked for me:

withr::with_dir(rprojroot::find_root('_targets.R'),tar_load(mydata))

It would be useful if the .Rmd created by use_rmd() implemented one of these workarounds so tar_load() could work.

Aariq commented 3 years ago

Possibly by adding a code chunk with something like:

```{r load-data}
withr::with_dir(here::here(), {
  ## Load targets with tar_load() here only
  # tar_load(target1)
  # tar_load(target2)
  })
Aariq commented 3 years ago

Ah, nevermind. I think maybe there is a different problem going on. I'll close this for now until I figure it out.