make_movie: Create GIF animations

Description Usage Arguments Details Value Examples

View source: R/make_movie.R

Description

From the output of the function run_experiment with display, create a .gif file of the output for one specific columns. One gif will be created for each experiment (rows in the input object).

Usage

1
2
make_movie(exp, name_col, output_path = NULL, autoplay = TRUE,
  interval = 0.01, loop = TRUE, autobrowse = FALSE, ...)

Arguments

exp

an object of class experiment.

name_col

character string, name of the column containing the display information (format .png).

output_path

path to store the .gif file generated, if NULL will take the path store in the attributes of each data frame contained in the column output.

autoplay

logical, whether to autoplay the animation when the HTML page is loaded (default to be TRUE).

interval

a positive number to set the time interval of the animation (unit in seconds); default to be 0.01.

loop

logical or numeric, Number of times the GIF animation is to cycle; default TRUE (infinite loop)

autobrowse

logical: whether auto-browse the animation page immediately after it is created?; default to be FALSE

...

arguments in tag = value form, or a list of tagged values. The tags usually come from the animation parameters.

Details

The function uses the package animation to generate the .gif file(s). Please take a look at the documentation of the package and to the website https://yihui.name/animation for more information on the usage and the installation of this package.

The arguments autoplay, interval, loop, autobrowse and ... are used to control the behaviour of the animation, see ?animation::ani.options for more details..

Value

path the gif file(s) invisibly.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Load an experiment
exp <- load_experiment("prey_predator",
                       system.file("models/predator_prey/models",
                                   "predator_prey.gaml", package = "rama"))

# to explore the parameters and the observed variables
parameters(exp)
obs_rates(exp)

# to set the experiment
exp$p_Initial_number_of_preys_ <- 990L
exp$p_Initial_number_of_predators_ <- 100L
exp$p_Predator_probability_reproduce_ <- 0.1
exp$tmax <- 100L

# to run the experiment
out <- run_experiment(exp, hpc = 2, display = TRUE)

# to visualize the output
with(out$output[[1]],
    plot(Step, `r_Number_of_preys`, type = "l", lwd = 2, col = "red"))

# to make a movie
path_movie <- make_movie(out, "r_main_display")

# to print the result, it is necessary to have the package `magick`
magick::image_read(path_movie)

r-and-gama/rama documentation built on July 19, 2019, 9:49 p.m.