R/within.mitml.list.R

Defines functions within.mitml.list

Documented in within.mitml.list

within.mitml.list <- function(data, expr, ignore = NULL, ...){
# evaluate an expression for a list of data sets, then return altered data sets

  expr <- substitute(expr)
  parent <- parent.frame()

  out <- lapply(data, function(x){
    e <- evalq(environment(), x, parent)
    eval(expr, e)
    l <- as.list(e)
    l <- l[!sapply(l, is.null)]
    l[ignore] <- NULL
    nD <- length(del <- setdiff(names(x), (nl <- names(l))))
    x[nl] <- l
    if(nD){
      x[del] <- if(nD == 1){ NULL } else { vector("list", nD) }
    }
    x
  })

  class(out) <- c("mitml.list", "list")
  return(out)

}

Try the mitml package in your browser

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

mitml documentation built on Jan. 6, 2023, 5:17 p.m.