arrange.SpatVector: Order a 'SpatVector' using column values

View source: R/arrange-SpatVector.R

arrange.SpatVectorR Documentation

Order a SpatVector using column values

Description

arrange.SpatVector() orders the geometries of a SpatVector by the values of selected columns.

Usage

## S3 method for class 'SpatVector'
arrange(.data, ..., .by_group = FALSE, .locale = NULL)

Arguments

.data

A SpatVector created with terra::vect().

...

<data-masking> Variables, or functions of variables. Use desc() to sort a variable in descending order.

.by_group

If TRUE, will sort first by grouping variable. Applies to grouped SpatVector only.

.locale

The locale to sort character vectors in.

  • If NULL, the default, uses the "C" locale unless the deprecated dplyr.legacy_locale global option escape hatch is active. See the dplyr-locale help page for more details.

  • If a single string from stringi::stri_locale_list() is supplied, then this will be used as the locale to sort with. For example, "en" will sort with the American English locale. This requires the stringi package.

  • If "C" is supplied, then character vectors will always be sorted in the C locale. This does not require stringi and is often much faster than supplying a locale identifier.

The C locale is not the same as English locales, such as "en", particularly when it comes to data containing a mix of upper and lower case letters. This is explained in more detail on the locale help page under the ⁠Default locale⁠ section.

Value

A SpatVector object.

terra equivalent

terra::sort()

Methods

Implementation of the generic dplyr::arrange() function for SpatVector class.

See Also

dplyr::arrange()

Other single table verbs: filter.Spat, mutate.Spat, rename.Spat, select.Spat, slice.Spat, summarise.SpatVector()

Other dplyr verbs that operate on rows: distinct.SpatVector(), filter.Spat, slice.Spat

Other dplyr methods: 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, relocate.Spat, rename.Spat, rowwise.SpatVector(), select.Spat, slice.Spat, summarise.SpatVector()

Examples


library(terra)
library(dplyr)

v <- vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))

# Single variable

v |>
  arrange(desc(iso2))

# Two variables
v |>
  mutate(even = as.double(cpro) %% 2 == 0, ) |>
  arrange(desc(even), desc(iso2))

# With new variables
v |>
  mutate(area_geom = terra::expanse(v)) |>
  arrange(area_geom)

tidyterra documentation built on March 11, 2026, 9:08 a.m.