[R] How to make "<-" generic?

Patrick Burns pburns at pburns.seanet.com
Sat Jul 26 15:16:10 CEST 2003


I think Brian's question --- what are you trying to do? -- should
be the first order of business.

Someone can make R do just about anything, but it is better to
do a few things very well than lots of things in a muddled way.

So.  What is the advantage of using assignment as a generic?
I'm open-minded about there being such an advantage, but I
don't see any right off.

Patrick Burns

Burns Statistics
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")


Thomas Koenig wrote:

>Am Samstag, 26. Juli 2003 11:38 schrieb Peter Dalgaard BSA:
>  
>
>>Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> writes:
>>    
>>
>>>Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
>>>      
>>>
>>>>What are you trying to do with this?  Assignment (<-) is not a
>>>>function,
>>>>        
>>>>
>
>But what the difference between <- and e.g. the function length or "[<-"? As I 
>understood in "methods" everything has a class. And R says me with is(...) 
>(hope that the results are correct):
>< is(get("<-"))
>[1] "function"         "OptionalFunction" "PossibleMethod"
>< is(get("length"))
>[1] "function"         "OptionalFunction" "PossibleMethod"
>  
>
>>is(get("[<-"))
>>    
>>
>[1] "function"         "OptionalFunction" "PossibleMethod"
>  
>
>>## test for the correct result of get(...) ?
>>x <- 10
>>is(get("x"))
>>    
>>
>[1] "numeric" "vector"
>  
>
>>## and
>>setGeneric("<-")
>>    
>>
>[1] "<-"
>Warning message:
>"<-" is a primitive function; its generic definition is built in and 
>automatically included. in: setGeneric("<-")
>
>  
>
>>>>and the language grammar does not convert a <- b into "<-"(a,
>>>>b) (as it would with the binary operator functions).  You could call it
>>>>that way, and then it will probably work.
>>>>        
>>>>
>>>Eh? Are you sure about that???
>>>
>>>      
>>>
>>>>quote("<-"(a,b))
>>>>        
>>>>
>>>a <- b
>>>      
>>>
>>Adding on to this, I think the point is that assignment bypasses the
>>usual *evaluation* rules, even though it is syntactically a binop.
>>
>>I think it basically has to be so: For one thing, it is kind of
>>difficult to check for a signature match without evaluating the
>>arguments and the left hand side of an assignment will not in general
>>exist at that point.
>>    
>>
>
>In the methods is the class "missing". Could that help?
>for one thing : signature=c("missing","A") (only allowed for <- ?)
>for both things: signature=c("A","B")
>for nothing ;-) : signature=c("missing","missing")
>
>Thanks and Best Regards
>
>Thomas König
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>
>  
>




More information about the R-help mailing list