[R] Messing with the ... argument

2009-02-12 Thread Steve Lianoglou
Hi all,

Sorry if this is documented somewhere, but trying to search and google for 
ways to alter my ... argument is having me chasing my tail.

Is there someway that I can manipulate the elements in ...? 
Specifically I'd like to use certain vars in ..., then remove them 
from ... and pass the rest of ... to another function.

Here's a short example: I'm adding more functionality to a generic 
method by defining how it works on a new class MyClass:

setMethod('existingFunction', 'MyClass', function (object, ...) {
  vars - list(...)
  doSomethingWith(vars$myCustomVar)
  
  # now I want to pass the rest of the vars down to another function,
  # let's say some plotting function, so I'd like to remove
  # `myCustomVar` from ..., keep the rest of the vars and just
  # pass the valid ... elements down through the call chain
  
  doSomePlot(somethingSane, ...)
})

Currently the `doSomePlot` that's called does fine until it passes the
rest of it's vars to the real plot method, at which point I'll get
a warning like:

Warning messages:
1: In plot.window(...) : myCustomVar is not a graphical parameter
2: In plot.xy(xy, type, ...) : myCustomVar is not a graphical parameter
3: In axis(side = side, at = at, labels = labels, ...) :
  myCustomVar is not a graphical parameter
4: In axis(side = side, at = at, labels = labels, ...) :
  myCustomVar is not a graphical parameter
5: In box(...) : myCustomVar is not a graphical parameter
6: In title(...) : myCustomVar is not a graphical parameter

Depending on what the name of myCustomVar is, this can work even with
the warnings, which is passable. It might also bail if myCustomVar
happens to share a name with a real plotting var, but has an illegal
value for it.

Anyway, while there are ways it can work in this case, I'm just wondering
if I can remove elements from ... and side-step these warning/error issues
altogether.

Since vars - list(...) works to create a list of arguments from ...,
I'm guessing there must be a way to take an already existing list variable
and turn its name/value pairs into an appropriate ... object?

Thanks for any help,
-steve

__
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.


Re: [R] Messing with the ... argument

2009-02-12 Thread Duncan Murdoch

On 2/12/2009 2:34 PM, Steve Lianoglou wrote:

Hi all,

Sorry if this is documented somewhere, but trying to search and google for 
ways to alter my ... argument is having me chasing my tail.


Is there someway that I can manipulate the elements in ...? 
Specifically I'd like to use certain vars in ..., then remove them 
from ... and pass the rest of ... to another function.


Here's a short example: I'm adding more functionality to a generic 
method by defining how it works on a new class MyClass:


setMethod('existingFunction', 'MyClass', function (object, ...) {
  vars - list(...)
  doSomethingWith(vars$myCustomVar)
  
  # now I want to pass the rest of the vars down to another function,

  # let's say some plotting function, so I'd like to remove
  # `myCustomVar` from ..., keep the rest of the vars and just
  # pass the valid ... elements down through the call chain
  
  doSomePlot(somethingSane, ...)

})

Currently the `doSomePlot` that's called does fine until it passes the
rest of it's vars to the real plot method, at which point I'll get
a warning like:

Warning messages:
1: In plot.window(...) : myCustomVar is not a graphical parameter
2: In plot.xy(xy, type, ...) : myCustomVar is not a graphical parameter
3: In axis(side = side, at = at, labels = labels, ...) :
  myCustomVar is not a graphical parameter
4: In axis(side = side, at = at, labels = labels, ...) :
  myCustomVar is not a graphical parameter
5: In box(...) : myCustomVar is not a graphical parameter
6: In title(...) : myCustomVar is not a graphical parameter

Depending on what the name of myCustomVar is, this can work even with
the warnings, which is passable. It might also bail if myCustomVar
happens to share a name with a real plotting var, but has an illegal
value for it.

Anyway, while there are ways it can work in this case, I'm just wondering
if I can remove elements from ... and side-step these warning/error issues
altogether.

Since vars - list(...) works to create a list of arguments from ...,
I'm guessing there must be a way to take an already existing list variable
and turn its name/value pairs into an appropriate ... object?


I don't think so, but an alternative is to put together a parameter list 
and call do.call().  For example,


 g - function(...) {
+list(...)# just return the arg list to see what arrived
+ }

 f - function(...) {
+all - list(...)
+all[nothanks] - NULL
+do.call(g, all)
+ }

 g(nothanks=1, yesplease=2)
$nothanks
[1] 1

$yesplease
[1] 2

 f(nothanks=1, yesplease=2)
$yesplease
[1] 2

Duncan Murdoch

__
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.


Re: [R] Messing with the ... argument

2009-02-12 Thread Steve Lianoglou
Hi Duncan,

 ...
 I don't think so, but an alternative is to put together a parameter list 
 and call do.call().  For example,
 ...

Nice!

Yeah, that did the trick quite well ... 

Thanks,
-steve

__
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.


Re: [R] Messing with the ... argument

2009-02-12 Thread Wacek Kusnierczyk
here's an example which may give you a hint -- it is not supposed to
solve your particular problem:

f = function(...)
list(...)
g = function(...) {
args = list(...)
names = names(args)
if (is.null(names))
   f(...)
else
do.call(f, args[names(args) != 'foo']) }

g()
# list()
g(1)
# list(1)
g(a=1)
# list(a=1)
g(a=1, foo=2)
# list(a=1)
g(1, foo=2)
# list(1)
g(foo=1)
# list()

consider using grep for finding the variables to be removed.

vQ


Steve Lianoglou wrote:
 Hi all,

 Sorry if this is documented somewhere, but trying to search and google for 
 ways to alter my ... argument is having me chasing my tail.

 Is there someway that I can manipulate the elements in ...? 
 Specifically I'd like to use certain vars in ..., then remove them 
 from ... and pass the rest of ... to another function.

 Here's a short example: I'm adding more functionality to a generic 
 method by defining how it works on a new class MyClass:

 setMethod('existingFunction', 'MyClass', function (object, ...) {
   vars - list(...)
   doSomethingWith(vars$myCustomVar)
   
   # now I want to pass the rest of the vars down to another function,
   # let's say some plotting function, so I'd like to remove
   # `myCustomVar` from ..., keep the rest of the vars and just
   # pass the valid ... elements down through the call chain
   
   doSomePlot(somethingSane, ...)
 })

 Currently the `doSomePlot` that's called does fine until it passes the
 rest of it's vars to the real plot method, at which point I'll get
 a warning like:

 Warning messages:
 1: In plot.window(...) : myCustomVar is not a graphical parameter
 2: In plot.xy(xy, type, ...) : myCustomVar is not a graphical parameter
 3: In axis(side = side, at = at, labels = labels, ...) :
   myCustomVar is not a graphical parameter
 4: In axis(side = side, at = at, labels = labels, ...) :
   myCustomVar is not a graphical parameter
 5: In box(...) : myCustomVar is not a graphical parameter
 6: In title(...) : myCustomVar is not a graphical parameter

 Depending on what the name of myCustomVar is, this can work even with
 the warnings, which is passable. It might also bail if myCustomVar
 happens to share a name with a real plotting var, but has an illegal
 value for it.

 Anyway, while there are ways it can work in this case, I'm just wondering
 if I can remove elements from ... and side-step these warning/error issues
 altogether.

 Since vars - list(...) works to create a list of arguments from ...,
 I'm guessing there must be a way to take an already existing list variable
 and turn its name/value pairs into an appropriate ... object?

 Thanks for any help,
 -steve

 __
 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

__
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.