R/within.nested.datlist.R

## File Name: within.nested.datlist.R
## File Version: 1.08


#########################################################
within.nested.datlist <- function (data, expr, ...)
{
    res <- data
    CALL <- attr(res,"call")
    imp <- res
    NB <- length(imp)
    NW <- length(imp[[1]])
    for (ii in 1:NB){
        for (ww in 1:NW){
            # this function is simply a copy of within.data.frame
            parent <- parent.frame()
            data <- imp[[ii]][[ww]]
            e <- evalq(environment(), data, parent)
            eval(substitute(expr), e)
            l <- as.list(e)
            l <- l[!sapply(l, is.null)]
            nD <- length(del <- setdiff(names(data), (nl <- names(l))))
            data[nl] <- l
            if (nD)
                data[del] <- if (nD==1)
                    NULL
                else vector("list", nD)
            imp[[ii]][[ww]] <- data
        }
    }
    res <- nested.datlist_create( imp )
    attr(res,"call") <- CALL
    return(res)
}
###############################################################

Try the miceadds package in your browser

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

miceadds documentation built on May 29, 2024, 11:05 a.m.