Install r-gee

First, you have to install the packages rgee, this packages have to be downloaded from the github repository, so we have to use the function install-github from the remotes packages (this packages is loaded automatically by Rstudio).

remotes::install_github("r-spatial/rgee")
## Skipping install of 'rgee' from a github remote, the SHA1 (784d8a84) has not changed since last install.
##   Use `force = TRUE` to force installation

Next, you have to make the conection to a Python environment with Earth Engine API.

If you have a python environment with GEE you can go to Tools -> Global Options -> Python and specify the path to the Python interpreter with GEE, else, you can create a Python environment for R calling the rgee pacakge and using the function ee_install with the argument py_env equals to the name for the environment and follow the instructions.

Warning: Maybe you have to install Google Cloud SDK to run the Earth Engine API.

library(rgee)

ee_install(py_env = 'rgee_env')
## ──────────────────────────────── Python configuration used to create rgee_env ──
## python:         C:/Users/sedz/Miniconda3/envs/gis/python.exe
## libpython:      C:/Users/sedz/Miniconda3/envs/gis/python37.dll
## pythonhome:     C:/Users/sedz/Miniconda3/envs/gis
## version:        3.7.13 (default, Mar 28 2022, 08:03:21) [MSC v.1916 64 bit (AMD64)]
## Architecture:   64bit
## numpy:          C:/Users/sedz/Miniconda3/envs/gis/Lib/site-packages/numpy
## numpy_version:  1.21.5
## ee:             C:\Users\sedz\MINICO~1\envs\gis\lib\site-packages\ee\__init__.p
## 
## NOTE: Python version was forced by RETICULATE_PYTHON
## ────────────────────────────────────────────────────────────────────────────────
## 1. Removing the previous Python Environment (rgee_env), if it exists ...
## + "C:/Users/sedz/Miniconda3/condabin/conda.bat" "remove" "--yes" "--name" "rgee_env" "--all"
## 
## 2. Creating a Python Environment (rgee_env)
## + "C:/Users/sedz/Miniconda3/condabin/conda.bat" "create" "--yes" "--name" "rgee_env" "python=3.8" "--quiet" "-c" "conda-forge"
## 
## rgee::ee_install want to store the environment variables: EARTHENGINE_PYTHON 
## and EARTHENGINE_ENV in your .Renviron file to use the Python path:
## C:\Users\sedz\Miniconda3\envs\rgee_env/python.exe in future sessions.
## rgee needs to restart the R session to see changes.
## 
## 3. The Environment Variables: 'EARTHENGINE_PYTHON=C:\Users\sedz\Miniconda3\envs\rgee_env/python.exe' and 'EARTHENGINE_ENV=rgee_env'
## were saved in the .Renviron (C:/Users/sedz/OneDrive/Documentos/.Renviron) file. Remember that you
## could remove EARTHENGINE_PYTHON and EARTHENGINE_ENV using rgee::ee_clean_pyenv().
## 
## 4. Installing the earthengine-api. Running:
## reticulate::py_install(packages = 'earthengine-api', envname = 'C:/Users/sedz/Miniconda3/envs/rgee_env')
## + "C:/Users/sedz/Miniconda3/condabin/conda.bat" "install" "--yes" "--prefix" "C:/Users/sedz/Miniconda3/envs/rgee_env" "-c" "conda-forge" "earthengine-api" "numpy"
## rgee needs to restart the R session to see changes.

Finally you have to authenticate Earth Engine with your Google account (You have to sign up for this) using the function ee_Initialize():

library(rgee)

ee_Initialize()
## ── rgee 1.1.4 ─────────────────────────────────────── earthengine-api 0.1.316 ──
## Warning in ee_Initialize(): Update your earthnengine-api installations to
## v0.1.317 or greater. Earlier versions are not compatible with recent changes to
## the Earth Engine backend.
##  ✔ user: not_defined
##  ✔ Initializing Google Earth Engine:
 ✔ Initializing Google Earth Engine:  DONE!
## 
 ✔ Earth Engine account: users/plume 
## ────────────────────────────────────────────────────────────────────────────────

The authentication process only has to be done once, but the initialize process has to be done for all every time.