Nothing
#' Check whether an object is empty
#'
#' Check whether an object is empty, e.g. has no sub-elements, is NA, or is the
#' empty string.
#'
#' @param x An object.
#'
#' @examples
#' is_empty(NA) # TRUE
#' is_empty("") # TRUE
#' is_empty(list()) # TRUE
#' is_empty(list(list())) # TRUE
#'
#' is_empty(1) # FALSE
#' is_empty(list(1)) # FALSE
#' is_empty(list(list(1))) # FALSE
#'
#' @export
is_empty <- function(x) {
if (is.null(x) || length(x) == 0) return(TRUE)
UseMethod("is_empty")
}
#' @export
is_empty.character <- function(x) {
return(is.na(x) || x == "")
}
#' @export
is_empty.raw <- function(x) {
return(length(x) == 0)
}
# Check if a list of values is empty. If the list is recursive, search the list.
#' @export
is_empty.list <- function(x) {
return(all(sapply(x, is_empty)))
}
#' @export
is_empty.default <- function(x) {
return(is.na(x))
}
# Call a function `f` with arguments taken from elements in `data`, including
# only those data elements that correspond to parameters.
# For example:
# f <- function(a) {}
# data <- list(a = "1", b = "2")
# call_with_args(f, data) == f("1")
call_with_args <- function(f, data) {
args <- methods::formalArgs(f)
if (is.null(args)) {
return(f())
}
if (!all(args %in% names(data))) {
stop("A parameter has no corresponding element in `data`.")
}
return(do.call(f, as.list(data)[args]))
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.