Skip to content

rmarkdown::render with output_format=html_notebook mangles output file name  #1180

Closed

Description

@DarwinAwardWinner

If I have an Rmd file named test.Rmd and I try to render it programmatically, passing a specific file name to rmarkdown::render, I expect the output to always be placed at that file name. However, when I set output_format="html_notebook" and output_file="test.html", the generated file is instead named "test.nb.html". This hinders my attempts to put Rmarkdown rendering into a step in my reproducible workflow, because I can't precisely control the output file name.

Activity

  1. DarwinAwardWinner commented on Oct 26, 2017

    @DarwinAwardWinner
    Author

    Note that if I use output_file="test" (i.e. no file extension), then the file name is not mangled.

  2. added this to the v1.7 milestone on Oct 27, 2017
  3. yihui commented on Oct 27, 2017

    @yihui
    Collaborator

    .nb.html is the special filename extension for R Markdown Notebook output files. That is by design.

    If you want .html, you need to use a normal HTML output format like html_document.

  4. DarwinAwardWinner commented on Oct 27, 2017

    @DarwinAwardWinner
    Author

    I know that Rmd notebook output files normally have a special extension, but I think manually specifying an output file name should override any automatic naming. Why should it output to any file name other than the one I explicitly requested in the call to render?

    For what it's worth, I'm using the html_notebook as the output format for my html files instead of html_document because it provides nice features like paginated tables and hiding code blocks without me having to do anything special.

  5. yihui commented on Oct 27, 2017

    @yihui
    Collaborator

    I see.

    Since you are rendering notebooks programmatically, perhaps it is not too much hassle to file.rename() the output. If it is, I'll be happy to investigate this issue in the future (or you can investigate it by yourself and send a pull request).

  6. DarwinAwardWinner commented on Oct 27, 2017

    @DarwinAwardWinner
    Author

    Yes, that's the workaround I've gone with: creating a temporary output file with no extension and then renaming it to the name I actually want.

  7. DarwinAwardWinner commented on Nov 1, 2017

    @DarwinAwardWinner
    Author

    So, looking at the code, the post_processor function in html_notebook.R is what does the renaming. We can't just skip calling this in render.R, since other formats' post-processor functions perform important tasks. So it seems like the post-processor function interface would need to gain a new argument to indicate whether the output file name was auto-generated or manually specified. Or it could be hacked by attaching an attribute to the output_file variable to indicate that it was manually specified. This doesn't seem particularly elegant, but it could also be mostly internal to render.R and related functions rather than being exposed as an implementation detail.

    Another idea would be to split the "post-processor" functionality into two different functions. A post-processor for processing the content of the output file, and a renamer for modifying the output file name. That way, we could always call the post-processor, but only call the renamer if the file name was not manually specified.

    Perhaps the best alternative in this case would be to just add all the fancy features included in the html_notebook format to the html_document format as well, perhaps using an opt-in parameter or something if you don't want to change the default. That would remove my motivation for using the html_notebook format programmatically.

  8. github-actions commented on Nov 3, 2020

    @github-actions

    This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

  9. locked as resolved and limited conversation to collaborators on Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions