Skip to contents

These functions provide support reading and writing routes and intervals from and to HDF5 files while preserving class names and attributes.

Usage

write_routes(obj, path)

# S3 method for class 'Routes'
write_routes(obj, path)

# S3 method for class 'BirdFlowRoutes'
write_routes(obj, path)

# Default S3 method
write_routes(obj, path)

read_routes(path)

read_intervals(path)

write_intervals(obj, path)

Arguments

obj

For write_routes() a Routes, or BirdFlowRoutes object. For write_intervals() a BirdFlowIntervals object.

path

Path to write or read from, should end in .hdf5

Value

  • write_routes() and write_intervals() invisibly return their input object (after writing to disk).

  • read_routes() returns the written object - either Routes or BirdFlowRoutes.

  • read_intervals() return the written BirdFlowIntervals object.

Details

The Hierarchical Data Format version 5 (HDF5) is an open format to efficiently store large, heterogeneous data sets. HDF5 files can be written and read from R and Python among other languages so make a good cross-language format for routes and intervals.

read_routes() and write_routes() work on both Routes and BirdFlowRoutes. See as_routes() and as_birdflow_routes() to create objects of these classes.

read_intervals() and write_intervals() work on BirdFlowIntervals which are a collection of movements each with a single start and end derived from BirdFlowRoutes. See as_birdflow_intervals().

Internal functions

  • write_r_object_h5() and read_r_object_h5() are internal workhorses: they handle the recursive traversal of R lists (including data.frames, Date/POSIX/Factor vectors) and store both data and class attributes in the HDF5 file hierarchy.

See also

Examples

# \donttest{
bf <- BirdFlowExamples::amewoo
rts <- route(bf, n = 3)

route_path <- tempfile(fileext = ".hdf5")
write_routes(rts, route_path)
rts2 <- read_routes(route_path)
identical(class(rts), class(rts2))
#> [1] TRUE

ivl <- as_birdflow_intervals(rts)
interval_path <- tempfile(fileext = ".hdf5")
write_intervals(ivl, interval_path)
ivl2 <- read_intervals(interval_path)
identical(class(ivl), class(ivl2))
#> [1] TRUE
# }