Skip to content
Prev 33635 / 398513 Next

right assignment ("->") and functions

You need an extra level of braces to resolve the ambiguity:
function(x) {x^2} -> f3
function(x) {x^2} -> f3

You need to do it as follows:
function(x) {x^2}


Of course the inner braces around the x^2 are not necessary, now.

Bill Venables. 

-----Original Message-----
From: Robin Hankin [mailto:r.hankin at auckland.ac.nz]
Sent: Monday, June 23, 2003 1:32 PM
To: r-help at stat.math.ethz.ch
Subject: [R] right assignment ("->") and functions


Hi everyone

check this out [R-1.7.0]:

R> f1 <- function(x){x^2}
R> f1 -> f2
R> f2(4)
[1] 16
R> 
R> function(x){x^2} -> f3
function(x){x^2} -> f3
R> f3(4)
Error: couldn't find function "f3"

Why does right assignment "->" work in the first but not the second
case?  Can anyone else reproduce this?