title: Extend dimensions in netCDF file using R
body: <p>I would like to write a netCDF file using R with 'unlimited' dimensions that I can later extend.</p>
  
  <p>This is what I have tried:</p>
  
  <h3>Create a netcdf file</h3>
  
  <pre><code>library(ncdf4)
  
  ## define lat, lon time dimensions
  lat &lt;- ncdim_def("latitude", "degrees_east", vals =  44.0, unlim = TRUE) 
  lon &lt;- ncdim_def("longitude", "degrees_north", vals = -88.5, unlim = TRUE)
  time &lt;- ncdim_def("time", "days since 0000-01-01", 1:1000)
  
  ## define data with these dimensions
  x &lt;- ncvar_def("myvar", units = "m2", dim = list(lat, lon, time))
  
  ## create, write to, close nc file
  nc &lt;- nc_create(filename = "tmp.nc", vars = list(x))
  
  ncvar_put(nc = nc, varid = x, vals = 1:1000)
  nc_close(nc = nc)
  </code></pre>
  
  <h3>I want to add a new vector at a different lat and lon</h3>
  
  <pre><code>## reopen existing file
  nc &lt;- nc_open("tmp.nc", write = TRUE)
  
  ## define new lat, lon dimensions (keep time dim from above)
  lat2 &lt;- ncdim_def("latitude", "degrees_east", vals =  44.5, unlim = TRUE) 
  lon2 &lt;- ncdim_def("longitude", "degrees_north", vals = -89.0, unlim = TRUE)
  
  ## define, write new dataset at new lat lon coordinates
  x2 &lt;- ncvar_def("myvar", units = "m2", dim = list(lat2, lon2, time))
  ncvar_put(nc = nc, varid = x2, vals = 11:1011)
  </code></pre>
  
  <h3>I would expect to find the two different latitudes and longitudes</h3>
  
  <pre><code>ncvar_get(nc, 'latitude')
  ncvar_get(nc, 'longitude')
  
  ncvar_get(nc, 'myvar')
  </code></pre>
  
  <p>These show that the file was written using the first set of lat/lon and 'myvar' values, but was not appended with the new set of values.</p>
  
  <h3>What am I doing wrong?</h3>
  
  <p>I know that the ability to have multiple unlimited dimensions, and to add to them, is a feature of netCDF-4. How can I do this in R?</p>
  
  <p>I recognize that I must be confusing the 'dimension definition' with some other concept. But I am a bit lost.</p>