-
-
Notifications
You must be signed in to change notification settings - Fork 975
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
Argument keep_md not inherited by custom output format that extends html_document() #1558
Comments
Hi @jdblischak, sorry for the delay.
html_wrap <- function(...) {
rmarkdown::output_format(knitr = rmarkdown::knitr_options(),
pandoc = rmarkdown::pandoc_options(to = "html"),
base_format = rmarkdown::html_document(...))
}
html_wrap()$keep_md
#> [1] FALSE
html_wrap(keep_md = TRUE)$keep_md
#> [1] FALSE However, you can set the value to NULL to explicitly use the one from html_wrap <- function(...) {
rmarkdown::output_format(knitr = rmarkdown::knitr_options(),
pandoc = rmarkdown::pandoc_options(to = "html"),
keep_md = NULL,
base_format = rmarkdown::html_document(...))
}
html_wrap()$keep_md
#> [1] FALSE
html_wrap(keep_md = TRUE)$keep_md
#> [1] TRUE Currently there is also the option to do as some rmarkdown format by providing explictly the argument html_wrap <- function(keep_md = FALSE, ...) {
rmarkdown::output_format(knitr = rmarkdown::knitr_options(),
keep_md = keep_md,
pandoc = rmarkdown::pandoc_options(to = "html"),
base_format = rmarkdown::html_document(...))
}
html_wrap()$keep_md
#> [1] FALSE
html_wrap(keep_md = TRUE)$keep_md
#> [1] TRUE or as some of the bookdown format, by modifying directly a format (this way you can decide the merging rule too) html_wrap <- function(...) {
base_format <- rmarkdown::html_document(...)
base_format$knitr <- rmarkdown::knitr_options()
base_format$pandoc <- rmarkdown::pandoc_options(to = "html")
base_format
}
html_wrap()$keep_md
#> [1] FALSE
html_wrap(keep_md = TRUE)$keep_md
#> [1] TRUE This is the current state of how this works. I understand this is not what you expected. I guess the default value in If we change the current default behavior (by inheriting from base format if Do you still find it is not suitable from the example above ? |
@jdblischak what are your thoughts on the above ? |
@cderv Thanks for diving into this complicated issue and following up. Ultimately I think this is a documentation issue. Some arguments to
Thus currently the only way to learn that For my purposes, I am fine with the workaround I implemented for workflowr (which is essentially what I proposed above). My main concern would be if new arguments were added to Of the options you proposed above, I think the most straightforward option is to explicitly supply the argument |
By filing an issue to this repo, I promise that
xfun::session_info('rmarkdown')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('rstudio/rmarkdown')
.Note: Sorry for the strange line wrapping below. I used the output format
github_document()
, but apparently GitHub markdown now respects line breaks. I manually fixed a few of the more egregious breaks below.I have created a custom output format that extends
html_document()
. Inoticed that the argument
keep_md
is not properly inherited.My first thought was that both the arguments
keep_md
anddf_print
might have issues since they are arguments for both
output_format()
and
html_document()
, but somehowdf_print
is properly inherited.Here is a minimal example to demonstrate the issue. The function below
is a trivial output format that wraps
html_document()
, but doesn’tchange anything.
If a user runs
render()
on an R Markdown file with the following YAMLheader:
then this would result in the following call to
create_output_format()
:This inherits the default values from
html_document()
as expected:However, if a user runs
render()
on an R Markdown file with thefollowing YAML header:
then this would result in the following call to
create_output_format()
(line 378):toc
is inherited as expected:df_print
is inherited not only in the environment of thepre_knit()
function, but the value of the output format is also inherited:
Unfortunately,
keep_md
is only updated in the environment of thepre_knit()
function, where it has no effect.When
render()
addsrmarkdown.keep_md
toknitr::opts_knit
, it usesoutput_format$keep_md
(line 500).When
render()
decides to keep the md file, it again usesoutput_format$keep_md
(line 869).Potentially related Issues include #842 and #928.
Note that
bookdown::html_document2()
does not have this issue.But it is unclear to me what part of its code would change the
inheritance of
keep_md
.It appears to be directly editing the base output format instead of
inheriting from it using
output_format(base_format = )
, which is whatthe documentation recommends.
What is the recommended method for passing all arguments provided to a
custom output format to the base output format that it extends?
I realize that I could hard-code a work-around for the custom output
format to handle
keep_md
, but this is fragile. If a future release ofrmarkdown added a new argument to
output_format()
/html_document()
, Iwould have to update my code and also put a restriction on the minimum
version of rmarkdown that is compatible.
The text was updated successfully, but these errors were encountered: