I'm a bit confused about types here. While I'm loading a image:
tif = raster(paste0(path))
I get some "Formal Class RasterLayer" object. But while I change it's matrix of values, for example:
idx <- values(tif) != 200
values(tif)[idx] <- 255
if becomes "Large RasterLayer" object. And indeed it's large, for file of about 100Mpx it's over 270mb, while that first is about 10mb in memory.
How can I convert this new one into the "Formal" class to save memory?
I tried: tif1 = raster(tif)
but object missing coordinates. as.raster(tif)
returns raster chr variable.
EDIT
Found a workaround:
writeRaster(tif, "tif.tif")
tif = raster("tif.tif")
It takes much memory for process but at last its freed. Wish to find something faster without saving to disk.
object.size(tif)
.