I have a function foo that takes one argument and has a default parameter
foo <- function(b = 2) b
I want to call this function from another function bar.
bar <- function(a, b = NULL){
a * foo(b = ???)
}
b is provided in bar I want to call foo with this parameterfoo with its default parameter.How can I do that?
(I couldn't find a good title for this question, so please change it if you know a better one.)
You can use the ... argument:
foo <- function(b = 2) b
bar <- function(a, ...) {
a * foo(...)
}
bar(a=5)
bar(3, b=3)
bar(3, 7)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With