Skip to content

Commit 325c4ad

Browse files
jvolkeningyihui
andauthored
have inf_mr() watch all Rmd files (#349)
Co-authored-by: Yihui Xie <[email protected]>
1 parent 254abbf commit 325c4ad

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: xaringan
22
Type: Package
33
Title: Presentation Ninja
4-
Version: 0.23.1
4+
Version: 0.23.2
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
77
# contributors ordered alphabetically below

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# CHANGES IN xaringan VERSION 0.24
22

3+
- 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).
34

45
# CHANGES IN xaringan VERSION 0.23
56

R/render.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,14 @@ infinite_moon_reader = function(moon, cast_from = '.', ...) {
298298
# otherwise watch files under the dir of the moon
299299
d = if (p <- is_package()) 'inst' else dirname(moon)
300300
files = if (getOption('xaringan.inf_mr.aggressive', TRUE)) function() {
301-
c(list.files(
302-
d, '[.](css|js|png|gif|jpeg)$', full.names = TRUE, recursive = TRUE
303-
), moon)
301+
list.files(
302+
d, '[.](css|js|png|gif|jpeg|Rmd)$', full.names = TRUE, recursive = TRUE
303+
)
304304
} else function() moon
305-
mtime = function() file.info(files())[, 'mtime']
305+
mtime = function() {
306+
fs = files()
307+
setNames(file.info(fs)[, 'mtime'], fs)
308+
}
306309
html <<- normalize_path(rebuild()) # render Rmd initially
307310
l = max(m <- mtime()) # record the latest timestamp of files
308311
r = servr:::is_rstudio(); info = if (r) slide_context()
@@ -331,9 +334,11 @@ infinite_moon_reader = function(moon, cast_from = '.', ...) {
331334
}
332335
return(FALSE)
333336
}
337+
# is any Rmd updated?
338+
u2 = !u && any(m2[grep('[.]Rmd$', names(m2))] > l)
334339
l <<- max(m2)
335340
# moon or dependencies have been updated, recompile and reload in browser
336-
if (p || tail(m2, 1) > tail(m, 1)) {
341+
if (p || u2) {
337342
rebuild(); if (r) info <<- slide_context()
338343
}
339344
l <<- max(m <<- mtime())

0 commit comments

Comments
 (0)