xcms icon indicating copy to clipboard operation
xcms copied to clipboard

Error in R_nc4_open: Too many open files and fail to load xcms package v 3.4.5

Open lysoifer opened this issue 3 years ago • 1 comments

I am running a for loop to extract data from .nc files for a series of points using the mcera5 package. However, after several iterations, I am getting the following error: "Error in R_nc4_open: Too many files".

for (i in c(1:length(pai_tiles))) {
  ll = latlongfromraster(pai_tiles[[i]])
  weath = list()
  for (yr in c(1:length(my_nc))) {
    #extract data from ERA5
    nc = my_nc[yr]
    w = extract_clim(nc = nc,
                     long = ll$long, lat = ll$lat,
                     start_time = st_times[[yr]], end_time = en_times[[yr]])
    weath[[yr]] = w
    #on.exit(close(nc))
  }
  #bind together weather dataframes for all years
  weath.df = rbindlist(weath)
  weather[[i]] = weath.df
  rm(weath, weath.df)
}

I found the following thread regarding this same error - [sneumann/mzR/issues/185]. I followed the recommendation devtools::install_github("sneumann/xcms", ref = "RELEASE_3_8")

However, when I try to install this version of the xcms R package, it fails to load

Error: objects 'Chromatograms', 'Spectra' are not exported by 'namespace:MSnbase'
Execution halted
ERROR: lazy loading failed for package 'xcms'
 removing 'C:/Users/lsoif/OneDrive/Documents/R/win-library/4.1/xcms'
 restoring previous 'C:/Users/lsoif/OneDrive/Documents/R/win-library/4.1/xcms'
Warning message:
In i.p(...) :
  installation of package ‘C:/Users/lsoif/AppData/Local/Temp/Rtmpk7NKSY/file505035e22126/xcms_3.4.5.tar.gz’ had non-zero exit status

I am using R v 4.1.1. Do you have any suggestions on how to install xcms version 3.4.5 or fix the 'too many files' error?

Thanks.

lysoifer avatar Jan 06 '22 17:01 lysoifer

The fix was added to packages from Bioconductor release 3.8 and should be in there since. So, no need to specify ref = "RELEASE_3_8" in the install_github - actually, it's recommended to install xcms using BiocManager::install("xcms") instead (in case you might need to install.packages("BiocManager") first).

Also note that you might fix your error by specicially closing opened CDF files (i.e. call close(nc) in each loop).

jorainer avatar Jan 07 '22 08:01 jorainer