1

I am downloading tree cover spatial data using the 'dataverse' package and attempting to save it as a RasterStack. The download is fine, however when I use writeRaster to save it, I get the following error message: "Error in .local(.Object, ...) :"

I set it up as a function to ideally download and save each year. I've reviewed many forums, but none of the fixes applied have worked. I've been able to save other, test RasterStacks with the writeRaster function, but not mine. Any idea what the issue is?

library(dataverse)
library(raster)


setwd("C:/Users/Kate/Documents/ScottRiver/ShastaScottStateOfBasin/Data/Dataverse/")

downloaddataverse <- function(year){

thedf <- 
  get_dataframe_by_name(
    filename = paste0("ARD_h02v06_C2_",year,"_vegCover.tif"),
    dataset = "10.7910/DVN/KMBYYM",
    server = "dataverse.harvard.edu",
    .f = raster,
    original=T)

}

df1990 <- stack(downloaddataverse(1990))

writeRaster(df1990,"df1990.tif",overwrite=T)
Kate
  • 51
  • 1
  • 3
  • I set my working directory as the file location to avoid file path issues. There are many issues with this function, but it seems like there are different reasons behind the issues. – Kate Jul 27 '22 at 18:15
  • Maybe about memory limits? https://stackoverflow.com/a/61468198/8400969 – Michael Roswell Jul 27 '22 at 18:57
  • Not a memory issue, I just set the working directory to my 5 TB external hard drive and had the same error. – Kate Jul 27 '22 at 19:50
  • Hi Kate, I am really not an expert on this, but I am not sure that simply changing the working directory would resolve the memory issue, because of how `raster` uses temp files (on some kind of drive) and memory (RAM) together... I know that in an example I had on my machine in RStudio, a large raster stack was classed as a `Large RasterStack` rather than `Formal Class RasterStack`; I don't know where the raster stack data actually are (memory, temp files, etc.) while R is thinking about them. – Michael Roswell Jul 27 '22 at 20:00
  • what does `raster::tmpDir()` return? – Michael Roswell Jul 27 '22 at 20:02

0 Answers0