Learn R Programming

⚠️There's a newer version (1.8-54) of this package.Take me there.

terra

This R package is a replacement of the raster package. It has a very similar, but simpler, interface, and it is much faster.

All native computations are done in C++. Classes, methods and properties are exposed via a Rcpp module. The R side has two main S4 classes (SpatRaster and SpatVector) that represent spatial data. These classes have only slot, a reference to a C++ object. They are used to provide a "normal" "S4" R user-interface as in the raster package.

The first (alpha) release is expected by July 2019.

Installation

You need to install the latest version of "raster" from CRAN or github.

Windows

If you are on Windows, you need to first install Rtools to get a C++ compiler that R can use. After that, you need the first install development version of "raster" for "terra" to work.

Then, in R, install the packages.

library(devtools)
install.packages("raster")
#devtools::install_github("rspatial/raster")
devtools::install_github("rspatial/terra")

Mac - OSX

The libraries GDAL (>= 2.0.0), GEOS (>= 3.3.0) and Proj.4 (>= 4.8.0) are required (as for sf)

With Homebrew you can do:

brew install gdal

And now, in R, install the packages.

library(devtools)
install.packages("raster")
devtools::install_github("rspatial/terra")

Linux

The libraries GDAL (>= 2.0.0), GEOS (>= 3.3.0) and Proj.4 (>= 4.8.0) are required (as for sf)

To install these on Ubuntu you can do:

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install libgdal-dev libgeos-dev libproj-dev 

And now, in R, install the packages.

library(devtools)
install.packages("raster")
devtools::install_github("rspatial/terra")

See the sf instructions for installation on other linux systems.

Copy Link

Version

Install

install.packages('terra')

Monthly Downloads

185,852

Version

0.4-4

License

GPL (>=3)

Issues

Pull Requests

Stars

Forks

Maintainer

Robert Hijmans

Last Published

June 1st, 2025

Functions in terra (0.4-4)

buffer

Create a buffer around vector objects or raster patches
density

Density plot
atan2

Two argument arc-tangent
as.data.frame

Get the attributes of a SpatVector
clamp

Clamp values
boundaries

Detect boundaries (edges)
distance

Geographic distance
click

Query by clicking on a map
ifel

ifelse for SpatRaster objects
area

Area and perimeter
crs

Get or set a coordinate reference system (projection)
focal

Focal values
flip

Flip a raster
draw

Draw a polygon, line, extent, or points
c

Combine
dimensions

Dimensions of a SpatRaster or SpatVector
extend

Extend
crop

Cut out a geographic subset
contour

Contour plot
compareGeom

Compare geometries of SpatRaster objects
extract

Extract values from a SpatRaster
cover

Cover (replace) NA values with values of another raster
collapse

Collapse cell values from a multi-layer SpatRaster
coerce

Coercion to other object types
disaggregate

Disaggregate raster cells
SpatDataFrame-class

C++ classes
freq

Frequency table
extent

Create, get or set a SpatExtent
geomtype

Geometry type of a SpatVector
interpolate

Interpolate
names

Names of Spat objects
factors

Factors
isLonLat

Check for longitude/latitude crs
hist

Histogram
global

global statistics
head and tail

Show the head or tail of a Spat* object
math

Mathematical operations with SpatRaster objects
local

Local statistics
initialize

Initialize a SpatRaster with values
project

Change the coordinate reference system
merge

Merge SpatRaster or SpatExtent objects, or a SpatVector with a data.frame
mask

Mask values in a SpatRaster
geom

Get the geometry (coordinates) of a SpatVector
range

Get or compute the minimum and maximum cell values
tmpFiles

Temporary files
quantile

SpatRaster local quantiles
overlay

Overlay SpatRaster objects
transpose

Transpose
xyRowColCell

Coordinates from a row, column or cell number and vice versa
select

Geometric subsetting
persp

Perspective plot
slope

Compute slopes
modal

modal value
shift

Shift
sources

Data sources of a SpatRaster
zoom

Zoom in on a map
pack

pack a Spat* object
plot

Plot a SpatRaster or SpatVector
rotate

Rotate a SpatRaster along longitude
plotRGB

Red-Green-Blue plot of a multi-layered SpatRaster
read and write

Read from, or write to, file
zonal

Zonal statistics
unique

Unique values
trim

Trim a SpatRaster
pairs

Pairs plot (matrix of scatterplots)
subset

Subset of a SpatRaster
spatSample

Take a regular sample
predict

Spatial model predictions
vector-attributes

Get or replace attribute values of a SpatVector
subset-vector

Subset of a SpatVector
tapp

Apply a function to subsets of layers of a SpatRaster
terra-package

The "terra" package
warp

Transfer values of a SpatRaster to another one with a different geometry
writeRaster

Write raster data to a file
rasterize

Rasterize vector data
rast

Create a SpatRaster
SpatOptions-class

Inspect of set general options for "terra"
text

Add labels to a map
writeVector

Write vector data to a file
values

Get cell values
xmin

Get or set single values of an extent
vect

Create SpatVector objects
SpatRaster-class

SpatRaster class
SpatExtent-class

Class "SpatExtent"
aggregate

Aggregate raster cells
adjacent

Adjacent cells
SpatVector-class

Class "SpatVector"
as.character

Create a text representation of (the skeleton of) an object
align

Align a SpatExtent with a SpatRaster
app

Apply a function to the cells of a SpatRaster
classify

Classify (or reclassify) cell values