diff --git a/.Rbuildignore b/.Rbuildignore index 5b23b455401c260d8450a0920702c162a6fcf585..e06dfa986fbe1bc1f42937fb8aa767264c38cfe6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ .gitlab-ci.yml # unit tests should be ignored when building the package for CRAN ^tests$ +^CONTRIBUTING\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index 26bf454899e6a696149fa0666ef5048ad58b42cf..cb6d1b5ba450f105dcc376cd41acef328c1b98ee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,6 +18,6 @@ License: GPL-3 URL: https://earth.bsc.es/gitlab/es/easyNCDF BugReports: https://earth.bsc.es/gitlab/es/easyNCDF/-/issues SystemRequirements: netcdf development libraries -RoxygenNote: 7.2.0 +RoxygenNote: 7.3.1 Encoding: UTF-8 Config/testthat/edition: 3 diff --git a/R/ArrayToNc.R b/R/ArrayToNc.R index 6b4e477fd17e073d7c46124b337741d2ba1c8584..6952edc978799596e26c6cf802d353a9ff176963 100644 --- a/R/ArrayToNc.R +++ b/R/ArrayToNc.R @@ -5,53 +5,56 @@ #'arrays and stores them in a NetCDF file, using the \code{ncdf4} package. The #'full path and name of the resulting file must be specified. Metadata can be #'attached to the arrays and propagated into the NetCDF file in 3 possible -#'ways:\cr -#' \itemize{ - #' \item{Via the list names if a list of arrays is provided:}{Each name in -#' the input list, corresponding to one multidimensional array, will be -#' interpreted as the name of the variable it contains.\cr -#'E.g:\cr -#' \code{ -#'ArrayToNc(arrays = list(temperature = array(1:9, c(3, 3))), -#' file_path = 'example.nc') +#'ways: +#' \describe{ +#' \item{Via the list names if a list of arrays is provided:}{ +#' Each name in the input list, corresponding to one multidimensional +#' array, will be interpreted as the name of the variable it contains. +#' +#' E.g.: +#' \code{ +#' ArrayToNc(arrays = list(temperature = array(1:9, c(3, 3))), +#' file_path = 'example.nc') #' } #' } -#' \item{Via the dimension names of each provided array:}{The dimension names -#' of each of the provided arrays will be interpreted as names for the -#' dimensions of the NetCDF files. Read further for special dimension -#' names that will trigger special behaviours, such as 'time' and 'var'. -#'\cr -#'E.g:\cr +#' \item{Via the dimension names of each provided array:}{ +#' The dimension names of each of the provided arrays will be interpreted +#' as names for the dimensions of the NetCDF files. Read further for +#' special dimension names that will trigger special behaviours, such as +#' 'time' and 'var'. +#' +#' E.g.: #' \code{ -#'temperature <- array(rnorm(100 * 50 * 10), dim = c(100, 50, 10)) -#'names(dim(temperature)) <- c('longitude', 'latitude', 'time') -#'ArrayToNc(list(temperature = temperature), file_path = 'example.nc') +#' temperature <- array(rnorm(100 * 50 * 10), dim = c(100, 50, 10)) +#' names(dim(temperature)) <- c('longitude', 'latitude', 'time') +#' ArrayToNc(list(temperature = temperature), file_path = 'example.nc') #' } #' } -#' \item{Via the attribute 'variables' of each provided array:}{The arrays -#' can be provided with metadata in an attribute named 'variables', which -#' is expected to be a named list of named lists, where the names of the -#' container list are the names of the variables present in the provided -#' array, and where each sub-list contains metadata for each of the -#' variables. The attribute names and values supported in the sub-lists -#' must follow the same format the package \code{ncdf4} uses to represent -#' the NetCDF file headers.\cr -#'E.g:\cr +#' \item{Via the attribute 'variables' of each provided array:}{ +#' The arrays can be provided with metadata in an attribute named +#' 'variables', which is expected to be a named list of named lists, where +#' the names of the container list are the names of the variables present +#' in the provided array, and where each sub-list contains metadata for +#' each of the variables. The attribute names and values supported in the +#' sub-lists must follow the same format the package \code{ncdf4} uses to +#' represent the NetCDF file headers. +#' +#' E.g.: #' \code{ -#'a <- array(1:400, dim = c(5, 10, 4, 2)) -#'metadata <- list( -#' tos = list(addOffset = 100, -#' scaleFact = 10, -#' dim = list(list(name = 'time', -#' unlim = FALSE))), -#' tas = list(addOffset = 100, -#' scaleFact = 10, -#' dim = list(list(name = 'time', -#' unlim = FALSE))) -#' ) -#'attr(a, 'variables') <- metadata -#'names(dim(a)) <- c('lat', 'lon', 'time', 'var') -#'ArrayToNc(a, 'tmp.nc') +#' a <- array(1:400, dim = c(5, 10, 4, 2)) +#' metadata <- list( +#' tos = list(addOffset = 100, +#' scaleFact = 10, +#' dim = list(list(name = 'time', +#' unlim = FALSE))), +#' tas = list(addOffset = 100, +#' scaleFact = 10, +#' dim = list(list(name = 'time', +#' unlim = FALSE))) +#' ) +#' attr(a, 'variables') <- metadata +#' names(dim(a)) <- c('lat', 'lon', 'time', 'var') +#' ArrayToNc(a, 'tmp.nc') #' } #' } #' } @@ -235,7 +238,7 @@ ArrayToNc <- function(arrays, file_path) { if (!is.character(file_path)) { stop("Parameter 'file_path' must be a character string.") } - + defined_dims <- list() defined_vars <- list() global_attrs <- list() diff --git a/man/ArrayToNc.Rd b/man/ArrayToNc.Rd index e51880ebb621affb4a878d274ebc5e203b8864ec..ed65ff3edf94c0de41d0e895f7eca397b9ab69ae 100644 --- a/man/ArrayToNc.Rd +++ b/man/ArrayToNc.Rd @@ -25,53 +25,56 @@ This function takes as input one or a list of multidimensional R arrays and stores them in a NetCDF file, using the \code{ncdf4} package. The full path and name of the resulting file must be specified. Metadata can be attached to the arrays and propagated into the NetCDF file in 3 possible -ways:\cr - \itemize{ - \item{Via the list names if a list of arrays is provided:}{Each name in - the input list, corresponding to one multidimensional array, will be - interpreted as the name of the variable it contains.\cr -E.g:\cr - \code{ -ArrayToNc(arrays = list(temperature = array(1:9, c(3, 3))), - file_path = 'example.nc') +ways: + \describe{ + \item{Via the list names if a list of arrays is provided:}{ + Each name in the input list, corresponding to one multidimensional + array, will be interpreted as the name of the variable it contains. + + E.g.: + \code{ + ArrayToNc(arrays = list(temperature = array(1:9, c(3, 3))), + file_path = 'example.nc') } } - \item{Via the dimension names of each provided array:}{The dimension names - of each of the provided arrays will be interpreted as names for the - dimensions of the NetCDF files. Read further for special dimension - names that will trigger special behaviours, such as 'time' and 'var'. -\cr -E.g:\cr + \item{Via the dimension names of each provided array:}{ + The dimension names of each of the provided arrays will be interpreted + as names for the dimensions of the NetCDF files. Read further for + special dimension names that will trigger special behaviours, such as + 'time' and 'var'. + + E.g.: \code{ -temperature <- array(rnorm(100 * 50 * 10), dim = c(100, 50, 10)) -names(dim(temperature)) <- c('longitude', 'latitude', 'time') -ArrayToNc(list(temperature = temperature), file_path = 'example.nc') + temperature <- array(rnorm(100 * 50 * 10), dim = c(100, 50, 10)) + names(dim(temperature)) <- c('longitude', 'latitude', 'time') + ArrayToNc(list(temperature = temperature), file_path = 'example.nc') } } - \item{Via the attribute 'variables' of each provided array:}{The arrays - can be provided with metadata in an attribute named 'variables', which - is expected to be a named list of named lists, where the names of the - container list are the names of the variables present in the provided - array, and where each sub-list contains metadata for each of the - variables. The attribute names and values supported in the sub-lists - must follow the same format the package \code{ncdf4} uses to represent - the NetCDF file headers.\cr -E.g:\cr + \item{Via the attribute 'variables' of each provided array:}{ + The arrays can be provided with metadata in an attribute named + 'variables', which is expected to be a named list of named lists, where + the names of the container list are the names of the variables present + in the provided array, and where each sub-list contains metadata for + each of the variables. The attribute names and values supported in the + sub-lists must follow the same format the package \code{ncdf4} uses to + represent the NetCDF file headers. + + E.g.: \code{ -a <- array(1:400, dim = c(5, 10, 4, 2)) -metadata <- list( - tos = list(addOffset = 100, - scaleFact = 10, - dim = list(list(name = 'time', - unlim = FALSE))), - tas = list(addOffset = 100, - scaleFact = 10, - dim = list(list(name = 'time', - unlim = FALSE))) - ) -attr(a, 'variables') <- metadata -names(dim(a)) <- c('lat', 'lon', 'time', 'var') -ArrayToNc(a, 'tmp.nc') + a <- array(1:400, dim = c(5, 10, 4, 2)) + metadata <- list( + tos = list(addOffset = 100, + scaleFact = 10, + dim = list(list(name = 'time', + unlim = FALSE))), + tas = list(addOffset = 100, + scaleFact = 10, + dim = list(list(name = 'time', + unlim = FALSE))) + ) + attr(a, 'variables') <- metadata + names(dim(a)) <- c('lat', 'lon', 'time', 'var') + ArrayToNc(a, 'tmp.nc') } } }