Thaler,Thorn,LAUSANNE,Applied Mathematics
2013-Nov-04 09:54 UTC
[Rd] ggplot2: Add '+' operator for aes (uneval) objects
Dear all, Is there a reason, why there is no +-operator for aes (i.e. uneval) objects (as there is for themes and gg objects)? I had a couple of cases where such an operator would be useful, for instance to combine the result of aes and aes_string in functions. Any flaws with the following proposition: `+.uneval` <- function(e1, e2) { dup <- names(e1) %in% names(e2) if (any(dup)) { duplist <- paste(sQuote(names(e1)[dup]), collapse = ", ") msg <- sprintf(ngettext(length(dup), "element %s occurs in both summands - second one gets precedence", "elements %s occur in both summands - second one gets precedence"), duplist) warning(msg, domain = NA) } res <- c(e1[!dup], e2) class(res) <- "uneval" res } Any thoughts on that? Kind Regards, Thorn Thaler NRC Lausanne Applied Mathematics
Brian G. Peterson
2013-Nov-04 10:02 UTC
[Rd] ggplot2: Add '+' operator for aes (uneval) objects
This seems like a conversation to have with the package's maintainer (Hadley), as suggested by the posting guide: http://www.r-project.org/posting-guide.html "If the question relates to a contributed package , e.g., one downloaded from CRAN, try contacting the package maintainer first." and not R-devel. Regards, Brian On 11/04/2013 03:54 AM, Thaler,Thorn,LAUSANNE,Applied Mathematics wrote:> Dear all, > > Is there a reason, why there is no +-operator for aes (i.e. uneval) objects (as there is for themes and gg objects)? I had a couple of cases where such an operator would be useful, for instance to combine the result of aes and aes_string in functions. Any flaws with the following proposition: > > `+.uneval` <- function(e1, e2) { > dup <- names(e1) %in% names(e2) > if (any(dup)) { > duplist <- paste(sQuote(names(e1)[dup]), collapse = ", ") > msg <- sprintf(ngettext(length(dup), > "element %s occurs in both summands - second one gets precedence", > "elements %s occur in both summands - second one gets precedence"), > duplist) > warning(msg, domain = NA) > } > res <- c(e1[!dup], e2) > class(res) <- "uneval" > res > } > > Any thoughts on that? > > Kind Regards, > > Thorn Thaler > NRC Lausanne > Applied Mathematics