R/returnMultipleValues.R

####################################################################################################################################
################################## ':=' ############################################################################################
# >>
':=' <- function(lhs, rhs) {
    
    frame = parent.frame()
    
    lhs   = as.list(substitute(lhs))
    
    if( length(lhs) > 1 )  { lhs = lhs[-1] }
    
    if( length(lhs) == 1 ) { 
        do.call(`=`, list(lhs[[1]], rhs), envir=frame)
        return(invisible(NULL)) 
    }
    
    if( is.function(rhs) || is(rhs, 'formula') ) { rhs <- list(rhs) }
    
    if( length(lhs) > length(rhs) ) { rhs <- c(rhs, rep(list(NULL), length(lhs) - length(rhs))) }
    
    for( i in 1:length(lhs) ) { do.call(`=`, list(lhs[[i]], rhs[[i]]), envir=frame) }
    
    return(invisible(NULL)) 
    
}
# <<
################################## ':=' ############################################################################################
####################################################################################################################################


####################################################################################################################################
################################## Help Code #######################################################################################
# >>
# c(a, b) := anotherFunction(arg)
# <<
################################## Help Code #######################################################################################
####################################################################################################################################
ShashankKumbhare/paramonteR documentation built on April 25, 2022, 12:08 a.m.