From 3e176e23dfa083ac571c5a044909fdbb70192b84 Mon Sep 17 00:00:00 2001 From: Nikolas Burkoff Date: Wed, 22 Jun 2022 11:00:03 +0100 Subject: [PATCH] export validation function (#75) --- NAMESPACE | 1 + NEWS.md | 2 ++ R/utils.R | 15 ++++++++++++++- _pkgdown.yml | 1 + man/validate_metadata.Rd | 26 ++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 man/validate_metadata.Rd diff --git a/NAMESPACE b/NAMESPACE index bce130458..122ea7119 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -114,6 +114,7 @@ export(set_keys) export(teal_data) export(teal_data_file) export(to_relational_data) +export(validate_metadata) import(shiny) importFrom(digest,digest) importFrom(formatters,var_labels) diff --git a/NEWS.md b/NEWS.md index 261f6b734..490bc3ae2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # teal.data 0.1.1.9001 +* Exported `validate_metadata` function. + # teal.data 0.1.1 ### Miscellaneous diff --git a/R/utils.R b/R/utils.R index 28c2cf60f..539b57003 100644 --- a/R/utils.R +++ b/R/utils.R @@ -119,10 +119,23 @@ check_pkg_quietly <- function(pckg, msg) { invisible(NULL) } -# validate metadata as a list of length one atomic + +#' validate metadata as a list of length one atomic entries (or NULL) +#' @param metadata `object` to be checked +#' @return `NULL` or throw error +#' @examples +#' +#' validate_metadata(NULL) +#' validate_metadata(list(A = TRUE, B = 10, C = "test")) +#' \dontrun{ +#' validate_metadata(list(a = 1:10)) +#' } +#' +#' @export validate_metadata <- function(metadata) { checkmate::assert_list(metadata, any.missing = FALSE, names = "named", null.ok = TRUE) lapply(names(metadata), function(name) { checkmate::assert_atomic(metadata[[name]], len = 1, .var.name = name) }) + return(NULL) } diff --git a/_pkgdown.yml b/_pkgdown.yml index e854a54c7..a3cbcb35c 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -86,6 +86,7 @@ reference: - join_keys - python_code - read_script + - validate_metadata - title: For Developers subtitle: R6 Classes desc: Abstract and concrete classes used to build teal functionality. diff --git a/man/validate_metadata.Rd b/man/validate_metadata.Rd new file mode 100644 index 000000000..9f7a3d879 --- /dev/null +++ b/man/validate_metadata.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{validate_metadata} +\alias{validate_metadata} +\title{validate metadata as a list of length one atomic entries (or NULL)} +\usage{ +validate_metadata(metadata) +} +\arguments{ +\item{metadata}{\code{object} to be checked} +} +\value{ +\code{NULL} or throw error +} +\description{ +validate metadata as a list of length one atomic entries (or NULL) +} +\examples{ + +validate_metadata(NULL) +validate_metadata(list(A = TRUE, B = 10, C = "test")) +\dontrun{ +validate_metadata(list(a = 1:10)) +} + +}