4

I used these functions several times, and they were working perfect, nothing wrong with my input data!!

m<-raster::intersect(raster,shapefile)

or

n<-crop(raster, extent(shapefile))

I have to do this operation for a large set of data. Therefore, I tried to increase the speed of R by using multicore. I did use multicore.tabulate.intersect function from here

However, nothing works for me. Then, whenever I run intersect or crop function I got this error:

m<-raster::intersect(raster,shapefile)

Error in file(fn, "rb") : cannot open the connection
In addition: Warning message:
In file(fn, "rb") :
  cannot open file '/private/var/folders/57/dn1sv79j3zzgy01h2l9v89v80000gn/T/Rtmpg5AYsm/raster/r_tmp_2018-01-23_235923_1432_19427.gri': No such file or directory

> n<-crop(raster, extent(shapefile))

Error in file(fn, "rb") : cannot open the connection
In addition: Warning message:
In file(fn, "rb") :
  cannot open file '/private/var/folders/57/dn1sv79j3zzgy01h2l9v89v80000gn/T/Rtmpg5AYsm/raster/r_tmp_2018-01-23_235923_1432_19427.gri': No such file or directory

I deleted R and reinstalled it, nothing changed the problem!!

I tried to reinstall raster package and I feel R couldn't find it:

install.packages("raster")'

The downloaded binary packages are in
    /var/folders/57/dn1sv79j3zzgy01h2l9v89v80000gn/T//RtmpKDG7bH/downloaded_packages

Again try intersect

    m<-raster::intersect(raster,shapefile)

Error in file(fn, "rb") : cannot open the connection
In addition: Warning message:
In file(fn, "rb") :
  cannot open file '/private/var/folders/57/dn1sv79j3zzgy01h2l9v89v80000gn/T/Rtmpg5AYsm/raster/r_tmp_2018-01-23_235923_1432_19427.gri': No such file or directory 

Appreciate any ideas!!

  • 1
    It looks like it fails when trying to write a tempfile. Is there more from the traceback? The function from the GIS site looks like it's on windows, did you change the filepaths? Do you have permissions to write to that directory? Maybe try some of the file commands that are inside that function, like `rasterOptions(tmpdir=file.path("c:/rtemp",i,j, single@data$OWNER))`. Or maybe I misunderstood---now you're getting the error on the commands that used to work for you? – twedl Jan 25 '18 at 02:18
  • correct I am getting error on the commands that used to work for me, I applied it on mac. – Nuha J. Alhowramy Jan 25 '18 at 02:37
  • What happens if you run `file(tempfile())` by itself (to see if you can get an error when trying to open a connection by yourself)? – twedl Jan 25 '18 at 02:56
  • 1
    I had a similar problem before. The problem with using `raster` on multiple core is that they do not deal well with temp files (they do not share there temp files and they loose them when turning off the clusters). What is your `raster` object. How did you create it? You should add some code, I suspect your problem is prior to what you are showing us and dought very much it's in your installation. – Bastien Jan 26 '18 at 13:50
  • > file(tempfile()) A connection with description "/var/folders/57/dn1sv79j3zzgy01h2l9v89v80000gp/T//Rtmp6Ld1cn/file3cf179cbd8e" – Nuha J. Alhowramy Jan 28 '18 at 00:46
  • I am working with dem files, I downloaded multiple dem files and merge them, after that, I am clipping and masking from the merged dem based on a specific shapefile boundary. I copy some code related to parallel and paste it in my r "specifically this web site in the link", in a trial to use multi-core in order to speed crop after that it did not work. Is there any way to fix the temp file? I am not familiar with that at all. – Nuha J. Alhowramy Jan 28 '18 at 00:57
  • 1
    Possible duplicate of [Can not open created raster in R](https://stackoverflow.com/questions/48511974/can-not-open-created-raster-in-r) – user3386170 Feb 03 '19 at 21:38

0 Answers0