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 have the current version of raster from CRAN (>= 2.9-22) or install the development version of "raster".

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/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 libgeos++-dev libproj-dev 

And now, in R, install the packages.

library(devtools)
install.packages("raster")
#devtools::install_github("rspatial/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.2-13

License

GPL (>=3)

Issues

Pull Requests

Stars

Forks

Maintainer

Robert Hijmans

Last Published

March 26th, 2026

Functions in terra (0.2-13)

aggregate

Aggregate raster cells
align

Align a SpatExtent with a SpatRaster
SpatVector-class

Class "SpatVector"
SpatRaster-class

SpatRaster class
adjacent

Adjacent cells
SpatExtent-class

Class "SpatExtent"
as.data.frame

Get the attributes of a SpatVector
atan2

Two argument arc-tangent
area

Area and length
app

Apply a function to the cells of a SpatRaster
SpatDataFrame-class

C++ classes
compareGeom

Compare geometries of SpatRaster objects
collapse

Collapse cell values from a multi-layer SpatRaster
classify

Classify (or reclassify) cell values
dimensions

Dimensions of a SpatRaster or SpatVector
density

Density plot
c

Combine
clamp

Clamp values
disaggregate

Disaggregate raster cells
click

Query by clicking on a map
focal

Focal values
extent

Create, get or set a SpatExtent
distance

Geographic distance
coerce

Coercion to other object types
freq

Frequency table
factors

Factors
crop

Cut out a geographic subset
crs

Get or set a coordinate reference system (projection)
merge

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

Mathematical operations with SpatRaster objects
mask

Mask values in a SpatRaster
draw

Draw a polygon, line, extent, or points
extend

Extend
names

Names of Spat objects
overlay

Overlay SpatRaster objects
subset

Subset of a SpatRaster
tapp

Apply a function to subsets of layers of a SpatRaster
initialize

Initialize a SpatRaster with values
sources

Data sources of a SpatRaster
flip

Flip a raster
interpolate

Interpolate
subset-vector

Subset of a SpatVector
values

Get cell values
unique

Unique values
writeRaster

Write raster data to a file
range

Get or compute the minimum and maximum cell values
hist

Histogram
ifel

ifelse for SpatRaster objects
extract

Extract values from a SpatRaster
plot

Plot a SpatRaster or SpatVector
predict

Spatial model predictions
plotRGB

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

Get or set single values of an extent
tmpFiles

Temporary files
vector-attributes

Get or replace attribute values of a SpatVector
zonal

Zonal statistics
text

Add labels to a map
read and write

Read from, or write to, file
xyRowColCell

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

Detect boundaries (edges)
contour

Contour plot
buffer

Create a buffer around vector objects or raster patches
project

Change the coordinate reference system
geom

Get the geometry (coordinates) of a SpatVector
sampleRegular

Take a regular sample
rotate

Rotate a SpatRaster along longitude
cover

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

Geometry type of a SpatVector
rasterize

Rasterize vector data
local

Local statistics
rast

Create a SpatRaster
isLonLat

Check for longitude/latitude crs
global

global statistics
head and tail

Show the head or tail of a Spat* object
pairs

Pairs plot (matrix of scatterplots)
persp

Perspective plot
terra-package

The "terra" package
SpatOptions-class

Inspect of set general options for "terra"
shift

Shift
trim

Trim a SpatRaster
select

Geometric subsetting
transpose

Transpose
zoom

Zoom in on a map
warp

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

Create SpatVector objects