2

I am trying to produce an animated plot with gganimate following instructions from the knitr documentation:

knitr::opts_chunk$set(message = FALSE, warning = FALSE, fig.show = "animate")
# Example from https://github.com/dgrtwo/gganimate
library(ggplot2)
library(gganimate)

# For example, suppose we wanted to create an animation similar to the Gapminder 
# world animation, using Jenny Bryan's gapminder package for the data.
library(gapminder)

theme_set(theme_bw())
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
  geom_point() +
  scale_x_log10()

# Notice we added frame = year and saved the plot as p. 
# We then display it as an animation with the gg_animate function:
gg_animate(p)

However, I am getting the error:

Error: Could not find ffmpeg command. You should either change the animation.fun hook option or install ffmpeg with libvpx enabled.

I have followed the instructions here to install ffmpeg, and running ffmpeg -version in the command line gives:

C:\ffmpeg\bin>ffmpeg -version
ffmpeg version 3.2.2 Copyright (c) 2000-201
built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-versio
nable-nvenc --enable-avisynth --enable-bzli
 --enable-gnutls --enable-iconv --enable-li
s2b --enable-libcaca --enable-libfreetype -
le-libilbc --enable-libmodplug --enable-lib
enable-libopencore-amrwb --enable-libopenh2
pus --enable-librtmp --enable-libsnappy --e
ble-libtheora --enable-libtwolame --enable-
enable-libvorbis --enable-libvpx --enable-l
ibx264 --enable-libx265 --enable-libxavs --
ble-lzma --enable-decklink --enable-zlib
libavutil      55. 34.100 / 55. 34.100
libavcodec     57. 64.101 / 57. 64.101
libavformat    57. 56.100 / 57. 56.100
libavdevice    57.  1.100 / 57.  1.100
libavfilter     6. 65.100 /  6. 65.100
libswscale      4.  2.100 /  4.  2.100
libswresample   2.  3.100 /  2.  3.100
libpostproc    54.  1.100 / 54.  1.100

What should I do now? In particular, what does it mean to 'change the animation.fun hook option'?

EDIT: I have just noticed that system('ffmpeg -version') returns a 127 status code, but works fine from my command line.

Alex
  • 15,186
  • 15
  • 73
  • 127
  • I disagree with the proposed closed reason. The problem is not to do with a simple typographical error, there is nothing in the documentation to 1) suggest a restart. 2) tell you how to specify `animation.fun` hook explicitly to call whatever program you installed. – Alex Dec 21 '16 at 23:28
  • 3
    I vote to close as this specific problem can no longer be reproduced. – Axeman Jul 11 '17 at 08:12
  • 3
    It means you encountered a problem, solved it by installing the library. At least on windows, you always need to restart the command line tool to refresh the PATH variable in order to access the newly added elements. Your problem is not with knitr, gganimate, ggplot or R, but the way windows and their programs are designed. – Roman Luštrik Jul 11 '17 at 08:47

1 Answers1

4

A restart of Rstudio and presumably the underlying Rsession fixed the problem.

Alex
  • 15,186
  • 15
  • 73
  • 127