[R] Confusion regarding environments invoked by "source" command
fisher at plessthan.com
Mon Mar 23 23:06:29 CET 2009
R version 2.8.1 in OS X
Within a function (which is already within a function), I am sourcing
a file. The syntax of the command is something like (this is just an
example; the actual code is much more complicated):
BIGFUNCTION <- function()
DATAFRAME <- [some commands to create a dataframe]
MYFUNCTION <- function(DATAFRAME)
The file "myfile" contains the following:
When I execute BIGFUNCTION from the command line, R reports:
Error in print(DATAFRAME) : object "DATAFRAME" not found
Calls: BIGFUNCTION ... source -> eval.with.vis -> eval.with.vis ->
print -> head
However, the "print(ls())" command has just listed the existence of
DATAFRAME and "exists(DATAFRAME) return TRUE
So, I am at a loss as to why ls() and "exists" see the object but
print(DATAFRAME) command does not.
I tried "local=F" in the source command to no avail.
I also replaced "print(DATAFRAME)" with "print(str(DATAFRAME))" with
the same outcome.
I assume that this is an error as to how I am managing environments
but I cannot figure out a solution. Any help would be appreciated.
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
More information about the R-help