1

When I used writeRaster() in R, I got the error like this: Error in .startGDALwriting(x, filename, gdal = options, ...): 'file' slot name does not exist in the object of the 'RasterStack' class.

Does anyone know how to deal with it?

  • check this https://stackoverflow.com/a/69384275/2418532 – Sergio Apr 03 '23 at 03:13
  • @Sergio, thank you for your reply. I tried raster(stack) to convert the stack to a raster first, but it showed the converted raster had no value. I used brick(stack) instead and used writeRaster() after, and it works! – Yiqian Zeng Apr 03 '23 at 07:14

1 Answers1

0

I had a similar issue.

I created a raster stack with the raster package

raster_stack <- stack(DEM,SLP,TWI,AHS,LSF,CNBL,RSP)

But it was not able to write the raster stack in my file:

writeRaster(raster_stack, "Cov_Stack.tif", format="GTiff", overwrite = TRUE)

Error in .startGDALwriting(x, filename, gdal = options, ...) :
formal argument "sources" matched by multiple actual arguments

So I used the terra package.

test <- rast(raster_stack)
terra::writeRaster(Test, "Cov_Stack.tif")

It's simple but I hope it helps you.