Skip to content

Instantly share code, notes, and snippets.

@DarwinAwardWinner
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarwinAwardWinner/f8c64c74527c2d7d94d3 to your computer and use it in GitHub Desktop.
Save DarwinAwardWinner/f8c64c74527c2d7d94d3 to your computer and use it in GitHub Desktop.
Wrong variable scope when callGeneric with dots argument is called by a generic that is called from another function
setGeneric("f1", signature=c("a"),
function(..., a) standardGeneric("f1"))
setMethod("f1", c(a="ANY"), function(..., a) list(a=a, ...))
setMethod("f1", c(a="missing"), function(..., a) callGeneric(a=1, ...))
f2 <- function(b,c,d, a) {
if (missing(a))
f1(b=b, c=c, d=d)
else
f1(a=a, b=b, c=c, d=d)
}
## Neither of these calls triggers the callGeneric
f1(2,3,4, a=1)
f2(2,3,4, a=1)
## This triggers the callGeneric, but doesn't trigger the bug because we are calling f1 directly
f1(2,3,4)
## This triggers the callGeneric with f2 calling f1, so it triggers the bug
f2(2,3,4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment