R Works with Google Earth Engine - Installation 【rgee】
Date : 2022/04/24
Intallation Tutorial - Reference : Introduction to rgee (r-project.org)
Prerequisites :
1. A registered GEE acoount
2. A unrestricted-access VPN for google
3. A python package-management software , such as Anaconda
3. R and Rstudio
Process :
1. Install the 'rgee' package
2. Set up the dependent environment
3. Initialization
Step 1 : Install the 'rgee' package
First, start you Rtudio and create a new R file. Before your installation , set up your python interpreter in Rstudio.
! If you met with the following problem , try what the above picture shows.
> library(rgee)
Error: package or namespace load failed for ‘rgee’:
loadNamespace() 'rgee' .onLoad failed:
code: py_module_import(module, convert = convert)
error: ModuleNotFoundError: No module named 'ee'
Then install the 'rgee' package. Here is where you can install ,check and update the R packages.
Step 2 : Set up the dependent environment
Now, we load the package, set up the python environment.
library(rgee)
#set up the python environment, do follow the prompt, enter [y] to restart R session.
# ! Only need set up one time, if set up successfully, you don't have to write this line code again.
ee_install()# if this doesn't work , try the next line code
ee_install(py_env = "rgee") # if this doesn't work , try the next line code
ee_install_set_pyenv(py_env = "rgee")
After that , we need check out if all done.
ee_check()
Return Success Symbol :
(*) Python version
√ [Ok] D:/Anaconda3/envs/rgee/python.exe v3.8
(*) Python packages:
√ [Ok] numpy
√ [Ok] earthengine-api
! If don't , maybe the rgee and earthengine-api version doesn't match, just update your rgee package in Rstudio.
Step 3 : Initialization
Here is the Big Big Problem .
ee_Initialize() # You need to do it every time after loading the 'rgee' library.
Normally, you may encounter the following two problems:
√ email: not_defined
√ Initializing Google Earth Engine:
Error in py_call_impl(callable, dots$args, dots$keywords) :
1. TimeoutError: timed out [WinError 10060]
2. URLError: <urlopen error [WinError 10060]
I googled some solutions, but they didn't work, perhaps these attempts will solve your problems
## Solution 1 : clean up the environment then initialize
ee_clean_pyenv()
ee_Initialize()
## Solution 2 : Set the proxy then initialize
Sys.setenv(http_proxy='http://127.0.0.1:7890')
Sys.setenv(https_proxy='http://127.0.0.1:7890')
ee_Initialize()
Finally , I figured out the solution. It was unwise that I did not set system proxy , I just set up the browser proxy.
So, please make sure system proxy set up, then the initialization will succeess.
Step 4 : Enjoy working R with GEE
[ ^_^ ] If you have any problems , please comment on the box below.