Skip to content

Commit

Permalink
fix rstudio/rmarkdown#2363: ignore empty plots that only contain call…
Browse files Browse the repository at this point in the history
…s to requireNamespace()
  • Loading branch information
yihui committed May 25, 2022
1 parent 5e5ace6 commit f1b1c1e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: evaluate
Type: Package
Title: Parsing and Evaluation Tools that Provide More Details than the Default
Version: 0.15.1
Version: 0.15.2
Authors@R: c(
person("Hadley", "Wickham", role = "aut"),
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
Expand All @@ -28,6 +28,6 @@ Suggests:
ggplot2,
lattice,
testthat
RoxygenNote: 7.1.1
RoxygenNote: 7.2.0
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Version 0.16
================================================================================

- Fixed a bug that an empty **ggplot2** plot could be recorded and incorrectly saved (thanks, @sjspielman, rstudio/rmarkdown#2363).

Version 0.15
================================================================================
Expand Down
12 changes: 7 additions & 5 deletions R/graphics.r
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ is.empty <- function(x) {
plot_calls <- function(plot) {
el <- lapply(plot[[1]], "[[", 2)
if (length(el) == 0) return()
sapply(el, function(x) {
x <- x[[1]]
# grid graphics do not have x$name
if (is.null(x[["name"]])) deparse(x) else x[["name"]]
})
unlist(lapply(el, function(x) {
# grid graphics do not have x[[1]]$name
if (!is.null(nm <- x[[1]][["name"]])) return(nm)
nm <- deparse(x[[1]])
# the plot element should not be empty
if (length(x[[2]]) > 0 || !grepl("^requireNamespace\\(", nm)) nm
}))
}

0 comments on commit f1b1c1e

Please sign in to comment.