gcs_upload - object raster - S4 objects not supported by gcs_upload
Opened this issue · 4 comments
Usecase:
I am trying to save a raster object as a .tif file in gcs, with these lines of code:
f <- function(input, output){
raster::writeRaster(input, filename = output, format="GTiff", overwrite=TRUE)
}
gcs_upload(ndvi, name = "raster.tif", object_function = f, predefinedAcl = "bucketLevel")
Error:
Warning message in class(file) <- c("gcs_cf", class(file)):
“Setting class(x) to multiple strings ("gcs_cf", "RasterBrick", ...); result will no longer be an S4 object”.
Hmm the issue here is that I assume the nvdi
object is S3 compatible, whereas the raster object is S4. A workaround is to write the object to a file yourself and pass in the file name. A longer term solution is to handle S4 objects in the function.
Thanks for your answer. Could you please specify what you mean when you comment on the function to handle S4 objects.
The lines of code that I have commented have guided me from this issues:
I have a loop that generates RasterLayer objects and I need to save them as "GTiff" format in a bucket
If your loop writes to a temporary local file, uploads that filepath via gcs_upload()
then deletes the temporary local file it should work.
Great thank so much. Your suggestion works.