[R-sig-Geo] Error in basename(x) : path too long
Ben Tupper
btupper at bigelow.org
Sat Jul 29 14:30:48 CEST 2017
Hi,
It's not possible to know but I have a suspicion and a suggestion.
suspicion: You are accessing the elements of the data frame "newlist" different ways ...
> refr <- raster(paste("I:/Mauritius2001_2015/",newlist[i,1],sep = ""))
and
> r <- raster(paste("I:/Mauritius2001_2015/",newlist[i+p],sep = ""))
and
> filename=paste("D:/Mauritius2001_2015/Annual/",substr(newlist[i],1,6),".tif",sep='')
The first likely works. The latter two return the (i+p)'th and i'th columns each as a new data frame so the filenames may indeed be quite long. So, it looks like you need to work on your data frame indexing.
suggestion: Instead of using paste() to make file paths I suggest that you give file.path() a try. It works across all platforms and is easier than using paste.
CHeers,
Ben
> On Jul 29, 2017, at 7:56 AM, John Wasige <johnwasige at gmail.com> wrote:
>
> Dear all,
>
> I am running the script below & I get the following error:
> Error in basename(x) : path too long
>
> What could be the problem?
> Thanks for your help
> John
>
> ### Script
>
> setwd("I:/Mauritius2001_2015") # directory of data
> newlist= read.csv('I:/Mauritius2001_2015/Mauritius.csv',header=F)
>
> refr <- raster(paste("I:/Mauritius2001_2015/",newlist[i,1],sep = ""))
> refr[!is.na(refr)] <- 0
> for(i in seq(1,345,by=23)){
> rsum <- refr
> for(p in 0:22){
> r <- raster(paste("I:/Mauritius2001_2015/",newlist[i+p],sep = ""))
> rsum <- rsum + r
> }
> # rsum <- rsum
> writeRaster(rsum,
> filename=paste("D:/Mauritius2001_2015/Annual/",substr(newlist[i],1,6),".tif",sep=''),
> format="GTiff", overwrite=TRUE)
> }
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org
Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/
More information about the R-sig-Geo
mailing list