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 first 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)
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)
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 libproj-dev 

And now, in R, install the packages.

library(devtools)
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

229,584

Version

0.2-7

License

GPL (>=3)

Issues

Pull Requests

Stars

Forks

Maintainer

Robert Hijmans

Last Published

June 1st, 2025

Functions in terra (0.2-7)

c

Combine
SpatRaster-class

SpatRaster class
as.data.frame

Get the attributes of a SpatVector
Summary-methods

Summary methods
area

Area and length
SpatVector-class

Class "SpatVector"
atan2

Two argument arc-tangent
SpatExtent-class

Class "SpatExtent"
adjacent

Adjacent cells
click

Query by clicking on a map
dimensions

Dimensions of a SpatRaster or SpatVector
read and write

read from or write to file
names

Names of Spat* objects
overlay

Overlay SpatRaster objects
coerce

Coercion to other object types
reclassify

Reclassify
cover

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

Compare geometries of SpatRaster objects
geom

geom
geomtype

Geometry type of a SpatVector
aggregate

Aggregate raster cells
disaggregate

Disaggregate raster cells
draw

Draw a line, polygon, extent, or points
crs

Get or set a coordinate reference system (projection)
extract

Extract values from a SpatRaster
crop

Crop
gridDistance

Distance on a grid
predict

Spatial model predictions
extent

ext
math

Mathematical operations with SpatRaster objects
mask

Mask values in a SpatRaster
project

Change the coordinate reference system
head and tail

Show the head or tail of a Spat* object
hist

Histogram
rotate

rotate
ifel

ifelse for SpatRaster objects
reduce

reduce
merge

Merge SpatRaster or SpatExtent objects
vect

Create SpatVector objects
unique

Unique values
trim

Trim a SpatRaster
values

Get cell values
plot

Plot a SpatRaster or SpatVector
plotRGB

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

get or compute min and max values
sampleRegular

Take a regular sample
shift

Shift
clamp

Clamp values
subset-vector

Subset of a SpatVector
SpatDataFrame-class

C++ classes
sources

Data sources of a SpatRaster
xyRowColCell

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

Factors
subset

Subset of a SpatRaster
terra-package

terra
transpose

Transpose
SpatOptions-class

options
flip

Flip a raster
initialize

Initialize a SpatRaster with values
isLonLat

Check for longitude/latitude crs
focal

Focal values
rast

Create a SpatRaster
rasterize

rasterize
writeRaster

Write raster data to a file
warp

warp a SpatRaster
boundaries

boundaries (edges) detection
zonal

Zonal statistics
local

Local statistics
global

global statistics
zoom

Zoom in on a map