Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ rmarkdown 2.10

- New supported syntax for Shiny prerendered documents: you can now use `server: shiny` or `server: type: shiny`.

- Fix intermediate files being created at the current directory instead of the input directory when the input file name contains shell characters and `render(intermediates_dir = NULL)` (thanks, @atusy, #1982).


rmarkdown 2.9
================================================================================

Expand Down
17 changes: 9 additions & 8 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ render <- function(input,
if (!dir_exists(intermediates_dir))
dir.create(intermediates_dir, recursive = TRUE)
intermediates_dir <- normalize_path(intermediates_dir)
} else {
intermediates_dir <- normalize_path(dirname(input))
}
intermediates_loc <- function(file) {
if (is.null(intermediates_dir))
Expand All @@ -336,12 +338,17 @@ render <- function(input,
file.path(intermediates_dir, file)
}

# resolve output directory before we change the working directory in
# resolve output directory and file before we change the working directory in
# preparation for rendering the document
if (!is.null(output_dir)) {
if (!dir_exists(output_dir))
dir.create(output_dir, recursive = TRUE)
output_dir <- normalize_path(output_dir)
} else if (!is.null(output_file)) {
# if output_dir is not null, output file becomes relative to output_dir later
output_file <- structure(file.path(normalize_path(dirname(output_file)),
basename(output_file)),
class = class(output_file))
}

# check whether this document requires a knit
Expand All @@ -367,12 +374,6 @@ render <- function(input,
file.copy(input, input_no_shell_chars, overwrite = TRUE)
intermediates <- c(intermediates, input_no_shell_chars)
input <- input_no_shell_chars

# if an intermediates directory wasn't explicit before, make it explicit now
if (is.null(intermediates_dir)) {
intermediates_dir <-
dirname(normalize_path(input_no_shell_chars))
}
}

# never use the original input directory as the intermediate directory,
Expand Down Expand Up @@ -483,7 +484,7 @@ render <- function(input,
}
pandoc_to <- output_format$pandoc$to

# generate outpout file based on input filename
# generate output file based on input filename
output_auto <- pandoc_output_file(input, output_format$pandoc)
if (is.null(output_file) || is.na(output_file)) output_file <- output_auto else {
if (!inherits(output_file, "AsIs") && xfun::file_ext(output_file) == "")
Expand Down