Skip to contents

From a spacetime object, activate either the data or geometry contexts. The active object will then become available for manipulation.

Usage

active(.data)

activate(.data, what)

Arguments

.data

a spacetime object

what

default NULL. Determines which context to activate. Valid argument values are "geometry" and "data". If left null, returns .data.

Value

For activate() an object of class spacetime with the specified context activated. active() returns a scalar character with the active context can be either "goemetry" or "data".

Details

A spacetime object contains both a data frame and an sf object. The data frame represents geographies over one or more time periods and the sf object contains the geographic information for those locations.

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)

# Create spacetime object called `bos`
bos <- spacetime(df, geo,
                 .loc_col = ".region_id",
                 .time_col = "time_period")

active(bos)
#> [1] "data"
activate(bos, "geometry")
#> spacetime ────
#> Context:`geometry`
#> 168 locations `.region_id`
#> 10 time periods `time_period`
#> ── geometry context ────────────────────────────────────────────────────────────
#> Simple feature collection with 168 features and 1 field
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -71.19115 ymin: 42.22788 xmax: -70.99445 ymax: 42.3974
#> Geodetic CRS:  NAD83
#> # A tibble: 168 × 2
#>    .region_id                                                           geometry
#>  * <chr>                                                           <POLYGON [°]>
#>  1 25025010405 ((-71.09009 42.34666, -71.09001 42.34668, -71.08941 42.34685, -7…
#>  2 25025010404 ((-71.09066 42.33977, -71.09103 42.33961, -71.09177 42.33989, -7…
#>  3 25025010801 ((-71.08159 42.3537, -71.08044 42.35402, -71.07995 42.35415, -71…
#>  4 25025010702 ((-71.07066 42.35185, -71.07045 42.35142, -71.07282 42.35075, -7…
#>  5 25025010204 ((-71.10683 42.34875, -71.1052 42.34844, -71.10468 42.34834, -71…
#>  6 25025010802 ((-71.08159 42.3537, -71.08153 42.35358, -71.08145 42.3534, -71.…
#>  7 25025010104 ((-71.08784 42.34746, -71.08805 42.34746, -71.0883 42.34747, -71…
#>  8 25025000703 ((-71.12622 42.35041, -71.12685 42.35009, -71.12748 42.35, -71.1…
#>  9 25025000504 ((-71.14175 42.3404, -71.14194 42.34001, -71.14234 42.34005, -71…
#> 10 25025000704 ((-71.13551 42.34878, -71.13572 42.34904, -71.1358 42.34917, -71…
#> # … with 158 more rows
#> # ℹ Use `print(n = ...)` to see more rows