Write multiple attributes to a netCDF variable or file
Source:R/nctools-auxiliar.R
ncatt_put_all.RdWrites several attributes to a variable or to the global file metadata of an open netCDF file.
Arguments
- nc
An open netCDF connection created with
ncdf4::nc_open().- varid
Variable identifier. This can be a character string giving the variable name, an object of class
ncvar4, or an integer id. As a special case,varid = 0writes global attributes.- attname
Names of the attributes to write. Alternatively, this may be a named vector or list of attribute values when
attvalis omitted.- attval
Values of the attributes to write. If omitted,
attnamemust be a named vector or list whose names are used as attribute names.- prec
Optional precision used when writing the attributes. Passed to
ncdf4::ncatt_put().- verbose
Logical. If
TRUE, print additional information while writing attributes.- definemode
Logical. Passed to
ncdf4::ncatt_put(). See that function for details.
Details
Attributes can be supplied either as parallel attname and attval
arguments, or as a single named vector or list. Missing attribute names are
not allowed.
Examples
local({
input = system.file("extdata",
"temperature_2001_01.nc",
package = "nctools",
mustWork = TRUE)
copy = tempfile(fileext = ".nc")
file.copy(input, copy)
nc = ncdf4::nc_open(copy, write = TRUE)
on.exit({ ncdf4::nc_close(nc); unlink(copy) }, add = TRUE)
ncatt_put_all(nc, 0, attval = list(title = "Edited copy"))
})