Simple Features for R
See the codeA package that provides simple features access for R.
Blogs, links • Cheatsheet • Installing • Contributing • Acknowledgment • How to cite
Package sf:
data.frame or tibble with a geometry list-columnDate and POSIXct and list-columns(Illustration (c) 2018 by Allison Horst)
Install either from CRAN with:
install.packages("sf")
This will install binary packages on Windows and MacOS, unless you configured R such that it tries to install source packages; in that case, see below.
Install development versions from GitHub with:
library(remotes)
install_github("r-spatial/sf")
Installing sf from source works under Windows when Rtools is installed.
MacOS users are strongly encouraged to install the sf binary packages from CRAN, unless they are familiar with compilers, linking, C++ source code, and homebrew. If you experience that R tries to install sf from source (or otherwise your install fails but you don't understand what is going on) try again by explicitly installing the binary, using
install.packages("sf", type = "binary")
The remainder of this section is for those who understand what source installs mean, and imply.
Perhaps the easiest way of an install from source is to first install gdal using Homebrew. Recent versions of Homebrew include a full-featured up-to-date gdal formula, which installs proj and gdal at the same time:
brew install pkg-config
brew install gdal
Once gdal is installed, you may be able to install sf package from source in R. With the current version of proj on homebrew, installation requires additional configuration:
install.packages("sf", type = "source", configure.args = "--with-proj-lib=$(brew --prefix)/lib/")
Or the development version:
library(remotes)
install_github("r-spatial/sf", configure.args = "--with-proj-lib=$(brew --prefix)/lib/")
Alternatively, these instructions explain how to install gdal using kyngchaos frameworks.
For Mac OS 11 Big Sur source install instruction, see here
For Unix-alikes, GDAL (>= 2.0.1), GEOS (>= 3.4.0) and PROJ (>= 4.8.0) are required.
Dependencies for recent versions of Ubuntu (18.04 and later) are available in the official repositories; you can install them with:
sudo apt -y update && apt install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev libsqlite3-dev
However, to get more up-to-date versions of dependencies such as GDAL, GEOS and PROJ we recommend adding the ubuntugis-unstable PPA to the package repositories and installing them as follows:
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt install libudunits2-dev libgdal-dev libgeos-dev libproj-dev libsqlite3-dev
Adding this PPA is required for installing sf on older versions of Ubuntu (e.g. Xenial).
Another option, for advanced users, is to install dependencies from source; see e.g. an older Travis config file for hints.
The following command installs all required dependencies:
sudo dnf install gdal-devel proj-devel geos-devel sqlite-devel udunits2-devel
Get gdal, proj, geos and podofo from the main repos, and udunits from the AUR:
pacman -S gdal proj geos arrow podofo
yay/pacaur/yaourt/whatever -S udunits
renv or condaThere are several reports that sf fails to install as a source package when R is used with renv, or when R is installed in a conda environment. If you experience this, please only raise an issue here if the problem persists without renv or conda, and otherwise
renv developers or the conda maintainers, orsf package, e.g. from r2u, or the Posit package managerTo install on Debian, the rocker geospatial Dockerfiles may be helpful. Ubuntu Dockerfiles are found here.
sf links to GDAL, but does not control how GDAL was configured and built. Not every GDAL installation has built-in support for GeoParquet or Arrow. Please see this issue, or configure and compile GDAL with Parquet support e.g. using this Dockerfile.
If you use dynamic linking (installation from source) and have multiple versions of these libraries installed (e.g. one from ubuntugis-unstable, another installed from source in /usr/local/lib) then this will in general not work, even when setting LD_LIBRARY_PATH manually. See here for the reason why.
Functions and methods that require liblwgeom, including ellipsoidal (not spherical or Euclidean) metrics (area, distances), are provided by and used from lwgeom, which is also on CRAN.
= rather than <-; don't change indentation; tab stops of 4 spaces are preferred).Package sf can be cited as:
Edzer Pebesma, 2018. Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal 10:1, 439-446.
Pebesma, E.; Bivand, R. (2023). Spatial Data Science: With Applications in R (1st ed.). 314 pages. Chapman and Hall/CRC.
This project gratefully acknowledges financial support from the
(top 30 of 116)
R
64.7%
C++
29.5%
Dockerfile
3.7%
M4
1.7%
Simple Features for R
See the codeA package that provides simple features access for R.
Blogs, links • Cheatsheet • Installing • Contributing • Acknowledgment • How to cite
Package sf:
data.frame or tibble with a geometry list-columnDate and POSIXct and list-columns(Illustration (c) 2018 by Allison Horst)
Install either from CRAN with:
install.packages("sf")
This will install binary packages on Windows and MacOS, unless you configured R such that it tries to install source packages; in that case, see below.
Install development versions from GitHub with:
library(remotes)
install_github("r-spatial/sf")
Installing sf from source works under Windows when Rtools is installed.
MacOS users are strongly encouraged to install the sf binary packages from CRAN, unless they are familiar with compilers, linking, C++ source code, and homebrew. If you experience that R tries to install sf from source (or otherwise your install fails but you don't understand what is going on) try again by explicitly installing the binary, using
install.packages("sf", type = "binary")
The remainder of this section is for those who understand what source installs mean, and imply.
Perhaps the easiest way of an install from source is to first install gdal using Homebrew. Recent versions of Homebrew include a full-featured up-to-date gdal formula, which installs proj and gdal at the same time:
brew install pkg-config
brew install gdal
Once gdal is installed, you may be able to install sf package from source in R. With the current version of proj on homebrew, installation requires additional configuration:
install.packages("sf", type = "source", configure.args = "--with-proj-lib=$(brew --prefix)/lib/")
Or the development version:
library(remotes)
install_github("r-spatial/sf", configure.args = "--with-proj-lib=$(brew --prefix)/lib/")
Alternatively, these instructions explain how to install gdal using kyngchaos frameworks.
For Mac OS 11 Big Sur source install instruction, see here
For Unix-alikes, GDAL (>= 2.0.1), GEOS (>= 3.4.0) and PROJ (>= 4.8.0) are required.
Dependencies for recent versions of Ubuntu (18.04 and later) are available in the official repositories; you can install them with:
sudo apt -y update && apt install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev libsqlite3-dev
However, to get more up-to-date versions of dependencies such as GDAL, GEOS and PROJ we recommend adding the ubuntugis-unstable PPA to the package repositories and installing them as follows:
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt install libudunits2-dev libgdal-dev libgeos-dev libproj-dev libsqlite3-dev
Adding this PPA is required for installing sf on older versions of Ubuntu (e.g. Xenial).
Another option, for advanced users, is to install dependencies from source; see e.g. an older Travis config file for hints.
The following command installs all required dependencies:
sudo dnf install gdal-devel proj-devel geos-devel sqlite-devel udunits2-devel
Get gdal, proj, geos and podofo from the main repos, and udunits from the AUR:
pacman -S gdal proj geos arrow podofo
yay/pacaur/yaourt/whatever -S udunits
renv or condaThere are several reports that sf fails to install as a source package when R is used with renv, or when R is installed in a conda environment. If you experience this, please only raise an issue here if the problem persists without renv or conda, and otherwise
renv developers or the conda maintainers, orsf package, e.g. from r2u, or the Posit package managerTo install on Debian, the rocker geospatial Dockerfiles may be helpful. Ubuntu Dockerfiles are found here.
sf links to GDAL, but does not control how GDAL was configured and built. Not every GDAL installation has built-in support for GeoParquet or Arrow. Please see this issue, or configure and compile GDAL with Parquet support e.g. using this Dockerfile.
If you use dynamic linking (installation from source) and have multiple versions of these libraries installed (e.g. one from ubuntugis-unstable, another installed from source in /usr/local/lib) then this will in general not work, even when setting LD_LIBRARY_PATH manually. See here for the reason why.
Functions and methods that require liblwgeom, including ellipsoidal (not spherical or Euclidean) metrics (area, distances), are provided by and used from lwgeom, which is also on CRAN.
= rather than <-; don't change indentation; tab stops of 4 spaces are preferred).Package sf can be cited as:
Edzer Pebesma, 2018. Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal 10:1, 439-446.
Pebesma, E.; Bivand, R. (2023). Spatial Data Science: With Applications in R (1st ed.). 314 pages. Chapman and Hall/CRC.
This project gratefully acknowledges financial support from the
(top 30 of 116)
R
64.7%
C++
29.5%
Dockerfile
3.7%
M4
1.7%