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

Make quarto_render(as_job = TRUE) wrapable #105

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

salim-b
Copy link
Contributor

@salim-b salim-b commented May 9, 2023

Currently, quarto_render() cannot be wrapped in another function and run as a background job (as_job = TRUE) at the same time because of a naive deparse(Sys.call()) usage.

This PR properly evaluates and then deparses all provided arguments, so arguments are actually forwarded to quarto_render() when called inside another function. Before this PR, the following code would fail with error object 'path' not found:

dir <- rprojroot::find_testthat_root_file()
input <- file.path(dir, "test.Rmd")
output <- file.path(dir, "test.html")
wrapper <- function(path) quarto_render(path, quiet = TRUE, as_job = TRUE)
wrapper(input)

Addendum: rstudio/rstudio#12764 does not make this PR obsolete.

Copy link
Collaborator

@cderv cderv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I understand the problem.

That looks good but I wonder if it would be a bit better to try use rlang to handle the construction of the call, especially for '...' handling

This could require the change regarding missing() usage to make this works correctly.

I'll probably merge like this to unblock, and deal with that later

Comment on lines +89 to +98
render_args <- as.list(sys.call()[-1L])
render_args <- mapply(
function(arg, arg_name) paste0(
arg_name,
"="[nchar(arg_name) > 0L],
deparse1(eval(arg, envir = parent.frame(n = 3L)))
),
render_args,
names(render_args)
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to handle this a bit differently for complex wrapping calls that would use ... for example. In this case, it will not work. rlang maybe be useful for this. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, I didn't test with a wrapper function that uses dots, I only tested simple named args. Feel free to refactor and expand on this PR as you see fit!

@cderv
Copy link
Collaborator

cderv commented Mar 7, 2024

Thanks for updating. I postponed this for a later version, but still plan to come again into it. Thanks for the wait.

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

Successfully merging this pull request may close these issues.

None yet

2 participants