Skip to content

Commit

Permalink
Remove AsIs class before checking arg types
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAxthelm committed Sep 3, 2024
1 parent ffff64e commit 05ec613
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions R/export_manifest.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,19 @@ create_manifest <- function(
return(manifest_list)
}

# Check that arguments are nicely coercible to JSON. called for side effect of
# `stop` if not.
#' check_arg_type
#'
#' Check that arguments are nicely coercible to JSON. Primarily a check that
#' lists are composed of simple types (other lists, characters,
#' numeric/integers, or logicals). Called for side effect of `stop` if not.
#'
#' @param arg object to check. Lists will be checked recursively, and must be
#' named.
#' @return the same object, unchanged. Function will throw an error if objects are not simple
check_arg_type <- function(arg) {
log_trace("Checking argument type")
# remove AsIs class if necessary
arg <- un_asis(arg)
if (inherits(arg, "list")) {
if (
length(arg) != length(names(arg)) ||
Expand Down Expand Up @@ -113,3 +122,17 @@ check_arg_type <- function(arg) {
}
return(arg)
}

#' un_asis
#'
#' Remove AsIs class from object
#'
#' @param x an object (with the `AsIs` class)
#' @return the same object, without AsIs class
un_asis <- function(x) {
if (inherits(x, "AsIs")) {
log_trace("Removing AsIs class from object")
class(x) <- class(x)[-match("AsIs", class(x))]
}
return(x)
}

0 comments on commit 05ec613

Please sign in to comment.