R/clist.R

Defines functions length.clist as.list.clist `[[<-.clist` `[<-.clist` `[[.clist` `[.clist` print.clist format.clist

#' @export
format.clist <- function(x, ..., dict = FALSE) {
  class(x) <- setdiff(class(x), "clist")
  if(dict) {
    x
  } else {
    order <- attr(x, "order")
    x[order]
  }
}

#' @export
print.clist <- function(x, ...) {
  print(format(x, ...))
}

#str.clist <- function(x, ...) {
#  str(format(x), ...)
#}

#' @export
`[.clist` <- function(x, i, ...) {
  iorder <- attr(x, "order")[i]
  format(x, dict = TRUE)[iorder]
}

#' @export
`[[.clist` <- function(x, i, ...) {
  iorder <- attr(x, "order")[i]
  format(x, dict = TRUE)[[iorder]]
}


#' @export
`[<-.clist` <- function(x, i, ..., value) {
  res <- format(x)
  res[i] <- value
  res
}

#' @export
`[[<-.clist` <- function(x, i, ..., value) {
  res <- format(x)
  res[[i]] <- value
  res
}

#' @export
as.list.clist <- function(x, ...) {
  format(x)
}

#' @export
length.clist <- function(x, ...) {
  length(attr(x, "order"))
}

Try the nestr package in your browser

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

nestr documentation built on Feb. 2, 2022, 1:07 a.m.