Dear community Dear Ivan Thanks a lot. The code works now. Solution: direct and full path to the .tif files. I confused back and forward slash
#first import all files in a single folder as a list rastlist <- list.files(path = "C:/Users/Sibylle Stöckli/Desktop/NCCS_Impacts_Lot2_2022/InVEST/Species_Input/valpar_bee_presence", pattern='.tif$', all.files= T, full.names= T) At the end I got a warning #to run a function on an individual raster e.g., plot > boxplot(allrasters[[1]]) > > p<-boxplot(allrasters[[1]]) Warning message: In .local(x, ...) : taking a sample of 1e+05 cells > Not all of the characters in C:/Users/Sibylle Stöckli/Desktop/Test_Rasterfile.R could be encoded using ASCII. To save using a different encoding, choose "File | Save with Encoding..." from the main menu. > Kind regards Sibylle -----Original Message----- From: R-help <r-help-boun...@r-project.org> On Behalf Of SIBYLLE STÖCKLI via R-help Sent: Thursday, April 18, 2024 6:48 PM To: 'Ivan Krylov' <ikry...@disroot.org>; 'SIBYLLE STÖCKLI via R-help' <r-help@r-project.org> Subject: Re: [R] Import multiple tif raster Dear Ivan Thanks a lot. I tried now to provide the full path. However probably the "ö" in the path produces the error, would that be possible? > #first import all files in a single folder as a list rastlist <- > list.files(path = "C:\Users\Sibylle > Stöckli\Desktop\NCCS_Impacts_Lot2_2022\InVEST\Species_Input\valpar_bee > _presence", pattern='.tif$', all.files= T, full.names= T) Error: '\U' used without hex digits in character string (<input>:1:35) Kind regards Sibylle -----Original Message----- From: Ivan Krylov <ikry...@disroot.org> Sent: Thursday, April 18, 2024 2:39 PM To: SIBYLLE STÖCKLI via R-help <r-help@r-project.org> Cc: sibylle.stoec...@gmx.ch Subject: Re: [R] Import multiple tif raster В Thu, 18 Apr 2024 11:08:33 +0200 SIBYLLE STÖCKLI via R-help <r-help@r-project.org> пишет: > > #to check the index numbers of all imported raster list elements > > allrasters > list() > > > > #call single raster element > > allrasters[[1]] > Error in allrasters[[1]] : subscript out of bounds `allrasters` is an empty list, so it doesn't have a first item. Therefore, allrasters[[1]] is an error. Why is this so? Probably because list.files(...) above returned an empty vector. Check rastlist and/or length(rastlist). Make sure that the path you're giving to list.files (the one starting with /NCCS_Impacts_Lot2_2022/InVEST/...) exists on your computer. Did you mean to start it with a slash, making it an absolute path starting from the root of the filesystem? -- Best regards, Ivan ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.