I've made a package with a function that asks for 3 values, like so:
example.foo("directory",vA1,vA2)
Now, I want to set a default value for both vA1 and vA2. I wrote the following piece of code, but I don't know why it ain't working
if (!exists("vA1")) {
vA1 = 2
}
2 being the default value for vA1. When I run the package I get an "argument "vA1" missing, with no default". How do I set the default for this function? Thanks!
As Pascal points out, defaults to functions are provided by providing named arguments. For instance:
fun <- function(x="Hello World") print(x)
fun()
[1] "Hello World"
fun("and good bye")
[1] "and good bye"
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