Skip to contents

Persist a scene so it can be rebuilt later, in another session, or in another process. .rds is the default and needs nothing extra; .json produces a portable text format and needs the jsonlite package.

Usage

scene_write(scene, path)

scene_read(path)

Arguments

scene

A vl_scene(), or anything with an as_vellum_scene() method.

path

File path. The extension picks the format (.rds or .json).

Value

scene_write(): path, invisibly. scene_read(): a vellum_scene.

Details

What this buys you: caching a built scene without re-running the code that built it, sending one over a wire for a worker to render, and keeping a reproducible intermediate between "the code" and "the pixels".

Examples

s <- vl_scene(2, 2) |> draw(circle_grob(gp = vl_gpar(fill = "steelblue")))
f <- tempfile(fileext = ".rds")
scene_write(s, f)
identical(as_scene_spec(scene_read(f)), as_scene_spec(s))
#> [1] TRUE