[R] matching last argument in function

From: Alistair Gee <alistair.gee_at_gmail.com>
Date: Tue, 12 Feb 2008 09:45:30 -0800


I often want to temporarily modify the options() options, e.g.

a <- seq(10000001, 10000001 + 10) # some wide object

with.options <- function(..., expr) {
  options0 <- options(...)
  tryCatch(expr, finally=options(options0)) }

Then I can use:

with.options(width=160, expr = print(a))

But I'd like to avoid explicitly naming the expr argument, as in:

with.options(width=160, print(a))

How can I do this with R's argument matching? (I prefer the expr as the last argument since it could be a long code block. Also, I'd like with.options to take multiple options.)

TIA



R-help_at_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. Received on Tue 12 Feb 2008 - 17:50:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 12 Feb 2008 - 22:30:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive