Skip to content

Commit

Permalink
Revert "fix rstudio#1700: prevent rmarkdown::run from failing when fi…
Browse files Browse the repository at this point in the history
…le is NULL and dir is set (rstudio#1703)"

This reverts commit 5bb98e1 and fixes rstudio#1714 by creating the correct `target_file`.
  • Loading branch information
yihui committed Dec 4, 2019
1 parent 0441860 commit 3d648d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ rmarkdown 1.19

- `ioslides_presentation()` stylesheet is updated for printing. Browsers are notified that the presentation should preferentially be printed in landscape orientation and without margin (thanks, @RLesur, #1718).

- Reverted the fix #1703 and applied an alternative fix to #1700, because the original fix brought a new bug #1714 (thanks, @pablobernabeu @cderv @everron @aronatkins).


rmarkdown 1.18
================================================================================

Expand Down
12 changes: 6 additions & 6 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ run <- function(file = "index.Rmd", dir = dirname(file), default_file = NULL,
allRmds <- list.files(path = dir, pattern = "^[^_].*\\.[Rr][Mm][Dd]$")
if (length(allRmds) == 1) {
# just one R Markdown document
default_file <- file.path(dir, allRmds)
default_file <- allRmds
} else {
# more than one: look for an index
index <- which(tolower(allRmds) == "index.rmd")
if (length(index) > 0) {
default_file <- file.path(dir, allRmds[index[1]])
default_file <- allRmds[index[1]]
} else {
# look for first one that has runtime: shiny
for (rmd in allRmds) {
runtime <- yaml_front_matter(file.path(dir, rmd))$runtime
if (is_shiny(runtime)) {
default_file <- file.path(dir, rmd)
default_file <- rmd
break
}
}
Expand All @@ -95,7 +95,7 @@ run <- function(file = "index.Rmd", dir = dirname(file), default_file = NULL,
if (is.null(default_file)) {
# no R Markdown default found; how about an HTML?
indexHtml <- list.files(dir, "index.html?", ignore.case = TRUE)
if (length(indexHtml) > 0) default_file <- file.path(dir, indexHtml[1])
if (length(indexHtml) > 0) default_file <- indexHtml[1]
}

# form and test locations
Expand All @@ -121,8 +121,8 @@ run <- function(file = "index.Rmd", dir = dirname(file), default_file = NULL,
if (is.null(render_args$envir)) render_args$envir <- parent.frame()

# determine the runtime of the target file
target_file <- file %||% default_file
runtime <- if (!is.null(target_file)) yaml_front_matter(target_file)$runtime
target_file <- file %||% file.path(dir, default_file)
runtime <- if (length(target_file)) yaml_front_matter(target_file)$runtime

# run using the requested mode
if (is_shiny_prerendered(runtime)) {
Expand Down

0 comments on commit 3d648d3

Please sign in to comment.