Learn R Programming

tidyterra (version 1.3.0)

cross_join.SpatVector: Cross joins for SpatVector objects

Description

[Experimental]

Cross joins match each row in x to every row in y.

See dplyr::cross_join() for details.

Usage

# S3 method for SpatVector
cross_join(x, y, ..., copy = FALSE, suffix = c(".x", ".y"))

Value

A SpatVector object.

Arguments

x

A SpatVector created with terra::vect().

y

A data frame or other object coercible to a data frame. If a SpatVector or sf object is provided, this method returns an error.

...

Additional arguments passed to sf::st_as_sf().

copy

If x and y are not from the same data source, and copy is TRUE, then y will be copied into the same src as x. This allows you to join tables across srcs, but it is a potentially expensive operation so you must opt into it.

suffix

If there are non-joined duplicate variables in x and y, these suffixes will be added to the output to disambiguate them. Should be a character vector of length 2.

Methods

Implementation of the generic dplyr::cross_join() method for SpatVector objects.

The geometry column has sticky behavior. The result repeats each geometry in x once for every row in y.

If y has a column named geometry, it is treated as a regular attribute and receives the suffix from suffix.

See Also

dplyr::cross_join().

Other dplyr verbs that operate on pairs of SpatVector and data frame objects: bind_cols.SpatVector, bind_rows.SpatVector, filter-joins.SpatVector, mutate-joins.SpatVector, nest_join.SpatVector(), rows.SpatVector

Examples

Run this code
v <- terra::vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))

labels <- data.frame(period = c("past", "present"))

cross_join(v, labels)

Run the code above in your browser using DataLab