View source: R/spacetime-constructor.R
| spacetime | R Documentation |
spacetime objectA spacetime object is a collection of a linked data frame and an sf objects. It can be thought of as geography linked to a table that represents those geographies over one or more time periods.
spacetime(.data, .geometry, .loc_col, .time_col, active = "data")
new_spacetime(.data, .geometry, .loc_col, .time_col, active = "data")
validate_spacetime(.data, .geometry, .loc_col, .time_col)
is_spacetime(x, ...)
is.spacetime(x, ...)
.data |
an object with base class |
.geometry |
an |
.loc_col |
the quoted name of the column containing unique location identifiers. Must be present in both |
.time_col |
the quoted name of the column containing time periods must be present |
active |
default |
x |
an object to test |
... |
unused |
Create a spacetime representation of vector data from a data.frame and an
sf object with spacetime()
.time_col must be able to be sorted. As such, .time_col
cannot be a character vector. It must have a base type of (typeof()) either
double or integer—the case in dates or factors respectively. An edge case
exists with POSIXlt class objects as these can be sorted appropriately but
have a base type of list.
spacetime() is a wrapper around new_spacetime(). Spacetimes are
validated before creation with validate_spacetime().
Check if an object is a spacetime object with is_spacetime() or
is.spacetime().
spacetime() and new_spacetime() construct spacetime clss objects
validate_spacetime() returns nothing but will elicit a warning or error if the spacetime object is not validly constructed
is_spacetime() and is.spacetime() return a logical scalar indicating if an object inherits the spacetime class
validate_spacetime() checks both .data and .geometry to ensure that
the constructed spacetime object meets minimum requirements.:
.data inherits the data.frame class
.geometry is an sf object
ensures that .time_col is of the proper class
ensures there are no missing geometries in .geometry
checks for duplicate geometries
ensures .loc_col are the same type in .data and .geometry
lastly informs of missing values in additional columns in .data
df_fp <- system.file("extdata", "bos-ecometric.csv", package = "sfdep")
geo_fp <- system.file("extdata", "bos-ecometric.geojson", package = "sfdep")
# read in data
df <- read.csv(
df_fp, colClasses = c("character", "character", "integer", "double", "Date")
)
geo <- sf::st_read(geo_fp)
bos <- spacetime(df, geo, ".region_id", "year")
is_spacetime(bos)
bos
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.