Learn R Programming

tidyterra (version 0.7.0)

relocate.Spat: Change layer/attribute order

Description

Use relocate() to change layer/attribute positions, using the same syntax as select.Spat to make it easy to move blocks of layers/attributes at once.

Usage

# S3 method for SpatRaster
relocate(.data, ..., .before = NULL, .after = NULL)

# S3 method for SpatVector relocate(.data, ..., .before = NULL, .after = NULL)

Value

A Spat* object of the same class than .data. See Methods.

Arguments

.data

A SpatRaster created with terra::rast() or a SpatVector created with terra::vect().

...

<tidy-select> layers/attributes to move.

.before, .after

<tidy-select> Destination of layers/attributes selected by .... Supplying neither will move layers/attributes to the left-hand side; specifying both is an error.

<a href="https://CRAN.R-project.org/package=terra"><span class="pkg">terra</span></a> equivalent

terra::subset(data, c("name_layer", "name_other_layer"))

Methods

Implementation of the generic dplyr::relocate() function.

SpatRaster

Relocate layers of a SpatRaster.

SpatVector

The result is a SpatVector with the attributes on a different order.

See Also

dplyr::relocate()

Other dplyr verbs that operate on columns: glimpse.Spat, mutate.Spat, pull.Spat, rename.Spat, select.Spat

Other dplyr methods: arrange.SpatVector(), bind_cols.SpatVector, bind_rows.SpatVector, count.SpatVector(), distinct.SpatVector(), filter-joins.SpatVector, filter.Spat, glimpse.Spat, group-by.SpatVector, mutate-joins.SpatVector, mutate.Spat, pull.Spat, rename.Spat, rowwise.SpatVector(), select.Spat, slice.Spat, summarise.SpatVector()

Examples

Run this code

library(terra)


f <- system.file("extdata/cyl_tile.tif", package = "tidyterra")
spatrast <- rast(f) %>% mutate(aa = 1, bb = 2, cc = 3)

names(spatrast)


spatrast %>%
  relocate(bb, .before = cyl_tile_3) %>%
  relocate(cyl_tile_1, .after = last_col())

Run the code above in your browser using DataLab