rgee installation: Step by step for different Operating Systems

In this section, you’re going to learn to how to install rgee step by step for different Operating Systems. Remember it’s necessary to have previously installed R, Rtools, and Rstudio in your desktop.


Information:

  • Rtools is only necessary for Windows OS users. You can download Rtools here 📥.


🔴 1. Installation on a Linux distribution

For a distribution like Ubuntu and its derivatives, you must have set up and installed some dependencies of spatial libs in your Operative System. The following bash commands should install key geographic R packages on Ubuntu 20.10.

# install system dependencies:
sudo apt install libudunits2-dev libgdal-dev libgeos-dev libproj-dev libfontconfig1-dev libjq-dev libprotobuf-dev protobuf-compiler

# binary versions of key R packages:
sudo apt install r-cran-rgee r-cran-geojsonio

For a distribution like Manajaro, Archilinux or derivatives, the installation uses the following bash commands

# install system dependencies:
sudo pacman -S gcc-fortan gdal proj geos
git clone https://aur.acrhlinux.org/udunits.git
cd udunits
makepkg -si
# Starting with R
R
# Installation of rgee and geojsonio:
install.packages("rgee")
install.packages("geojsonio")

rgee set up and registration of credentials

rgee depends on the Python packages numpy and ee for its installation. There are two methods for this, and we will explain the most recommended way for new users without experience handling the Python virtual environment.

For the installation of rgee dependencies, use the following function (this function can only be used once):

rgee::ee_install()

After the installation of the rgee dependencies, you need to have a registered account on Google Earth Engine.


Observation:

  • To register on Google Earth Engine, you only need a gmail account and to answer a few short questions.

Finally, with your verified gmail account, you can authenticate and initialize the Earth Engine R API.


🔴 2. Installation on Windows

On windows, the rgee installation is accessible, but you need to have miniconda or anaconda previously installed. To use the rgee package, you must have python3 installed. For a perfect installation on Windows, activate the reticulate library in your R session, and then activate rgee.

# Installation of rgee and geojsonio:
install.packages("rgee")
install.packages("geojsonio")
# Activation of packages:
library(rgee)
library(reticulate)

The py_discover_config() function of the reticulate package will allow you to know which version of python will be used for the installation of numpy and ee libraries.

> py_discover_config()
python:         C:/Users/Windows 10/anaconda3/python.exe
libpython:      C:/Users/Windows 10/anaconda3/python39.dll
pythonhome:     C:/Users/Windows 10/anaconda3
version:        3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/Users/Windows 10/anaconda3/Lib/site-packages/numpy
numpy_version:  1.20.3
Information:
- The function py_config() we allow list all version of python discovered in our System.

After identifying the python version, the next step is to set the path for the new Python environment for rgee, for this you can use the following function use_python(“PUT-HERE-THE-PYTHON3-VERSION-PATH”)

use_python("C:/Users/Windows 10/anaconda3/python.exe")

You can verify the selection of python to work with rgee.

> py_config()
python:         C:/Users/Windows 10/anaconda3/python.exe
libpython:      C:/Users/Windows 10/anaconda3/python39.dll
pythonhome:     C:/Users/Windows 10/anaconda3
version:        3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/Users/Windows 10/anaconda3/Lib/site-packages/numpy
numpy_version:  1.20.3
ee:             [NOT FOUND]
NOTE: Python version was forced by the use_python function

Finally, we set up our rgee environment, install the necessary python dependencies.


Then initialize Google Earth Engine from R and save your credentials.

ee_Initialize(user = "GMAIL_ACCOUNT",drive = TRUE)


🔴 3. Installation on Mac OS

Installation on Mac OS is very similar to a GNU/Linux distribution. In the following code section, you’ll find the codes and some screenshots of some key points to consider.


Information:

  • For Mac OS it is recommended to work with the development version of rgee.
library(remotes)
install_github("r-spatial/rgee")

# Installation of rgee and geojsonio:
install.packages("sf")
install.packages("geojsonio")
# Installation of Python dependence libraries:
rgee::ee_install()


Initialize Google Earth Engine from R and save your credentials.

ee_Initialize(user = "GMAIL_ACCOUNT",drive = TRUE)


🔴 4. Additional packages

pkgs <- c("tmap","mapview","ggspatial","viridis","raster","sf",
          "stars","geojsonio","tidyverse","patchwork","lubridate")
install.packages(pkgs)