Last active
October 21, 2016 19:40
-
-
Save brooke-watson/e03c8a785fe69cbef42a7ebfe9e24613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'%=%' = function(l, r, ...) | |
UseMethod('%=%') | |
# Binary Operator | |
'%=%.lbunch' = function(l, r, ...) { | |
Envir = as.environment(-1) | |
if (length(r) > length(l)) | |
warning("Right side has more args than left side. Only first ", length(l), " arguments used.") | |
if (length(l) > length(r)) { | |
warning("Left side has more arguments than right side. Right side will be repeated.") | |
r <- extendToMatch(r, l) | |
} | |
for (n in 1:length(l)) { | |
do.call('<-', list(l[[n]], r[[n]]), envir=Envir) | |
} | |
} | |
# Used if LHS is larger than RHS | |
extendToMatch <- function(source, destin) { | |
s <- length(source) | |
d <- length(destin) | |
# Assume that destin is a length when it is a single number and source is not | |
if(d==1 && s>1 && !is.null(as.numeric(destin))) | |
d <- destin | |
dif <- d - s | |
if (dif > 0) { | |
source <- rep(source, ceiling(d/s))[1:d] | |
} | |
return (source) | |
} | |
g = function(...) { | |
List = as.list(substitute(list(...)))[-1L] | |
class(List) = 'lbunch' | |
return(List) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment