spacetime: Construct a 'spacetime' object

View source: R/spacetime-constructor.R

spacetimeR Documentation

Construct a spacetime object

Description

A 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.

Usage

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, ...)

Arguments

.data

an object with base class data.frame containing location and time identifiers .loc_col and .time_col respectively.

.geometry

an sf object with columns .loc_col and .time_col

.loc_col

the quoted name of the column containing unique location identifiers. Must be present in both .data and .geometry.

.time_col

the quoted name of the column containing time periods must be present .data. See details for more

active

default "data". The object to make active. See activate() for more.

x

an object to test

...

unused

Details

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().

Value

  • 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

Validation

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

Examples


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



sfdep documentation built on Sept. 13, 2024, 5:07 p.m.