r-spatial / rgee

Google Earth Engine for R
https://r-spatial.github.io/rgee/
Other
677 stars 146 forks source link

map function doesn't recognize first argument of function #306

Closed SvenVw closed 1 year ago

SvenVw commented 1 year ago

At submit an issue, please attached the following information of your rgee session:

library(rgee)

# Initialize the Earth Engine module.
ee_Initialize()

# Print metadata for a DEM dataset.
print(ee$Image('USGS/SRTMGL1_003')$getInfo())

Attach your Python (reticulate) configuration:

library(reticulate)
py_config()
python:         C:/Users/[user]/AppData/Local/r-miniconda/envs/rgee/python.exe
libpython:      C:/Users/[user]/AppData/Local/r-miniconda/envs/rgee/python38.dll
pythonhome:     C:/Users/[user]/AppData/Local/r-miniconda/envs/rgee
version:        3.8.15 | packaged by conda-forge | (default, Nov 22 2022, 08:42:03) [MSC v.1929 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/Users/[user]/AppData/Local/r-miniconda/envs/rgee/Lib/site-packages/numpy
numpy_version:  1.23.5
ee:             C:\Users\[user]\AppData\Local\R-MINI~1\envs\rgee\lib\site-packages\ee\__init__.p

NOTE: Python version was forced by RETICULATE_PYTHON

Description

When using the map function to loop over a EE List, it returns that it can't find the function argument. When trying the same code translated to JavaScript in Code Editor it works.

What I Did

library(rgee)
ee_Initialize()
x <- ee$List$sequence(1,100,1)
y <- x$map(function(z) { return(z + 1)})

It returns this error and traceback:

Error in py_call_impl(callable, dots$args, dots$keywords) :
RuntimeError: Evaluation error: argument "z" is missing, with no default.

3: stop(structure(list(message = "RuntimeError: Evaluation error: argument \"z\" is missing, with no default.\n", 
       call = py_call_impl(callable, dots$args, dots$keywords), 
       cppstack = NULL), class = c("Rcpp::exception", "C++Error", 
   "error", "condition")))
2: py_call_impl(callable, dots$args, dots$keywords)
1: x$map(function(z) {
       return(z + 1)

This translated JavaScript code works in the Code Editor:

var x = ee.List.sequence(1,100,1);
var y = x.map(function(z) {
  return z + 1;
});
print(y);
csaybar commented 1 year ago

Please read rgee documentation. https://r-spatial.github.io/rgee/articles/rgee02.html

library(rgee)

ee_Initialize()

x <- ee$List$sequence(1,100,1)
y <- x$map(
  ee_utils_pyfunc(
    function(z) { return(ee$Number(z)$add(1))}
  )
)
y$getInfo()