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..7feca7cf 100644 --- a/R/images.R +++ b/R/images.R @@ -17,12 +17,12 @@ #' @seealso [plotTag()] saves plots as a self-contained `` #' tag. #' -#' @examples +#' @examplesIf rlang::is_interactive() #' # Default settings #' 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) #' } #' @@ -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/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{} 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.