Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
I have a script where I read a raster stored as .tif :
f_treecover <- raster('Landcover_data/treecover_res_100_q.tif')
The script used to run fine a few months ago, but now I get the following error message:
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create a RasterLayer object from this file.
I can read the file with the 'rast' function in terra:
f_treecover <- rast('Landcover_data/treecover_res_100_q.tif')
> f_treecover
class : SpatRaster
dimensions : 1400, 3600, 1 (nrow, ncol, nlyr)
resolution : 0.1, 0.1 (x, y)
extent : -180, 180, -60, 80 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs
source : treecover_res_100_q.tif
name : treecover_res_100_q
However, all the other objects in the script are RasterLayers , so I need this object to be one as well. I tried coercing the resulting SpatRaster into a Raster with
raster(f_treecover)
, but that leads to the same error message as when originally trying to read the .tif file.
I probably installed an updated version of the raster package in the meanwhile (now using 3.4-10), could that be causing the issue?
If you do not have the rgdal
package installed, you get
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create RasterLayer object from this file; perhaps you need to install rgdal first
In which case you should install rgdal
Otherwise, make sure you are not loading an old workspace (use unlink(".RData")
, quit R without saving the workspace and start again.
If that does not help: uninstall R and install the latest version and packages again.
–
–
–
–
–
This happened to me after having no issues prior. I realized what happened was my Dropbox account was not synced and so the file was simply not being found. If you store your raster .tif object in your environment and run the code chunk below it should find your file. If not, Dropbox sync (if your file is from Dropbox) may also be your issue:
readr::read_file(tif_file)
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.