Skip to contents

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

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

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

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 <- readr::read_csv(df_fp, col_types = "ccidD")
geo <- sf::read_sf(geo_fp)

bos <- spacetime(df, geo, ".region_id", "year")
is_spacetime(bos)
#> [1] TRUE
bos
#> spacetime ────
#> Context:`data`
#> 168 locations `.region_id`
#> 10 time periods `year`
#> ── data context ────────────────────────────────────────────────────────────────
#> # A tibble: 1,680 × 5
#>    .region_id  ecometric  year value time_period
#>  * <chr>       <chr>     <int> <dbl> <date>     
#>  1 25025010405 Guns       2010  0.35 2010-01-01 
#>  2 25025010405 Guns       2011  0.89 2011-01-01 
#>  3 25025010405 Guns       2012  1.2  2012-01-01 
#>  4 25025010405 Guns       2013  0.84 2013-01-01 
#>  5 25025010405 Guns       2014  1.5  2014-01-01 
#>  6 25025010405 Guns       2015  1.15 2015-01-01 
#>  7 25025010405 Guns       2016  1.48 2016-01-01 
#>  8 25025010405 Guns       2017  1.64 2017-01-01 
#>  9 25025010405 Guns       2018  0.49 2018-01-01 
#> 10 25025010405 Guns       2019  0.17 2019-01-01 
#> # … with 1,670 more rows
#> # ℹ Use `print(n = ...)` to see more rows