Skip to content
Prev 206393 / 398506 Next

advice/opinion on "<-" vs "=" in teaching R

G'day all,

On Fri, 15 Jan 2010 09:08:44 -0000 (GMT)
(Ted Harding) <Ted.Harding at manchester.ac.uk> wrote:

            
Depending on the definition of foo() more than two lines might be
necessary to clarify what this code is actually supposed to do. :)
Absolutely.
And a full discussion of these examples would include to warn about the
side effects of lazy evaluation:

R> rm(list=ls(all=TRUE))
R> foo <- function(x, y){
+   if(x > 0 ) x else x + y}
R> foo(2, x <- 10)
[1] 2
R> x
Error: object 'x' not found
R> foo(-2, x <- 10)
[1] 8
R> x
[1] 10

Having said this, I often use "plot(fm <- lm(y ~ . , somedata))".

And, yes, students have complained that the code I gave them was not
working, that they got a strange error message and they promised that
they had typed exactly what I had written on the lab sheet.  On
checking, they had, of course, typed "plot(fm = lm(y ~ . , somedata))"

Cheers,

	Berwin