dev2swf: Convert R graphics to SWF using different graphics devices

Description Usage Arguments Details Value Author(s) Examples

View source: R/xx2swf.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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

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.

Value

The name of the generated swf file if succeeded.

Author(s)

Yihui Xie <https://yihui.org>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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)

R2SWF documentation built on Sept. 13, 2021, 1:06 a.m.