title: Fail to loop in creating multiple NCDF4 files from analysis
body: <p>I have the following script to write analysis outputs to individual NCDF4 files. The script is writing the first file and stops.
  the error i am getting is :-</p>
  
  <p>Error in R_nc4_create: Permission denied (creation mode was 4096)
  Error in nc_create(ncfname, list(tmp_def, tmp_def2), force_v4 = T) : 
    Error in nc_create!</p>
  
  <p>there appears to be something wrong with the:-</p>
  
  <pre><code>ncfname&lt;- sprintf('%sA.nc', Listbreak3)
  </code></pre>
  
  <p>and I can't figure it out.</p>
  
  <p>My script is part of a much larger analysis. But the the part of interests is below. </p>
  
  <p>It could be the loop, But I think the loop is okay</p>
  
  <p>Hope somebody has wrote multiple NCDF4 files</p>
  
  Write NCDF4 files
  
  #
  
  <pre><code>  tunits&lt;-"days since 1800-01-01 00:00:00"
  
    #Define dimensions
    ##################################################################
    londim&lt;-ncdim_def("Lon","degrees_east",as.double(Lon))
    latdim&lt;-ncdim_def("Lat", "degrees_north",as.double(Lat))
    timedim&lt;-ncdim_def("timeset",tunits,as.double(timeset))
  
    #Define variables
    ##################################################################
    fillvalue&lt;-NA
  
    dlname&lt;-"2 meter air temperature"
    dlname2&lt;-" 2 meter max air temperature"
  
    tmp_def&lt;-ncvar_def("Y2ts_Stripped","deg_C",
    list(londim,latdim,timedim),fillvalue,dlname,prec = "double")
    tmp_def2&lt;-ncvar_def("X2ts_Stripped","deg_C", 
    list(londim,latdim,timedim),fillvalue,dlname2,prec = "double")
  
    ncatt_put(ncout,"Lon","axis","X")
    ncatt_put(ncout, "Lat", "axis", "Y")
    ncatt_put(ncout, "timeset","axis", "T")
  
    #################################################
    title&lt;-c( 1:2 )
    names(title)&lt;-c("jack","jill")
    title&lt;-as.data.frame(title)
    ###############################################  
     Listbreak&lt;-filelist
  
  
     #Create Ncdf4 file and  put arrays 
     ##################################################################
     for (i in 1:length( Listbreak)){
     Listbreak2&lt;-do.call(rbind, strsplit(Listbreak, "[[:punct:]]|\\s")) 
     [,c(1, 2,3)]###Breaking up the file name
     Listbreak3&lt;-Listbreak2[,2]
  
  
      ncfname&lt;- sprintf('%sA.nc', Listbreak3)
  
      ncout&lt;-nc_create(ncfname,list(tmp_def,tmp_def2),force_v4=T) 
  
      ncvar_put(ncout,tmp_def,Y2ts_Stripped,start=NA,count = NA )
  
      ncvar_put(ncout,tmp_def2,X2ts_stripped, start= NA,count = NA )
  
      } 
  
      # attributes # the 0 designates the attribute as global 
      ###########################################################
      ncatt_put(ncout,0,"Make_NCDF4_File",1, prec="int")
      ncatt_put(ncout,0,"Maynooth_University",1,prec="short")
      ncatt_put(ncout,0,"AR000087828",1, prec="short")
      ncatt_put(ncout,0,"description","this is the script to write NCDF4 
      files")
  
  
      #Close file and write date to disk
      ##########################################################
      nc_close(ncout)
  </code></pre>