I should note I'm using RStudio. These terms may be specific to RStudio.

I've seen a couple of questions referencing this, but I haven't found any explanation of how they are different. I'm finding calculations are taking a very long time with a formal class rasterlayer but not a large raterlayer, so I want to understand how they are different and how to solve this.

Here is an example raster. It's only about 2mb. When I load this raster, it loads as a formal class rasterlayer. However, if I load this raster and perform any simple mathematical operation to it, it becomes a large rasterlayer. For some reason, though (and this is not happening with this example raster), this takes about 10 seconds to perform any simple calculation with my data.

r1<- raster("./example_raster.tif")
r2<- r1 + 0  #this takes about 10 seconds with my data

Is there any other way to convert from the formal class rasterlayer to a large rasterlayer?

  • Where do you see if something is a Large or not-Large raster layer? What happens if you do this in plain R outside R-studio? What does rasterOptions() print?
    – Spacedman
    Commented Sep 25, 2019 at 18:58
  • R studio defines the layer either as "Formal Class RasterLayer" or "Large RasterLayer". Here are the results of rasterOptions(): format : raster datatype : FLT4S overwrite : FALSE progress : none timer : FALSE chunksize : 1e+08 maxmemory : 1e+09 memfrac : 0.6 tmpdir : C:\Users\Public\Documents\Wondershare\CreatorTemp\Rtmpo9OB3v/raster/ tmptime : 168 setfileext : TRUE tolerance : 0.1 standardnames : TRUE warn depracat.: TRUE header : none
    – Scott Z
    Commented Sep 25, 2019 at 20:36
  • I have the same issues in base R as I have in RStudio. But I've identified another possible reason for this. Until making a calculation (even the nonsense +0 calculation), the data source for the raster is from my disk. After making the calculation, the source is in memory. I'm reading these rasters from netCDF files, which are then stacked, the subset to get to individual rasters, so I imagine this is a convoluted path. Do you think that would make a difference? Is there another way to load the rasters into memory rather than off my disk?
    – Scott Z
    Commented Sep 25, 2019 at 20:41


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.