Skip to content

Instantly share code, notes, and snippets.

@nfultz
Created April 29, 2015 23:16
Show Gist options
  • Save nfultz/2809aa1d9df4540bfbcc to your computer and use it in GitHub Desktop.
Save nfultz/2809aa1d9df4540bfbcc to your computer and use it in GitHub Desktop.
generifying Rcssplot
#Taking a look at Rcssplot, seems nice enough.
#
#Wrappers feel inelegant though, especially building commands as strings then eval(parse())
#
#here is a potential solution:
#
# 1. Build call using substitute()
# 2. get copy of property list
# 3. delete any properties that are specified by user explicitly (in ...)
# 4. append the props to the call
# 5. eval
RcssGeneric <- function(...,
Rcss, Rcssclass, f) {
RcssCall <- substitute(f(...))
if(!missing(Rcss)){
css <- RcssGetProperties(Rcss, as.character(RcssCall[[1]]), Rcssclass = Rcssclass)
css[names(RcssCall)] <- NULL
if(length(css) > 0) {
i <- length(RcssCall) + seq_along(css)
RcssCall[i] <- css
names(RcssCall)[i] <- names(css)
}
}
eval(RcssCall, 1);
return();
}
# copy over the generic to the actual function and set the function
Rcsspoints <- RcssGeneric
formals(Rcsspoints)$f <- quote(points)
Rcssplot <- RcssGeneric
formals(Rcssplot)$f <- quote(plot)
### etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment