Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NAs in foreign function call trying to open a netcdf file in R

Tags:

r

netcdf

I'm using the library ncdf with R version 3.0.2. I'm trying to open and close some netcdfs over and over again (I can explain why but it isn't needed for this question).

sapply(1:14000, function(whatever) {
    print(whatever)
      sapply(prediction.cdfs, function(cdf) {
        print(file.path(cdf.dir, cdf))
        nc = open.ncdf(file.path(cdf.dir, cdf))
        close.ncdf(nc)
      })
})

After open and closing over and over again it eventually fails with this error:

[1] 3329                                                                                             

[1] "/opt/devel/cdfs/file_one.cdf"

[1] "/opt/devel/cdfs/file_two.cdf"

[1] "/opt/devel/cdfs/file_three.cdf"

[1] "/opt/devel/cdfs/file_four.cdf"

[1] "/opt/devel/cdfs/file_five.cdf"

Error in open.ncdf(file.path(cdf.dir, cdf)) : 
  NAs in foreign function call (arg 1)

Anyone know what's going on? The error seems stochastic in nature. The time till it barks about the foreign function call is variable. I'm looking for an explanation or just a work around?

Thanks

like image 757
Andrew Cassidy Avatar asked Jan 22 '26 01:01

Andrew Cassidy


1 Answers

I believe the problem was from un-closed connections to the same files from a previous step in my analysis. I'm running this on a Linux system, so I tracked the open file connections as the loop was running using

watch ls -l /proc/${PID}/fd

The connections opened and closed just fine, but I saw some old connections laying around from my previous analysis. I closed them and everything run just fine!!!

like image 162
Andrew Cassidy Avatar answered Jan 24 '26 15:01

Andrew Cassidy