Skip to content

{gganimate} rendering fails with svg figure output #6643

@mmbcorley

Description

@mmbcorley

Bug description

When rendering to html with fig-output: svg, plots which make use of {gganimate} won't render. Errors implicate device(), as below.

Error in `device()`:
! unused arguments (units = "in", res = 96)

A workaround is to set dev: png in the relevant chunk options. This fails, however, if a plot is saved and then rendered with animate().

Steps to reproduce

Apologies for the slightly long example. The document will render fine if fig-format: svg is removed from the yaml header.

---
title: "gganimate example"
execute: 
  fig-format: svg
  echo: false
---

```{r}
library(gganimate)
```

Should work (using `#| dev: png`): 

```{r}
#| dev: png
ggplot(mtcars, aes(factor(cyl), mpg)) + 
  geom_boxplot() + 
  transition_states(gear)
```

Will fail (no device override):

```{r}
ggplot(mtcars, aes(factor(cyl), mpg)) + 
  geom_boxplot() + 
  transition_states(gear)
```

Will fail (device override but uses `animate()`)

```{r}
#| dev: png
p <- ggplot(mtcars, aes(factor(cyl), mpg)) + 
  geom_boxplot() + 
  transition_states(gear)
animate(p)
```

Expected behavior

The animated plots should be created without needing to change device settings, or restrictions on devices should be clearly documented. It should be possible to render an animated plot using animate() in a document which has a global setting of fig-format: svg (at the moment that does not appear to be the case).

Actual behavior

An error is raised when attempting to render an animation, unless dev: png is in the chunk options.
However even when dev: png is in the chunk options, if animate() is called, an error is raised.

Your environment

  • IDE: RStudio 2023.06.2+561
  • OS: Arch Linux (kernel 6.4.12-zen1-1-zen)

Quarto check output

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.3.450
      Path: /opt/quarto/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.11.5
      Path: /usr/bin/python3
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

[✓] Checking R installation...........OK
      Version: 4.3.1
      Path: /usr/lib64/R
      LibPaths:
        - /home/martinc/lib/R
        - /usr/lib/R/library
      knitr: 1.43
      rmarkdown: 2.24

[✓] Checking Knitr engine render......OK

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingengines-knitrAnything regarding knitr enginesupstreamBug is in upstream librarywontfixThis will not be worked on

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions