문제

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

도움이 되었습니까?

해결책

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!!!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top