From 5fd07df1798385c4025b0ef0142f0b52975f12a9 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 29 Mar 2024 13:58:37 -0500 Subject: [PATCH 1/4] Start v0.5.8.1 release candidate --- DESCRIPTION | 2 +- NEWS.md | 4 +++- R/images.R | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6b32eb71..81f2a7a0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: htmltools Title: Tools for HTML -Version: 0.5.8.9000 +Version: 0.5.8.1 Authors@R: c( person("Joe", "Cheng", , "joe@posit.co", role = "aut"), person("Carson", "Sievert", , "carson@posit.co", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 628fbaaf..e0f5c0c8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,6 @@ -# htmltools (development version) +# htmltools 0.5.8.1 + +* `capturePlot()`s examples are now only run when `interactive()`. (#429) # htmltools 0.5.8 diff --git a/R/images.R b/R/images.R index 30a63bb1..0ef3802d 100644 --- a/R/images.R +++ b/R/images.R @@ -17,7 +17,7 @@ #' @seealso [plotTag()] saves plots as a self-contained `` #' tag. #' -#' @examples +#' @examplesIf interactive() #' # Default settings #' res <- capturePlot(plot(cars)) #' From 9dea7a4a5e5f58abcd2c3924f016be1a33f8e80b Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 29 Mar 2024 14:00:24 -0500 Subject: [PATCH 2/4] Use rlang's version --- R/images.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/images.R b/R/images.R index 0ef3802d..155865fd 100644 --- a/R/images.R +++ b/R/images.R @@ -17,7 +17,7 @@ #' @seealso [plotTag()] saves plots as a self-contained `` #' tag. #' -#' @examplesIf interactive() +#' @examplesIf rlang::is_interactive() #' # Default settings #' res <- capturePlot(plot(cars)) #' From e47e390721c17e74411fc754e147b8e39a07ed06 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 29 Mar 2024 14:01:54 -0500 Subject: [PATCH 3/4] Get rid of other, now redundant, interactive checks --- R/images.R | 6 +++--- man/capturePlot.Rd | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/R/images.R b/R/images.R index 155865fd..791553d6 100644 --- a/R/images.R +++ b/R/images.R @@ -22,7 +22,7 @@ #' res <- capturePlot(plot(cars)) #' #' # View result -#' if (interactive()) browseURL(res) +#' browseURL(res) #' #' # Clean up #' unlink(res) @@ -30,7 +30,7 @@ #' # Custom width/height #' pngpath <- tempfile(fileext = ".png") #' capturePlot(plot(pressure), pngpath, width = 800, height = 375) -#' if (interactive()) browseURL(pngpath) +#' browseURL(pngpath) #' unlink(pngpath) #' #' # Use a custom graphics device (e.g., SVG) @@ -41,7 +41,7 @@ #' grDevices::svg, #' width = 8, height = 3.75 #' ) -#' if (interactive()) browseURL(svgpath) +#' browseURL(svgpath) #' unlink(svgpath) #' } #' diff --git a/man/capturePlot.Rd b/man/capturePlot.Rd index 31d50738..9271f7ff 100644 --- a/man/capturePlot.Rd +++ b/man/capturePlot.Rd @@ -34,11 +34,12 @@ Easily generates a .png file (or other graphics file) from a plotting expression. } \examples{ +\dontshow{if (rlang::is_interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Default settings res <- capturePlot(plot(cars)) # View result -if (interactive()) browseURL(res) +browseURL(res) # Clean up unlink(res) @@ -46,7 +47,7 @@ unlink(res) # Custom width/height pngpath <- tempfile(fileext = ".png") capturePlot(plot(pressure), pngpath, width = 800, height = 375) -if (interactive()) browseURL(pngpath) +browseURL(pngpath) unlink(pngpath) # Use a custom graphics device (e.g., SVG) @@ -57,10 +58,10 @@ if (capabilities("cairo")) { grDevices::svg, width = 8, height = 3.75 ) - if (interactive()) browseURL(svgpath) + browseURL(svgpath) unlink(svgpath) } - +\dontshow{\}) # examplesIf} } \seealso{ \code{\link[=plotTag]{plotTag()}} saves plots as a self-contained \verb{} From ff7f09d4d8dee6b3a830035eba1eb5d4657683d4 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 2 Apr 2024 09:19:42 -0500 Subject: [PATCH 4/4] Do the same for plotTag() --- R/images.R | 6 +++--- man/plotTag.Rd | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/R/images.R b/R/images.R index 791553d6..7feca7cf 100644 --- a/R/images.R +++ b/R/images.R @@ -131,14 +131,14 @@ capturePlot <- function(expr, filename = tempfile(fileext = ".png"), #' #' @seealso [capturePlot()] saves plots as an image file. #' -#' @examples +#' @examplesIf rlang::is_interactive() #' img <- plotTag({ #' plot(cars) #' }, "A plot of the 'cars' dataset", width = 375, height = 275) #' -#' if (interactive()) img +#' img #' -#' if (interactive() && capabilities("cairo")) { +#' if (capabilities("cairo")) { #' plotTag( #' plot(pressure), "A plot of the 'pressure' dataset", #' device = grDevices::svg, width = 375, height = 275, pixelratio = 1/72, diff --git a/man/plotTag.Rd b/man/plotTag.Rd index da332789..66e647d6 100644 --- a/man/plotTag.Rd +++ b/man/plotTag.Rd @@ -61,20 +61,21 @@ source. Capture a plot as a self-contained \verb{} tag } \examples{ +\dontshow{if (rlang::is_interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} img <- plotTag({ plot(cars) }, "A plot of the 'cars' dataset", width = 375, height = 275) -if (interactive()) img +img -if (interactive() && capabilities("cairo")) { +if (capabilities("cairo")) { plotTag( plot(pressure), "A plot of the 'pressure' dataset", device = grDevices::svg, width = 375, height = 275, pixelratio = 1/72, mimeType = "image/svg+xml" ) } - +\dontshow{\}) # examplesIf} } \seealso{ \code{\link[=capturePlot]{capturePlot()}} saves plots as an image file.