'Processing big raster using clusterR

I have a really big raster of LULC in netcdf that I load in R and convert I some values in the raster to NA and save the file

library(raster)
library(snow)

r <- raster("f.nc")
values(r)[values(r) %in% c(0, 190, 200, 210, 220)] <- NA

However, the raster is so big that I ran into memory issue. Using the below blog, I tried to use the clusterR function

https://strimas.com/post/processing-large-rasters-in-r/

func_ <- function(x){ values(x)[values(x) %in% c(0, 190, 200, 210, 220)] <- NA }

beginCluster(n = 4)
parallel_r <- clusterR(r, fun = func_)
endCluster()

Error in clusterR(r, fun = func_) : cluster error

Could anyone help me with it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source