Renames one or more variables and/or dimensions in an existing netCDF file, optionally writing the result to a new file.
Arguments
- filename
Character string giving the path to the input netCDF file.
- oldnames
Character vector with the current names of variables or dimensions to rename.
- newnames
Character vector with the replacement names. Must be in the same order and of the same length as
oldnames.- output
Optional character string giving the path to the output file. If omitted,
overwrite = TRUEmust be used and the original file is replaced.- verbose
Logical. If
TRUE, print the renaming operations performed.- overwrite
Logical. If
TRUE, allow overwriting an existing output file. Use this when modifying the original file in place.
Details
Names in oldnames that do not match either a variable or a dimension in the
file are ignored with a warning. If none of the requested names are found,
the function exits without making changes.
Examples
local({
input = system.file("extdata",
"temperature_2001_01.nc",
package = "nctools",
mustWork = TRUE)
output = tempfile(fileext = ".nc")
on.exit(unlink(output))
nc_rename(input, "temperature", "temp", output = output)
})