From murdoch at stats.uwo.ca  Tue Mar 20 11:47:21 2007
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Tue, 20 Mar 2007 06:47:21 -0400
Subject: [Rd] Symbol and Ellipsis problems
In-Reply-To: <5a7daaf70703200336i7889cf8ft8be3b145750fcdac@mail.gmail.com>
References: <5a7daaf70703200336i7889cf8ft8be3b145750fcdac@mail.gmail.com>
Message-ID: <45FFBBB9.5030902@stats.uwo.ca>

On 3/20/2007 6:36 AM, Thomas McCallum wrote:
> Hi Everyone,
> 
> When I have a load of functions which have various arguments passed
> via the ellipsis argument it keeps on assigning them as symbol making
> them unusable to the function.  My current work around involves using
> do.call but this is rather cumbersome.
> 
> Does anyone know why it suddenly changes the types to symbol and if
> there is a way to get the actual data pointed to by the symbol? (I
> have tried eval but that does not work and most functions just treat a
> symbol as a string).
> 
> ( An example which shows the type conversion is given below with the
> output - the key is the following "dataX=data" which makes the object
> data passed as a symbol and not the actual data).

match.call() doesn't evaluate the args, it just shows you the 
unevaluated call.  If you print your "extras" variable in your function, 
you'll see

$dataX
data

because you called the function with dataX=data.  If you'd called it as
x(dataY = 1+2) you'd see

1 + 2
[1] "language"

for the same reason.

If you want to evaluate the ... args, use list(...) instead of match.call.

Duncan Murdoch

> Many thanks
> 
> Tom
> 
> ====EXAMPLE CODE====
> data=c(1,2,3,4,5,6,7,8,9);
> 
> x <- function( ... ) {
>         args <- list();
>         extras <- match.call(expand.dots = FALSE)$...;
>         for( i in names(extras) ) {
>                 args[[ i ]] <- extras[[ i ]];
>                 print(args[[i]]);
>                 print(typeof(extras[[i]]));
>         }
> 
> 
> }
> 
> cat("TYPE OF DATA:");
> print(typeof(data));
> x(dataX=data);
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Symbol and Ellipsis problems
Duncan Murdoch