From b411e46971c60993bba2dcfd103c0803f4a4e2d9 Mon Sep 17 00:00:00 2001 From: Trevor L Davis Date: Tue, 20 Jul 2021 07:34:23 -0700 Subject: [PATCH] fix: Support 'ani.res' for arbitrary graphic devices * Add support for 'ani.res' for arbitrary graphic devices in 'saveGIF()', 'saveHTML()', and 'saveVideo()'. * Should work for any graphic device function with 'res' as an argument. In particular should continue to support R's built-in raster image format devices as well as 'ragg::agg_png()' and R's built-in devices passed in as a function instead of string. * Still no 'ani.res' support in 'saveLatex()' ('pdf' devices recommended) nor 'saveSWF()' (flash no longer supported in many browsers) * Also fixes bug when 'ani.dev' is a function instead of a character vector closes #133, closes #134 --- R/saveGIF.R | 4 +--- R/saveHTML.R | 3 +-- R/saveVideo.R | 3 +-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/R/saveGIF.R b/R/saveGIF.R index f8076366..de708e92 100644 --- a/R/saveGIF.R +++ b/R/saveGIF.R @@ -85,11 +85,9 @@ saveGIF = function( img.fmt = paste(img.name, ani.options('imgnfmt'), '.', file.ext, sep = '') if ((use.dev <- ani.options('use.dev'))){ - if (is.character(ani.options('ani.dev')) && - any(grepl(ani.options('ani.dev'), c("png", "bmp", "jpeg", "tiff")))){ + if ("res" %in% names(formals(ani.dev))){ ani.dev(file.path(tempdir(), img.fmt), width = ani.options('ani.width'), height = ani.options('ani.height'), res = ani.options('ani.res')) - # ,bg = ani.options('ani.bg') } else { ani.dev(file.path(tempdir(), img.fmt), width = ani.options('ani.width'), height = ani.options('ani.height')) diff --git a/R/saveHTML.R b/R/saveHTML.R index 07d2ee0e..14f2f81a 100644 --- a/R/saveHTML.R +++ b/R/saveHTML.R @@ -133,8 +133,7 @@ saveHTML = function( img.fmt = file.path(imgdir, paste(img.name, ani.options('imgnfmt'), '.', ani.type, sep = '')) ani.options(img.fmt = img.fmt) if ((use.dev <- ani.options('use.dev'))) { - if (is.character(ani.options('ani.dev')) && - any(grepl(ani.options('ani.dev'), c("png", "bmp", "jpeg", "tiff")))) { + if ("res" %in% names(formals(ani.dev))){ ani.dev(img.fmt, width = ani.options('ani.width'), height = ani.options('ani.height'), res = ani.options('ani.res')) } else { diff --git a/R/saveVideo.R b/R/saveVideo.R index e9aa4bdf..ca6bb43c 100644 --- a/R/saveVideo.R +++ b/R/saveVideo.R @@ -74,8 +74,7 @@ saveVideo = function( img.fmt = file.path(tempdir(), img.fmt) ani.options(img.fmt = img.fmt) if ((use.dev <- ani.options('use.dev'))) { - if (is.character(ani.options('ani.dev')) && - any(grepl(ani.options('ani.dev'), c("png", "bmp", "jpeg", "tiff")))) { + if ("res" %in% names(formals(ani.dev))){ ani.dev(img.fmt, width = ani.options('ani.width'), height = ani.options('ani.height'), res = ani.options('ani.res')) } else {