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

An output format argument with no default causes rmarkdown:::default_output_format to fail with cryptic error message. #2407

Open
MilesMcBain opened this issue Sep 2, 2022 · 7 comments
Assignees

Comments

@MilesMcBain
Copy link

I ran into this developing a custom output format that worked fine from the console, but threw an error only when using the ‘knit’ button in RStudio.

Upon clicking the button I see this in the console:

Error in merge_lists(as.list(formals(format_function)), format$options,  : 
  argument "base" is missing, with no default

I found the cause here in default_output_format()

As you can see here the repo arg of my github_issue format had no default value.

So we get:

fake_output_format <- function(repo, number = NULL, action = "create") {
  NULL
}

fake_overlay <- list(repo = "milesmcabin/issuecreep", number = 1)

rmarkdown:::merge_lists(as.list(formals(fake_output_format)),
                        fake_overlay,
                        recursive = FALSE)
#> Error in rmarkdown:::merge_lists(as.list(formals(fake_output_format)), : argument "base" is missing, with no default

# And this is because in merge_lists:

base_list <- as.list(formals(fake_output_format))
base <- base_list[["repo"]]
is.list(base)
#> Error in eval(expr, envir, enclos): argument "base" is missing, with no default

# because base is 'missing'
base
#> Error in eval(expr, envir, enclos): argument "base" is missing, with no default

Created on 2022-09-02 with reprex v2.0.2

I think if I add a default to my output format all should be well. This was just a little hard to figure out and I didn’t find it documented anywhere, my apologies if this is so.

Maybe this case could be detected an some kind of more useful error thrown?

PS I drafted this and submitted this issue in RStudio with my github_issue format. An amazing job has been done with how extensible rmarkdown output formats are! 😄

@cderv
Copy link
Collaborator

cderv commented Sep 2, 2022

Thank for sharing your experience.

but threw an error only when using the ‘knit’ button in RStudio.

Is this happening only on RStudio IDE while knitting ? Or also in VS CODE. I understand it does not happen in Console when doing rmarkdown::render()

the function default_output_format() is called in the IDE itself:
https://github.com/rstudio/rstudio/blob/2e74d121d6d07e6d3e0d2d5a7dc82ff8b426cc6e/src/cpp/session/modules/rmarkdown/SessionRMarkdown.cpp#L175

We should probably try to fix in this function default_output_format() - merge_list is used at low level and is supposed to be used with at least a base by any function calling it. 🤔

This was just a little hard to figure out and I didn’t find it documented anywhere, my apologies if this is so.

yeah sorry. I don't think this is documented. We don't have a lot (yet) on custom format . Glad you managed to create one!

PS I drafted this and submitted this issue in RStudio with my github_issue format. An amazing job has been done with how extensible rmarkdown output formats are! 😄

That is so cool !! 🎉

@MilesMcBain
Copy link
Author

Yes, this is a RStudio-only thing. VSCode-R extension doesn't call default_output_format() in its knit routine as far as I can see.

@juliasilge
Copy link
Member

I ran into this same error today, with the vetiver dashboard. I also see no problem from the console, but see this error when clicking the "knit" button and when deploying to RStudio Connect:

Screen Shot 2022-10-21 at 12 49 55 PM

I'll try adding a default value for my custom format arguments.

@juliasilge
Copy link
Member

That did fix it for me; the new dashboard is now deployed here.

@rich-iannone rich-iannone self-assigned this Dec 20, 2022
@cderv cderv moved this from Next to Backlog in R Markdown Team Projects Jan 17, 2023
@ashne135

This comment was marked as off-topic.

@ashne135

This comment was marked as off-topic.

@cderv

This comment was marked as off-topic.

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

No branches or pull requests

5 participants