Reputation: 1255
The following JS equivalent code is working in the gee playground, but not in rgee.
This should calculate the sum of 1:5.
lst <- ee$List$sequence(1,5,1)
runsum = lst$iterate(function(item,sum) {
item = ee$Number(item)
sum = ee$Number(sum)
return(sum$add(item))
},0)
The error I receive is:
Error in py_call_impl(callable, dots$args, dots$keywords) :
RuntimeError: Evaluation error: argument "item" is missing, with no default.
What is the right syntax for rgee?
Upvotes: 0
Views: 70
Reputation: 1255
I figured out the answer and am posting it in case it might be helpful to someone in the future. If you want to use functions within map() or iterate(), you need to use the helper function ee_utils_pyfunc
.
https://r-spatial.github.io/rgee/articles/rgee02.html
lst <- ee$List$sequence(1,5,1)
runsum = lst$iterate(
ee_utils_pyfunc(function(item,sum) {
item = ee$Number(item)
sum = ee$Number(sum)
return(sum$add(item))
}),0)
print(runsum$getInfo())
Upvotes: 0