Skip to content
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

Safely allow tar_quarto() etc. to run the report from a custom working directory #169

Closed
wlandau opened this issue Mar 15, 2024 · 2 comments
Assignees

Comments

@wlandau
Copy link
Member

wlandau commented Mar 15, 2024

Many users have hit problems over the years while running tar_render() reports that live in subdirectories. targets requires each target to run from the root directory of the project for safety reasons, but this interferes with knitr and Quarto because of their own path management conventions. I was initially reluctant to expose knit_root_dir, execute_dir (even now I would probably use with::local_dir()). But we could allow the change in working directory if there are extra guardrails to make sure the user supplies a store argument to tar_read() and tar_load() in the report. The static code analysis could check this:

walk_load <- function(expr, counter) {
expr <- match.call(targets::tar_load, as.call(expr))
if (is.null(expr$names)) {
targets::tar_warn_validate(
"Found empty tar_load() call in a knitr / R Markdown ",
"code chunk. Dependencies cannot be detected statically, ",
"so they will be ignored."
)
}
walk_target_name(expr$names, counter)
}
walk_read <- function(expr, counter) {
expr <- match.call(targets::tar_read, as.call(expr))
if (is.null(expr$name)) {
targets::tar_warn_validate(
"Found empty tar_read() call in a knitr / R Markdown ",
"code chunk. Dependencies cannot be detected statically, ",
"so they will be ignored."
)
}
walk_target_name(expr$name, counter)
}

@wlandau wlandau self-assigned this Mar 15, 2024
@wlandau wlandau changed the title Safely allow tar_quarto() etc. to run from a custom working directory Safely allow tar_quarto() etc. to run the report from a custom working directory Mar 15, 2024
@wlandau
Copy link
Member Author

wlandau commented Mar 18, 2024

On second thought, I don't think we will need extra code analysis checks. The behavior will be documented in the working_directory argument, and the error message about not finding the data store will speak for itself.

wlandau-lilly pushed a commit that referenced this issue Mar 18, 2024
@wlandau
Copy link
Member Author

wlandau commented Mar 18, 2024

The reason for omitting this check is that users could have a _targets.yaml which tar_config_get() would understand, which could automatically set good defaults for tar_read() and tar_load() in reports.

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

No branches or pull requests

1 participant