[R-sig-Geo] cluster error with clusterR and calc

Robert J. Hijmans r.hijmans at gmail.com
Wed Nov 20 19:48:40 CET 2013


The manual is wrong. It should say that clusterR also works with
overlay if you use a single RasterStack or RasterBrick object as the
first argument (it would not work if you provided three RasterLayer
objects)

Yes, you can use clusterExport, by first calling getCluster() to get
the cluster object.

library(raster)
x <- raster()
y = setValues(x, runif(ncell(x)))
z = setValues(x, runif(ncell(x)))
x = setValues(x, runif(ncell(x)))
f= 'test.tif'
s <- stack(x, y, z)

ENV.LAPSERATE = 6
fun1 <- function(x) calc(x, fun = function(d){ 10 * (d[,2] - d[,3]) /
ENV.LAPSERATE + d[,1] })
fun2 <- function(x) overlay(x, fun = function(d,e,f){ 10 * (e - f) /
ENV.LAPSERATE + d })

beginCluster(4)
cl <- getCluster()
clusterExport(cl, "ENV.LAPSERATE")
h1 <- clusterR(s, fun1)
h2 <- clusterR(s, fun2)
h3 <- clusterR(s, overlay, args=list(fun = function(d,e,f){ 10 * (e -
f) / ENV.LAPSERATE + d }))
endCluster()

On Wed, Nov 20, 2013 at 9:49 AM, Guillaume Drolet
<droletguillaume at gmail.com> wrote:
> Hi Robert,
>
> Thanks for your help. I thought that overlay didn't work with clusterR (see
> ?clusterR: ... For example, it works with calc but not with overlay.)
>
> Is there any way to export variables to the clusters when using clusterR,
> similar to when using clusterExport() with snow, or if it HAS to be hard
> coded?
>
> Best wishes,
>
> Guillaume
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/cluster-error-with-clusterR-and-calc-tp7585148p7585153.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list