Skip to content

pandoc_convert() evaluates output argument in wrong directory #1889

@krlmlr

Description

@krlmlr

In pandoc_convert(), the output argument is forced after changing the working directory. This is unexpected, not documented, and breaks downlit::downlit_md_path() and perhaps others. PR follows.

input <- tempfile("in", fileext = ".md")
input
#> [1] "/tmp/Rtmpl3bcya/in6d94718e979a.md"
writeLines("# Document", input)

output <- "out.md"

# Breaks
writeLines("bogus", output)
normalizePath(output, mustWork = FALSE)
#> [1] "/tmp/Rtmp9ZZAHN/reprex6bed4897d478/out.md"
rmarkdown::pandoc_convert(input, output = normalizePath(output, mustWork = FALSE), verbose = TRUE)
#> /usr/lib/rstudio/bin/pandoc/pandoc +RTS -K512m -RTS /tmp/Rtmpl3bcya/in6d94718e979a.md --output out.md
readLines(output)
#> [1] "bogus"

# Works if we compute output outside of call
writeLines("bogus", output)
output <- normalizePath(output, mustWork = FALSE)
rmarkdown::pandoc_convert(input, output = output, verbose = TRUE)
#> /usr/lib/rstudio/bin/pandoc/pandoc +RTS -K512m -RTS /tmp/Rtmpl3bcya/in6d94718e979a.md --output /tmp/Rtmp9ZZAHN/reprex6bed4897d478/out.md
readLines(output)
#> [1] "Document" "========"

Created on 2020-09-03 by the reprex package (v0.3.0)

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