[R] Scoping problem?

rijn@swi.psy.uva.nl rijn at swi.psy.uva.nl
Thu Jul 6 14:51:19 CEST 2000

I have to admit, I'm not too familiar with all the scoping issues in R.
Luckily, I managed to write scripts/functions that didn't touch the hairy
scoping details. However, in a couple of functions I'm writing now, I think
I stumbled upon a problem related to scoping.

To demonstrate, the following code results in a "Error in paste("png::",
filename, sep = "") : Object "fn" not found" error. 

plot.and.save <- function(s) {
  plot(1:s,main="Just a demo")
  fn <- paste("filename-with-variable",s,".png",sep="")

If fn is defined in the "global scope", the function does not complain
about undefined variables. However, in the scripts I'm writing, I would
like to be able to construct the filename "online". Can anyone suggest a
solution to, or explain how I should approach this problem?


P.S. I'm using the following version of R:

> version
platform i686-pc-linux-gnu
arch     i686             
os       linux-gnu        
system   i686, linux-gnu  
major    1                
minor    1.0              
year     2000             
month    June             
day      15               
language R                

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list