[R] Weird behaviour function args in ellipses

Mario José Marques-Azevedo mariojmaaz at gmail.com
Fri Dec 11 18:40:51 CET 2015


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'?

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]]



More information about the R-help mailing list