#' Deserialize object from nctables format
#'
#' @author Ben Fasoli
#'
#' @param nc an object of class `ncdf4` as returned by `nc_open`
#' @param var string indicating variable to deserialize
#'
#' @import ncdf4
nct_deserialize <- function(nc, var) {
type_att <- ncdf4::ncatt_get(nc = nc,
varid = var,
attname = 'nct_type')
if (!type_att$hasatt) {
stop('File was not created with nctables::nct_create.')
}
nct_type <- type_att$value
vals <- ncdf4::ncvar_get(nc, var)
type_map <- getOption('nctables_type_map')
type <- names(type_map)[type_map == nct_type]
class(vals) <- type
attributes(vals) <- switch(type,
'POSIXct' = list(class = c('POSIXct', 'POSIXt'),
tzone = 'UTC'),
'Date' = list(class = 'Date', tzone = 'UTC'),
list(class = type))
vals
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.