From 8046ed8691f99fd7e32b9f1bb9488086e1a019b5 Mon Sep 17 00:00:00 2001 From: Michael Sumner Date: Mon, 25 Mar 2024 09:34:50 +0000 Subject: [PATCH] release --- DESCRIPTION | 4 ++-- NEWS.md | 4 ++++ R/nc_extended.R | 32 +++----------------------------- cran-comments.md | 11 +++-------- man/ncmeta-package.Rd | 1 + 5 files changed, 13 insertions(+), 39 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 580770e..f8561a3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ncmeta Title: Straightforward 'NetCDF' Metadata -Version: 0.3.6 +Version: 0.4.0 Authors@R: c(person("Michael", "Sumner", email = "mdsumner@gmail.com", role = c("aut", "cre")), person("Tomas", "Remenyi", role = "ctb"), person("Ben", "Raymond", role = "ctb"), @@ -15,7 +15,7 @@ Description: Extract metadata from 'NetCDF' data sources, these can be files, fi Depends: R (>= 3.3.0) License: GPL-3 Encoding: UTF-8 -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 Imports: dplyr, rlang, diff --git a/NEWS.md b/NEWS.md index 0c29abc..ba7850f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# ncmeta 0.4.0 + +* New function `nc_extended()` to enerate a table of extended dimension attributes, supporting 'time' currently (contributed by Patrick Van Laake). + # ncmeta 0.3.6 * Fixed namespace doc thanks to CRAN. diff --git a/R/nc_extended.R b/R/nc_extended.R index fe10420..a053526 100644 --- a/R/nc_extended.R +++ b/R/nc_extended.R @@ -17,7 +17,7 @@ nc_extended <- function(x, ...) { #' @export nc_extended.character <- function(x, ...) { if (nchar(x) < 1) stop("NetCDF source cannot be empty string") - + if (file.exists(x)) x <- normalizePath(x) nc <- RNetCDF::open.nc(x) on.exit(RNetCDF::close.nc(nc), add = TRUE) nc_extended(nc) @@ -55,33 +55,7 @@ nc_extended.NetCDF <- function(x, ...) { #' @name nc_extended #' @export nc_extended.ncdf4 <- function(x, ...) { - if (x$ndims == 0) return(tibble::tibble()) - - ## Add time information for any "time" dimension. Since not all files have a - ## "calendar" attribute or "axis == "T"", just try to create a CFtime - ## instance for any dimension variable with a "units" attribute and a - ## "calendar", if present. - cftime <- lapply(x$dim, function(d) { - units <- d$units - if (!is.null(units) && nchar(units) >= 8) { - try({ - # Create cheap bare-bones instance, to see if units represent time - cf <- CFtime::CFtime(units, d$calendar) - - # If we get here we have a CFtime instance, so now add offsets. - # NetCDF file may have been opened with suppress_dimvals = T or - # readunlim = F so test if we have vals as dim element. - if (!is.null(d$vals)) off <- d$vals - else off <- ncvar_get(x, d$name) - return(cf + as.vector(off)) - }, silent = TRUE) - } - return (NA) - }) - - ## Any other extended attributes to be added here - - ## Output - tibble::tibble(dimension = sapply(x$dim, function(d) d$id), name = sapply(x$dim, function(d) d$name), time = cftime) + ## we don't support ncdf4 so pass to RNetCDF + nc_extended(RNetCDF::open.nc(x$filename)) } diff --git a/cran-comments.md b/cran-comments.md index 83b1b06..92fdf8a 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,11 +1,12 @@ -# Release 0.3.5 of ncmeta +# Release 0.4.0 of ncmeta -Fix downstream problems tidync and other revdeps where extra metadata was not handled by dataframe structure. +New function `nc_extended()`. ## Test environments * local ubuntu * win-builder (devel and release) +* mac-builder (release) ## R CMD check results @@ -16,9 +17,3 @@ Fix downstream problems tidync and other revdeps where extra metadata was not ha The reverse dependencies pass check with this version. -* ncdfgeom -* oceanexplorer -* tidync -* sftime -* stars - \ No newline at end of file diff --git a/man/ncmeta-package.Rd b/man/ncmeta-package.Rd index d64cc13..8dd322f 100644 --- a/man/ncmeta-package.Rd +++ b/man/ncmeta-package.Rd @@ -39,6 +39,7 @@ API and by the two R wrapper providers \code{RNetCDF} and \code{ncdf4}. Useful links: \itemize{ \item \url{https://github.com/hypertidy/ncmeta} + \item \url{https://hypertidy.github.io/ncmeta/} \item Report bugs at \url{https://github.com/hypertidy/ncmeta/issues} }