Reputation: 449
I would like to perform an analysis on images located in a specific folder. I use:
library(raster)
folder <- "C:/Users/Mezeix/Pictures/FreeVideoToJPGConverter/1 images/"
img <- list.files(folder)
img.raster<-stack(img)
I started with only 1 image to check. As observed the image is well stored into "img "
But when I use the function stack(img) I have the following message:
Error in .local(.Object, ...) :
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create a RasterLayer object from this file. (file does not exist)
I do not understand why.
Upvotes: 0
Views: 628
Reputation: 47146
It will work if you use
img <- list.files(folder, full.names=TRUE)
Upvotes: 2
Reputation: 1076
x
argument of stack
function takes the full path of the file, if file[img] is not present in current working directory.
combine the directory and file name as below to make it work.
img_path <- paste0(folder, img)
img.raster<-stack(x = img_path)
Upvotes: 2