On 11/12/2015 12:40 PM, Mario José Marques-Azevedo wrote:
Dears,
I'm having a weird behaviours when setting arguments in functions.
fn <- function(x, st="mean", b=NULL, col.range="black", ...){
dots <- list(...)
cat("col.range =", col.range, "\n")
cat("dots =\n")
print(dots)
}
fn(1, b=2,col="red")
# Output
col.range = red
dots =
list()
Why 'col' arguments are not in ellipses, but setting col.range to 'red'?
See the R Language Definition manual, section 4.3.2. Partial matching
is used on arguments that precede ... in the function definition, exact
matching on arguments that follow it.
Duncan Murdoch
If I change the position of ellipses
fn2 <- function(x, ..., st="mean", b=NULL, col.range="black"){
dots <- list(...)
cat("col.range =", col.range, "\n")
cat("dots =\n")
print(dots)
}
fn2(1, b=2, col="red")
# Output
col.range = black
dots =
$col
[1] "red"
It works! I'm using R version 3.2.2.
Best regards!
Mario
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.