One of my in-progress functions calls grep()
with value = TRUE
hard-coded. I\'d like to pass all of the further arguments except <
You can combine Curry
with do.call
:
require(functional)
f <- function(pattern, x, ...)
{
dots <- list(...)
dots <- dots[!grepl('value', names(dots))]
do.call(Curry(grep, pattern=pattern, x=x, value=TRUE), dots)
}
Curry
provides the known arguments, and dots
supplies everything other than "value" in ...
.
One way is to just make value a named parameter but ignore the input - that way it will never be a part of the dots to begin with.
f <- function(pattern, x, value = "hahaThisGetsIgnored", ...){
grep(pattern, x, value = TRUE, ...)
}
You can also use the idea in the answer @MatthewLundberg gave but by doing the argument manipulation without Curry so you don't need the functional package
f <- function(pattern, x, ...){
dots <- list(...)
# Remove value from the dots list if it is there
dots$value <- NULL
args <- c(list(pattern = pattern, x = x, value = TRUE), dots)
do.call(grep, args)
}