From jarle.tufto at math.ntnu.no  Fri Jan 16 11:12:31 2004
From: jarle.tufto at math.ntnu.no (jarle.tufto@math.ntnu.no)
Date: Fri Jan 16 11:11:02 2004
Subject: [Rd] local variables (PR#6436)
Message-ID: <20040116101231.65936104B9@slim.kubism.ku.dk>

It seems that R (unlike S-plus) allows assignments to elements of a 
vector objects even when the object do not exists locally (inside a 
fucntion) in cases where an object of the same name exists globally.  I 
guess this is not really desired behaviour:


R v1.8.0
 > a
Error: Object "a" not found
 > testfunc <- function() {a[1]<-1; a}
 > testfunc()
Error in testfunc() : Object "a" not found
 > a<-2
 > testfunc()
[1] 1
 > a
[1] 2


S-plus v6.0
 > a
Problem: Object "a" not found
 > testfunc <- function() {a[1]<-1; a}
 > testfunc()
Problem in testfunc(): Object "a" not found
Use traceback() to see the call stack
 > a <- 2
 > testfunc()
Problem in testfunc(): object "a" must be assigned locally before 
replacement
Use traceback() to see the call stack


[Rd] local variables (PR#6436)
jarle.tufto@math.ntnu.no