[R] Problem with environments

Thomas L Jones, PhD jones3745 at verizon.net
Fri Nov 23 04:38:11 CET 2007


I have a numeric vector of length 1. I am trying to use it inside
a function just by giving its name, rather than specifying it as
an argument to the function. I am aware that there is an attach
function which you need to call. The attach function will accept a
list. However, I don't seem to be able to create the list properly. (Or 
should I use a frame instead?)

Anyway, here is the output, starting with the load operation;

----------------------------------------------------------------------------

> # function bar_driver
>
> free_driver <- function (){
+ i <- 25
+ attach_list <- list (i = i)
+ print1 ("attach_list = ", attach_list)
+ attach (attach_list)
+ free_test ()
+
+ }
> free_test <- function (){
+ print ("entering free_test")
+ print1 ("i")
+ return ()
+
+ }
>

[1] "attach_list = "
$i
[1] 25


        The following object(s) are masked _by_ .GlobalEnv :

         i

[1] "entering free_test"
[1] "i"
Error in print(value) : argument "value" is missing, with no default
>
---------------------------------------------------------------------

>From Tom:

Question 1: Is the idea of using such a variable viable at all? In some 
communities, it would be called a "free variable."
Question 2: Is the list correct? If not, how does one build it correctly?
Question 3: How do you tell it NOT to mask the variable i by .GlobalEnv, 
whatever that is?

Your advice?

Tom Jones
Thomas L. Jones, PhD, Computer Science



More information about the R-help mailing list