title: Error in .local(x, ...) : not a valid subset
body: <p>We have a 24-core HP workstation in our lab running on Ubuntu.  We are using RStudio and employing the parallel computation package.  Below is our code.  </p>
  
  <p>However, we always get the ERROR MESSAGE : Error in .local(x, ...) : not a valid subset</p>
  
  <hr>
  
  <pre><code>setwd("/home/physics/Documents/PNU OJT/January")
  getwd()
  library(RNetCDF)
  library(ncdf4)
  library(raster)
  library(sp)
  library(rasterVis)
  library(chron)
  library(RColorBrewer)
  library(lattice)
  library(maptools)
  library(parallel)
  library(rgdal)
  library(rgeos)
  
  f &lt;- function(s){ 
      for(i in 1:5){
          mask(s, PHL[PHL@data$OBJECTID== i,])
          MeanPW&lt;- cellStats(mask(s, PHL[PHL@data$OBJECTID== i,]),   
              stat=mean, na.rm=TRUE)
          if (is.na(MeanPW)) (MeanPW&lt;-NaN) 
          MeanPW&lt;-toString(MeanPW)
          date &lt;- substr(list.files(pattern= ".nc")[O], 15, 17)
          date &lt;- as.numeric(date)
          date2 &lt;- as.Date(date, origin = "2002/12/31")
          date1 &lt;- format(date2, "%Y/%b/%d")
          date2 &lt;- as.character(date2)
          year &lt;- substr(date1, 1, 4)
          month &lt;- substr(date1, 6, 8)
          month_name &lt;- substr(date2, 6, 7)
          season &lt;- if (as.numeric(month_name) &lt; 06 | 
              as.numeric(month_name)==12) {"Dry"} else("Wet")
          Table &lt;- cbind(date2, year, month, season, MeanPW, 
             matrix(Classification$Classification)[i], 
             PHL@data$NAME_2[1:length(PHL@data$OBJECTID)], 
             matrix(Region$Region)[1:length(PHL@data$OBJECTID)])
          write.table(Table, paste("Urban", 13, ".csv", sep=""), sep=",", 
             append=TRUE)
      }
      return(Table)
  }
  
  cl &lt;- makeCluster(16)
  
  PHL &lt;- readRDS("PHL_adm2.rds")
  Classification &lt;- read.csv("Classification.csv")
  Region &lt;- read.csv("Region.csv")
  PHL@data &lt;- cbind(PHL@data, Classification, Classification$Region)
  M &lt;- list.files(pattern= ".nc")
  s &lt;- raster(nrow=1800, ncol=3600)
  
  for(O in 1:2){
      Dataname &lt;- M[O]
      AlltheFiles &lt;- open.nc(Dataname)
      read.nc(AlltheFiles)
      PWV &lt;- raster(Dataname)
      PW_PHL &lt;- crop(PWV, PHL)
      s &lt;- resample(PW_PHL, s)
      s &lt;- crop(s, PHL)
      s &lt;- mask(s, PHL)
      clusterApply(cl, s, f)
  }
  </code></pre>
  
  <hr>
  
  <p>I hope you could help us.</p>