rmarkdown icon indicating copy to clipboard operation
rmarkdown copied to clipboard

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

Open MilesMcBain opened this issue 1 year ago • 7 comments

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! :smile:

MilesMcBain avatar Sep 02 '22 12:09 MilesMcBain

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 !! 🎉

cderv avatar Sep 02 '22 13:09 cderv

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.

MilesMcBain avatar Sep 02 '22 23:09 MilesMcBain

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 avatar Oct 21 '22 18:10 juliasilge

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

juliasilge avatar Oct 21 '22 19:10 juliasilge