Animations in R

Sometimes it is helpful to visualise data in time, especially when doing signal processing. While this can be done easily in Matlab by using VideoWriter on a structure that contains per-frame information, there doesn't seem to be an equivalent in (base) R. ffmpeg is a great tool for video conversions that can be used via a command-line interface. What could be done is to generate images in R representing each frame, and then calling ffmpeg to stich the images up into a movie format. Here is an example of phase shifting a sine wave 1 degree per frame:

Here's the R code used. ffmpeg is called from within R using the system function:

Code tested with both Linux (Arch) and Windows (10).