Happy 2013, Day 2.

I can't seem to figure out why parent.frame() works differently depending
on whether it is a formal/default argument or a passed argument.

##### code: basic setup ####

tmp <- tempfile()
A <- 101
save(A,file=tmp);rm(A)

# these work as expected, loading into the parent of the call load()
load(tmp);str(A);rm(A)
load(tmp, parent.frame());str(A);rm(A)
load(tmp, environment());str(A);rm(A)



# but these are odd, using local()

#     works
local( { load(tmp); str(A) } )

 #    FAILS even though env=parent.frame() by default !?!!
local( { load(tmp,env=parent.frame()); str(A) } )

#     works as well!
local( { load(tmp,env=environment()); str(A) } )

ls()            ## NOT in .GlobalEnv, correct!
args(load)  ## env=parent.frame() by default, but is it???


My question is why parent.frame() can't be specified in the args without
changing the behavior of the call itself if you aren't at the top level.

What am I missing?

Jeff


##### output #####

> tmp <- tempfile()
> A <- 101
> save(A,file=tmp);rm(A)
>
> # these work as expected, loading into the parent of the call load()
> load(tmp);str(A);rm(A)
 num 101
> load(tmp, parent.frame());str(A);rm(A)
 num 101
> load(tmp, environment());str(A);rm(A)
 num 101
>
>
>
> # but these are odd, using local()
>
> #     works
> local( { load(tmp); str(A) } )
 num 101
>
>  #    fails even though env=parent.frame() by default !?!!
> local( { load(tmp,env=parent.frame()); str(A) } )
Error in str(A) : object 'A' not found
>
> #     works as well!
> local( { load(tmp,env=environment()); str(A) } )
 num 101
>
> ls()            ## NOT in .GlobalEnv, correct!
[1] "tmp"
> args(load)  ## env=parent.frame() by default, but is it???
function (file, envir = parent.frame())
NULL
>

-- 
Jeffrey Ryan
jeffrey.ryan@lemnica.com

www.lemnica.com

	[[alternative HTML version deleted]]

