[R] Function Value Not Being Overwritten?

Jason Rupert jasonkrupert at yahoo.com
Fri Nov 6 23:43:25 CET 2009


Part of my problem is that I am in the middle of starting to use functions, so this was unexpected behavior for me.  Maybe there is a work-around because I like declaring some of the variables prior to using them.   

I have two separate files: 

# File: Test.R
dog<-function(x)
{
    templeton<-NULL
    source("Cat.R")
    print(templeton)
    print(x)
    
    print(bobby)
}




# File Cat.R
templeton<-c(7)
bobby<-c("This", "is", "a", "test.")



Now running the function in the RGui...
> source("Test.R")
> dog(13)
NULL
[1] 13
[1] "This"  "is"    "a"     "test."


My question is why is "templeton" equal to NULL?  

I expected "templeton" to be equal to "7".  Notice that bobby came across fine. 

Is there anyway for the value of "templeton" set in Cat.R to come across successfully? 

Thanks for any feedback and insights. 







More information about the R-help mailing list