You can use the animation package with the raster package. Here is a demo:
library(raster)
library(animation)
logo <- raster(system.file("external/rlogo.grd", package = "raster"), values = TRUE)
saveMovie(for (i in seq(1, 250, 20)) {
logo1 <- logo
logo1[logo1 < i] <- 0
plot(logo1, main = i)
}, interval = 0.5, outdir = getwd(), movie.name = "logo.gif")
Here is a demo to show you the real flexibility of the save*() functions. Let's take saveHTML() for example:
library(animation)
saveHTML({
## a custom file list on the Internet
extList = c('http://yihui.name/cn/wp-content/uploads/1192203237_1.jpg',
'http://yihui.name/cn/wp-content/uploads/1192203252_1.jpg',
'http://yihui.name/cn/wp-content/uploads/1191914651_1.jpg')
for (i in 1:length(extList)) {
download.file(url = extList[i], destfile = sprintf(ani.options("img.fmt"), i), mode = 'wb')
}
}, use.dev = FALSE, ani.width = 640, ani.height = 480, ani.type = 'jpg',
interval = 2, single.opts = "'dwellMultiplier': 1")