Skip to content

Can't change "output_dir" in the YAML metadata #2617

Open

Description

@thombet

Checklist

When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:

  • formatted your issue so it is easier for us to read?

  • included a minimal, self-contained, and reproducible example?

  • pasted the output from xfun::session_info('rmarkdown') in your issue?

  • upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)? I use RMarkdown 2.29 and I cannot upgrade to the latest version (2.31) currently but reading the release notes of versions 2.30 and 2.31, I think the issue was not fixed in these newer versions.

  • installed and tested your bug with the development version of the rmarkdown package using remotes::install_github("rstudio/rmarkdown") ? Same as above.

Bug description

Hello,

I am not able to change the output directory of an HTML document using the examples provided here and here.

Here is the content of a test.Rmd file:

---
title: "Test"
output: html_document
knit: (function(input, ...) {
    rmarkdown::render(
      input,
      output_dir = "docs/html"
    )
  })
---

This is a test document.

```{r dummy-chunk}
sample(letters, 2)
```

When I call in the R terminal

rmarkdown::render("test.Rmd")

the file test.html is generated in the same folder as test.Rmd whereas I would have expected it to be located in the folders docs/html.

Setting explicitly the output_dir in the command works as expected though:

rmarkdown::render("test.Rmd", output_dir = "docs/html")

Is this a bug or am I using the knit arguments in the metadata in the wrong way?

Thanks in advance for your help.

Session information

xfun::session_info('rmarkdown')

R version 4.5.1 (2025-06-13)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.5 LTS, RStudio 0

Locale:
  LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8     LC_MONETARY=fr_FR.UTF-8   
  LC_MESSAGES=en_GB.UTF-8    LC_PAPER=fr_FR.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
  LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C       

Package version:
  base64enc_0.1.3   bslib_0.9.0       cachem_1.1.0      cli_3.6.5         digest_0.6.37     evaluate_1.0.4    fastmap_1.2.0     fontawesome_0.5.3
  fs_1.6.6          glue_1.8.0        graphics_4.5.1    grDevices_4.5.1   highr_0.11        htmltools_0.5.8.1 jquerylib_0.1.4   jsonlite_2.0.0   
  knitr_1.50        lifecycle_1.0.4   memoise_2.0.1     methods_4.5.1     mime_0.13         R6_2.6.1          rappdirs_0.3.3    rlang_1.1.7      
  rmarkdown_2.29    sass_0.4.10       stats_4.5.1       tinytex_0.57      tools_4.5.1       utils_4.5.1       xfun_0.52         yaml_2.3.10      

Pandoc version: 3.6.2

Activity

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions