Learn R Programming

⚠️There's a newer version (1.9-11) 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

228,439

Version

0.4-7

License

GPL (>=3)

Issues

Pull Requests

Stars

Forks

Maintainer

Robert Hijmans

Last Published

March 26th, 2026

Functions in terra (0.4-7)

classify

Classify (or reclassify) cell values
clamp

Clamp values
crs

Get or set a coordinate reference system (projection)
SpatDataFrame-class

C++ classes
extract

Extract values from a SpatRaster
adjacent

Adjacent cells
math

Mathematical operations with SpatRaster objects
factors

Factors
buffer

Create a buffer around vector objects or raster patches
c

Combine
density

Density plot
mask

Mask values in a SpatRaster
SpatRaster-class

SpatRaster class
click

Query by clicking on a map
persp

Perspective plot
merge

Merge SpatRaster or SpatExtent objects, or a SpatVector with a data.frame
subset-vector

Subset of a SpatVector
atan2

Two argument arc-tangent
compareGeom

Compare geometries of SpatRaster objects
extend

Extend
contour

Contour plot
boundaries

Detect boundaries (edges)
cover

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

Geographic distance
draw

Draw a polygon, line, extent, or points
range

Get or compute the minimum and maximum cell values
pack

pack a Spat* object
coerce

Coercion to other object types
isLonLat

Check for longitude/latitude crs
extent

Create, get or set a SpatExtent
collapse

Collapse cell values from a multi-layer SpatRaster
head and tail

Show the head or tail of a Spat* object
project

Change the coordinate reference system
rast

Create a SpatRaster
spatSample

Take a regular sample
predict

Spatial model predictions
crop

Cut out a geographic subset
focal

Focal values
flip

Flip a raster
xyRowColCell

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

Zoom in on a map
pairs

Pairs plot (matrix of scatterplots)
quantile

SpatRaster local quantiles
ifel

ifelse for SpatRaster objects
disaggregate

Disaggregate raster cells
rasterize

Rasterize vector data
hist

Histogram
plotRGB

Red-Green-Blue plot of a multi-layered SpatRaster
sources

Data sources of a SpatRaster
slope

Compute slopes
dimensions

Dimensions of a SpatRaster or SpatVector
tapp

Apply a function to subsets of layers of a SpatRaster
subset

Subset of a SpatRaster
local

Local statistics
tmpFiles

Temporary files
zonal

Zonal statistics
modal

modal value
freq

Frequency table
read and write

Read from, or write to, file
initialize

Initialize a SpatRaster with values
select

Geometric subsetting
geom

Get the geometry (coordinates) of a SpatVector
names

Names of Spat objects
warp

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

global statistics
rotate

Rotate a SpatRaster along longitude
vector-attributes

Get or replace attribute values of a SpatVector
values

Get cell values
geomtype

Geometry type of a SpatVector
transpose

Transpose
writeRaster

Write raster data to a file
interpolate

Interpolate
overlay

Overlay SpatRaster objects
shift

Shift
plot

Plot a SpatRaster or SpatVector
terra-package

The "terra" package
vect

Create SpatVector objects
xmin

Get or set single values of an extent
text

Add labels to a map
unique

Unique values
trim

Trim a SpatRaster
SpatOptions-class

Inspect of set general options for "terra"
writeVector

Write vector data to a file
area

Area and perimeter
aggregate

Aggregate raster cells
app

Apply a function to the cells of a SpatRaster
as.data.frame

Get the attributes of a SpatVector
SpatExtent-class

Class "SpatExtent"
SpatVector-class

Class "SpatVector"
as.character

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

Align a SpatExtent with a SpatRaster