Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# 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!
foo <- function(x, ...) UseMethod("foo")
foo.parent <- function(x, n = 5, ...) n
foo.child <- function(x, ..., n1 = 1, n2 = 2) NextMethod("foo", list(...)) + 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