Skip to contents

Given an object with class spacetime, determine if it is a spacetime cube. If the time-series is is irregular a warning is emitted (see validate_spacetime() for more on the restrictions on the time column.


is_spacetime_cube(x, ...)



a spacetime object




A logical scalar.


A spacetime object is a spacetime cube when it contains a regular time-series representation of each geometry. That is, only one observation for at each time period per geography is present.

The number of rows in a spacetime cube is the number of geographies multiplied by the number of time periods. For example if there are 10 locations and 20 time periods, the number of rows must be 200.


is_spacetime_cube() runs a number of checks that to ensure that the provided object is in fact a spacetime cube. It checks that:

  • the number of rows is equal to the number of locations multiplied by the number of time periods

  • each time period has an equal number of observations

  • each location has an equal number of observations

  • each combination of time period and location has only one observation

  • that the time-series is regular


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")

#> [1] TRUE
is_spacetime_cube(bos[round(runif(1000, 0, nrow(bos))),])
#> ! Number of rows does not equal `n time-periods x n locations`
#> [1] FALSE
#> [1] FALSE