Dear list,

I know I have seen this discussed before but I haven't been successful
in searching for "ellipsis", "dots", "..." in the archives. I would
like to filter "..." arguments according to their name, and dispatch
them to two sub-functions, say fun1 and fun2. I looked at lm() but it
seemed more complicated than I need as it modifies the calling
function among other things. What is the best approach for this? My
current version presented below seems very awkward.

Best regards,

baptiste

sessionInfo()
R version 2.9.2 (2009-08-24)
i386-apple-darwin8.11.1

fun1 <- function(col, row){
  print(col)
  print(row)
}

fun2 <- function(x){
  print(x)
}

foo <- function(..., lty=1){

  dots <- list(...)

  cl <- match.call()

  col <- eval.parent(cl$col)
  row <- eval.parent(cl$row)

  params.fun1 <-  c("col", "row")

  removed <- na.omit(match(names(cl), params.fun1))
  # index whichever arguments were passed to fun1

  fun1(col, row)

  fun2(dots[seq_along(dots)[-removed]])

}

foo()
foo(col=1)
foo(col=1, row=1, g=2, test = "abc")

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to