Installation of rgee
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.
1# install system dependencies:
2sudo apt install libudunits2-dev libgdal-dev libgeos-dev libproj-dev libfontconfig1-dev libjq-dev libprotobuf-dev protobuf-compiler
3
4# binary versions of key R packages:
5sudo apt install r-cran-rgee r-cran-geojsonio
For a distribution like Manajaro, Archilinux or derivatives, the installation uses the following bash commands
1# install system dependencies:
2sudo pacman -S gcc-fortan gdal proj geos
3git clone https://aur.acrhlinux.org/udunits.git
4cd udunits
5makepkg -si
1# Starting with R
2R
3# Installation of rgee and geojsonio:
4install.packages("rgee")
5install.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):
1rgee::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.
1# Installation of rgee and geojsonio:
2install.packages("rgee")
3install.packages("geojsonio")
1# Activation of packages:
2library(rgee)
3library(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.
1> py_discover_config()
2python: C:/Users/Windows 10/anaconda3/python.exe
3libpython: C:/Users/Windows 10/anaconda3/python39.dll
4pythonhome: C:/Users/Windows 10/anaconda3
5version: 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
6Architecture: 64bit
7numpy: C:/Users/Windows 10/anaconda3/Lib/site-packages/numpy
8numpy_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")
1use_python("C:/Users/Windows 10/anaconda3/python.exe")
You can verify the selection of python to work with rgee.
1> py_config()
2python: C:/Users/Windows 10/anaconda3/python.exe
3libpython: C:/Users/Windows 10/anaconda3/python39.dll
4pythonhome: C:/Users/Windows 10/anaconda3
5version: 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
6Architecture: 64bit
7numpy: C:/Users/Windows 10/anaconda3/Lib/site-packages/numpy
8numpy_version: 1.20.3
9ee: [NOT FOUND]
10NOTE: Python version was forced by 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.
1ee_Initialize("GMAIL_ACCOUNT",drive = TRUE)
🔴 3. Instalacion 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.
1library(remotes)
2install_github("r-spatial/rgee")
1# Installation of rgee and geojsonio:
2install.packages("sf")
3install.packages("geojsonio")
1# Installation of Python dependence libraries:
2rgee::ee_install()
Initialize Google Earth Engine from R and save your credentials.
1ee_Initialize("GMAIL_ACCOUNT",drive = TRUE)
🔴 4. Additional packages
1pkgs <- c("tmap","mapview","ggspatial","viridis","raster","sf",
2 "stars","geojsonio","tidyverse","patchwork","lubridate")
3install.packages(pkgs)
-
mapview: https://github.com/r-spatial/mapview
-
ggspatial: https://github.com/paleolimbot/ggspatial
-
geojsonio: https://github.com/ropensci/geojsonio
-
tidyverse: https://github.com/tidyverse/tidyverse
-
patchwork: https://github.com/thomasp85/patchwork
-
lubridate: https://github.com/tidyverse/lubridate