I have a montyly rasters containing 20 years. I want to read only rasters in the year 2017 as a list of files. But I am getting this error Error: [rast] cannot open file: Apr 2017_masked_idw2.asc In addition: Warning message: Apr 2017_masked_idw2.asc: No such file or directory (GDAL error 4)
.
I am using this following code:
> # Read a bunch of rasters (12 months - one year) using terra package
> mypath <- "F:/OneDrive/ThesisDataAnalysis/rasters/IDW"
>
> rastlist <- list.files(path = mypath, pattern="*2017_masked_idw2.asc$",
+ all.files=FALSE , full.names= FALSE)
> rastlist
[1] "Apr 2017_masked_idw2.asc" "Aug 2017_masked_idw2.asc" "Dec 2017_masked_idw2.asc"
[4] "Feb 2017_masked_idw2.asc" "Jan 2017_masked_idw2.asc" "Jul 2017_masked_idw2.asc"
[7] "Jun 2017_masked_idw2.asc" "Mar 2017_masked_idw2.asc" "May 2017_masked_idw2.asc"
[10] "Nov 2017_masked_idw2.asc" "Oct 2017_masked_idw2.asc" "Sep 2017_masked_idw2.asc"
> rasters_2017 <- terra::rast(rastlist)
Error: [rast] cannot open file: Apr 2017_masked_idw2.asc
In addition: Warning message:
Apr 2017_masked_idw2.asc: No such file or directory (GDAL error 4) ```
Any thoughts?