Skip to content

Commit

Permalink
have inf_mr() watch all Rmd files (#349)
Browse files Browse the repository at this point in the history
Co-authored-by: Yihui Xie <[email protected]>
  • Loading branch information
jvolkening and yihui authored Mar 17, 2022
1 parent 254abbf commit 325c4ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: xaringan
Type: Package
Title: Presentation Ninja
Version: 0.23.1
Version: 0.23.2
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
# contributors ordered alphabetically below
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# CHANGES IN xaringan VERSION 0.24

- When running `xaringan::inf_mr()`, the Rmd file will be recompiled when any Rmd file under the same directory is updated. This allows for rebuilding the slides when child documents are used and updated. Previously, the Rmd file would be recompiled only if itself is updated (thanks, @jvolkening, #349).

# CHANGES IN xaringan VERSION 0.23

Expand Down
15 changes: 10 additions & 5 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,14 @@ infinite_moon_reader = function(moon, cast_from = '.', ...) {
# otherwise watch files under the dir of the moon
d = if (p <- is_package()) 'inst' else dirname(moon)
files = if (getOption('xaringan.inf_mr.aggressive', TRUE)) function() {
c(list.files(
d, '[.](css|js|png|gif|jpeg)$', full.names = TRUE, recursive = TRUE
), moon)
list.files(
d, '[.](css|js|png|gif|jpeg|Rmd)$', full.names = TRUE, recursive = TRUE
)
} else function() moon
mtime = function() file.info(files())[, 'mtime']
mtime = function() {
fs = files()
setNames(file.info(fs)[, 'mtime'], fs)
}
html <<- normalize_path(rebuild()) # render Rmd initially
l = max(m <- mtime()) # record the latest timestamp of files
r = servr:::is_rstudio(); info = if (r) slide_context()
Expand Down Expand Up @@ -331,9 +334,11 @@ infinite_moon_reader = function(moon, cast_from = '.', ...) {
}
return(FALSE)
}
# is any Rmd updated?
u2 = !u && any(m2[grep('[.]Rmd$', names(m2))] > l)
l <<- max(m2)
# moon or dependencies have been updated, recompile and reload in browser
if (p || tail(m2, 1) > tail(m, 1)) {
if (p || u2) {
rebuild(); if (r) info <<- slide_context()
}
l <<- max(m <<- mtime())
Expand Down

0 comments on commit 325c4ad

Please sign in to comment.