Chapter 18 Older R Spatial Packages
R users who have been around a bit longer, in particular before
stars were developed, may be more familiar
with older packages like
fair question is whether they should migrate existing code and/or
existing R packages depending on these packages. The answer is: yes.
Unless someone steps up to volunteer maintaining packages
rgeos, the plan is to retire packages by the end of
2023. Retirement means that maintenance will halt, and that as a
consequence the packages will sooner or later disappear from CRAN.
One reason for retirement is that their maintainer has retired,
another that their role has been superseded by the newer packages.
We hold it not for very likely that a new maintainer will take over,
in part because much of the code of these packages has over a few
decades gradually evolved along with developments in the GEOS,
GDAL and PROJ libraries, and now contains numerous constructs that
are no longer necessary and make it hard to read.
rgdal retire, existing ties that package
rgeos can and will be replaced by ties to
sf. This only involves validation of coordinate reference
system identifiers, and checking whether rings are holes or exterior
rings. Theoretically one could replace
packages that would call into
sf for their ties to the GEOS,
GDAL and PROJ libraries but that would involve a major effort.
18.3 Migration code and packages
The wiki page of the GitHub site for sf, found at
contains a list of methods and functions in
sp and the corresponding
sf method or function. This may help
converting existing code or packages.
A simple approach to migrate code is when only
used to read
file. As an alternative, one might use
however possible arguments to
readOGR, when used, would need more
An effort by us is underway to convert all code of our earlier book
“Applied Spatial Data Analysis with R” (with Virgilio Gomez-Rubio,
Bivand, Pebesma, and Gomez-Rubio (2013)) to run entirely without
where possible without
sp. The scripts are found at
18.4 Package raster and terra
raster has been a workhorse package for analysing raster
data with R since 2010, and has since then grown into a package for
“Geographic Data Analysis and Modeling” (Hijmans 2021a), indicating that
it is used for all kinds of spatial data. The
raster package uses
sp objects for vector data, and
rgdal to read and write data to
formats served by the GDAL library. Its successor package
for “Spatial Data Analysis” (Hijmans 2021b), “is very similar to the
raster package; but […] can do more, is easier to use, and
[…] is faster”. The
terra package comes with its own classes
for vector data, but accepts many
sf objects, with similar
restrictions as listed above for conversion to
has its own direct links to GDAL, GEOS and PROJ so no longer needs
other packages for that.
Raster maps, or stacks of them from package
can be converted to
stars objects using
sf contains an
st_as_sf() method for
terra. Migration from
become more important once
rgdal is no longer easily installable
The online book “Spatial Data Science with R”, written by Robert
Hijmans and found at https://rspatial.org/terra details the
approach to spatial data analysis. Package
several other r-spatial packages discussed in this book reside on the
r-spatial GitHub organisation (note the hyphen between
spatial, which is absent on Hijmans’ organisation), which has a
blog site, with links to this book, found at https://r-spatial.org/ .
stars on one hand and
terra on the other
have many goals in common, but try to reach them in slightly
different ways, emphasizing different aspects of data analysis,
software engineering, and community management. Although this may
confuse some users, we believe that these differences enrich the
R package ecosystem, are beneficial to users, encourage diversity
and choice, and hopefully work as an encouragement for others to
continue trying out new ideas when using R for spatial data problems,
and to help carrying the R spatial flag.
Bivand, Roger S., Edzer Pebesma, and Virgilio Gomez-Rubio. 2013. Applied Spatial Data Analysis with R, Second Edition. Springer, NY. http://www.asdar-book.org/.
Hijmans, Robert J. 2021a. Raster: Geographic Data Analysis and Modeling. https://rspatial.org/raster.
Hijmans, Robert J. 2021b. Terra: Spatial Data Analysis. https://rspatial.org/terra/.