Learn R Programming

R2SWF (version 0.7-1)

dev2swf: Convert R graphics to SWF using different graphics devices

Description

Given an R expression that can produce a sequence of images, this function will record the images with the device provided (e.g. png() or jpeg()) and convert them to a Flash file.

Usage

dev2swf(expr, output = "movie.swf", bgColor = "white",
    interval = 1, dev = "png", file.ext = "png",
    img.name = "Rplot", ...)

Arguments

expr
an expression to generate a sequence of images
output
the name of the output swf file
bgColor
background color of the output SWF file
interval
the time interval between animation frames
dev
the name of the graphics device to use (e.g. 'png' or 'jpeg')
file.ext
the file extension for the images
img.name
the file name of the images without the extension
...
other arguments to be passed to the graphics device

Value

  • The name of the generated swf file if succeeded.

Details

You can also use devices which are not in the grDevices package by setting the dev argument to the name of the function that opens a device, e.g. CairoPNG() in the Cairo package. Note that the file.ext argument should be set accordingly.

Examples

Run this code
olddir = setwd(tempdir())
output1 = dev2swf({
  for(i in 1:10) plot(runif(20), ylim = c(0, 1))
}, dev='png', file.ext='png', output='movie-png.swf')
swf2html(output1)

if(capabilities("cairo")) {
    output2 = dev2swf({
        for(i in 1:10) plot(runif(20), ylim = c(0, 1))
    }, dev='svg', file.ext='svg', output='movie-svg.swf')
}
swf2html(output2)

setwd(olddir)

Run the code above in your browser using DataLab