R/aaa.R

Defines functions is_string topNamespaceName `append<-` new_function `%||%`

`%||%` <- function(x, y) if (is.null(x)) y else x

new_function <- function(args = NULL,
                         body = NULL,
                         env = asNamespace("S7")) {
  as.function.default(c(args, body) %||% list(NULL), env)
}


`append<-` <- function(x, after, value) {
  if (missing(after))
    c(x, value)
  else
    append(x, value, after = after)
}

`append1<-` <- function (x, value) {
  stopifnot(is.list(x) || identical(mode(x), mode(value)))
  x[[length(x) + 1L]] <- value
  x
}


topNamespaceName <- function(env = parent.frame()) {
  env <- topenv(env)
  if (!isNamespace(env)) {
    return() # print visible
  }

  as.character(getNamespaceName(env)) # unname
}

is_string <- function(x) {
  identical(class(x), "character") && length(x) == 1L && !is.na(x) && x != ""
}

Try the S7 package in your browser

Any scripts or data that you put into this service are public.

S7 documentation built on April 3, 2025, 10:50 p.m.