R/NAhandling.R

Defines functions complete.cases.ModelEnv

### NA handling for objects of class `ModelEnv'

complete.cases.ModelEnv <- function(x) {
    
    do.call("complete.cases", as.data.frame(lapply(ls(x@env), function(o) x@get(o))))

}

# setGeneric("na.fail", useAsDefault = na.fail)

setMethod("na.fail", signature = "ModelEnv", definition = function(object, ...) {

    cc <- complete.cases.ModelEnv(object)
    if (!all(cc)) return(FALSE)
    return(object)
})

# setGeneric("na.pass", useAsDefault = na.pass)

setMethod("na.pass", signature = "ModelEnv", definition = function(object, ...) {  

    return(object)

})

# setGeneric("na.omit", useAsDefault = na.omit)

setMethod("na.omit", signature = "ModelEnv", definition = function(object, ...) {

    cc <- complete.cases.ModelEnv(object)
    if (!all(cc)) return(subset(object, cc, ...))
    return(object)

})

Try the modeltools package in your browser

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

modeltools documentation built on March 13, 2020, 1:53 a.m.