Skip to content

Commit

Permalink
add ragg support
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Oct 14, 2020
1 parent 643a3bc commit 68871ec
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: TRUE
VignetteBuilder: knitr
RoxygenNote: 7.1.0.9000
RoxygenNote: 7.1.1
Roxygen: list(markdown = TRUE)
URL: https://gganimate.com, https://github.com/thomasp85/gganimate
BugReports: https://github.com/thomasp85/gganimate/issues
Expand All @@ -35,7 +35,8 @@ Imports: stringi,
scales,
grDevices,
utils
Suggests: magick,
Suggests:
magick,
svglite,
knitr,
rmarkdown,
Expand All @@ -45,7 +46,8 @@ Suggests: magick,
covr,
transformr,
av,
gifski
gifski,
ragg
Collate:
'aaa.R'
'anim_save.R'
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# gganimate (development version)

* Support ragg png device to ensure that it works with knitr's ragg support

# gganimate 1.0.6

# gganimate 1.0.5
Expand Down
10 changes: 8 additions & 2 deletions R/animate.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
#' @param renderer The function used to render the generated frames into an
#' animation. Gets a vector of paths to images along with the framerate. (default [gifski_renderer()])
#' @param device The device to use for rendering the single frames. Possible
#' values are `'png'`, `'jpeg'`, `'tiff'`, `'bmp'`, `'svg'`, and `'svglite'`
#' (requires the svglite package). (default `'png'`)
#' values are `'png'`, `'ragg_png'` (requires the ragg package), `'jpeg'`,
#' `'tiff'`, `'bmp'`, `'svg'`, and `'svglite'` (requires the svglite package).
#' (default `'png'`)
#' @param ref_frame The frame to use for fixing dimensions of the plot, e.g. the
#' space available for axis text. Defaults to the first frame. Negative values
#' counts backwards (-1 is the last frame) (default `1`)
Expand Down Expand Up @@ -226,6 +227,9 @@ prepare_args <- function(nframes, fps, duration, detail, renderer, device, ref_f
if (args$device == 'svglite' && !requireNamespace('svglite', quietly = TRUE)) {
stop('The svglite package is required to use this device', call. = FALSE)
}
if (args$device == 'ragg_png' && !requireNamespace('ragg', quietly = TRUE)) {
stop('The ragg package is required to use this device', call. = FALSE)
}
args$ref_frame <- ref_frame %?% chunk_args$ref_frame %||% getOption('gganimate.ref_frame', 1)
args$start_pause <- start_pause %?% chunk_args$start_pause %||% getOption('gganimate.start_pause', 0)
args$end_pause <- end_pause %?% chunk_args$end_pause %||% getOption('gganimate.end_pause', 0)
Expand Down Expand Up @@ -262,6 +266,7 @@ draw_frames <- function(plot, frames, device, ref_frame, ...) {
files <- file.path(dir, sprintf('gganim_plot%04d', seq_along(frames)))
files <- switch(
tolower(device),
ragg_png = ,
png = paste0(files, '.png'),
jpg = ,
jpeg = paste0(files, '.jpg'),
Expand All @@ -275,6 +280,7 @@ draw_frames <- function(plot, frames, device, ref_frame, ...) {
)
device <- switch(
device,
ragg_png = ragg::agg_png,
png = png,
jpg = ,
jpeg = jpeg,
Expand Down
7 changes: 4 additions & 3 deletions man/animate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/gganimate.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ will do. The return value of your renderer is what is ultimately returned by the

Below are a couple of examples of different `animate()` calls:

```{r}
```{r, eval=requireNamespace('av', quietly = TRUE)}
# Video output
animate(
anim + enter_fade() + exit_fly(y_loc = 1),
Expand Down

0 comments on commit 68871ec

Please sign in to comment.