Marshalling of 'ncdf4' objects
# S3 method for ncdf4
marshal(x, ...)
# S3 method for ncdf4
marshallable(...)
A ncdf4:ncdf4 object.
Not used.
A marshalled
object as described in marshal()
.
base::readBin()
is used to produce a marshalled version
of the original object.
base::writeBin()
and ncdf4::nc_open()
are used to
reconstruct a version of the original object from the
marshalled object.
if (requireNamespace("ncdf4", quietly = TRUE)) {
library(ncdf4)
## Create a temporary NCDF file
tf <- tempfile(fileext = ".nc")
x <- ncvar_def("x", units = "count", dim = list())
nf <- nc_create(tf, x)
ncvar_put(nf, x, 42)
print(nf)
nc_close(nf)
rm(list = c("nf", "x"))
## Open NCDF file
nf <- nc_open(tf)
y <- ncvar_get(nf, "x")
## Marshal
nf_ <- marshal(nf)
## Unmarshal
nf2 <- unmarshal(nf_)
y2 <- ncvar_get(nf2, "x")
stopifnot(identical(y2, y))
}
#> File /tmp/henrik/Rtmpcvk0xd/filebeb45d2ecbc0.nc (NC_FORMAT_CLASSIC):
#>
#> 1 variables (excluding dimension variables):
#> float x[]
#> units: count
#>
#> 0 dimensions: