From olafm at statistik.tu-dortmund.de  Sat Jul  3 00:14:13 2010
From: olafm at statistik.tu-dortmund.de (Olaf Mersmann)
Date: Sat, 3 Jul 2010 00:14:13 +0200
Subject: [Rd] Attributes of 1st argument in ...
In-Reply-To: <AANLkTinkSMoLfFm5MGQwA5AGSkVvEEZJhw0GbhKYZ4lB@mail.gmail.com>
References: <AANLkTinkSMoLfFm5MGQwA5AGSkVvEEZJhw0GbhKYZ4lB@mail.gmail.com>
Message-ID: <CD24596A-0B94-4A32-822D-98345DFC65D9@statistik.tu-dortmund.de>

Hi Daniel,

On 02.07.2010, at 23:26, Daniel Murphy wrote:
> I am trying to get an attribute of the first argument in a call to a
> function whose formal arguments consist of dots only and do something, e.g.,
> call 'cbind', based on the attribute
> f<- function(...) {get first attribute; maybe or maybe not call 'cbind'}
> 
> I thought of (ignoring "deparse.level" for the moment)
> 
> f<-function(...) {x <- attr(list(...)[[1L]], "foo"); if (x=="bar")
> cbind(...) else x}

what about using the somewhat obscure ..1 syntax? This version runs quite a bit faster for me:

  g <- function(...) {
    x <- attr(..1, "foo")
    if (x == "bar")
      cbind(...)
    else
      x
  }

but it will be hard to quantify how this pans out for your unless we know how many and what size and type the arguments are.

Cheers,
Olaf



[Rd] Attributes of 1st argument in ...
Olaf Mersmann