0
votes

I am trying to import about 50 .tif files into a stack using the rasters package. Because of the large number of files I don't want to list them all out. I have tried a few methods but have been unsuccessful, including this code:

test<-stack(choose.files(),values=T) Error in .local(x, ...) : Arguments should be Raster* objects or filenames

In addition I want to classify a new raster based on the 50 I import. For example I have a group of polygons with the same extent (could convert to raster) and want to count the number of times a value "1" occurs in each polygon. I figure the "overlay" function would be best for this but am having trouble thinking of how to code the associated function. Any help would be appreciated.

1
it matters not that it's 50, do a test with just two, list them all out, test that they really are files that can be seen with file.exists() - my bet is your file paths are not right, or the files are raster-readable, demonstrate to yourself that it works with 1 by raster(x) - mdsumner

1 Answers

1
votes

The easier way with many files should be to use (with some modifications)

f <- list.files(path='???', pattern='.tif$', full.names=TRUE)
s <- stack(f)

But if you want to do it interactively:

f <- choose.files()
s <- stack(f)

The error occurred because you use "values=TRUE" (which is not an argument to stack and gets interpreted as a file name)