Skip to content

Instantly share code, notes, and snippets.

@daattali
Created May 20, 2015 10:10
Show Gist options
  • Save daattali/eb73d25ac5670b4fe996 to your computer and use it in GitHub Desktop.
Save daattali/eb73d25ac5670b4fe996 to your computer and use it in GitHub Desktop.
# Suppose a function has an argument "x". If a "child function" has multiple
# argument beginning with "x" and I want to pass the param "x" to its parent,
# I get error: `argument n matches multiple formal arguments`
# The reason this happens is clear, but at 3am my brain is firing blanks
# trying to find a solution. Help!
library(magrittr)
foo <- function(x, ...) UseMethod("foo")
foo.parent <- function(x, n = 5, ...) n
foo.child <- function(x, n1 = 1, n2 = 2, ...) NextMethod("foo") + n1
structure("", class = c("child", "parent")) %>% foo(n1 = 9) # this is ok
structure("", class = c("child", "parent")) %>% foo(n = 9) # this is not
# How do I pass "n" to foo.parent?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment