Re: [R] eval using a environment X but resultsin .GlobalEnv

2009-01-05 Thread Duncan Murdoch

Saptarshi Guha wrote:

Hello,
Suppose I have an expression, E, which accesses some variables present
in an environment V.
I do this via
eval(E,envir=V)
however all assignments end up in V. I would like the results of
assignments in E to end up in the .GlobalEnv ? Or at least the calling
environment.
Is there a quick way to this instead of iterating over all objects  E
and assigning into .GlobalEnv?


If you don't have control of E to make the changes Gabor suggested, then 
I don't think you can do it without iteration.  But you can leave V 
alone as follows:


V2 <- new.env(parent=V)
eval(E, envir=V2)   # Assignments happen in V2

Now iterate over V2 to move things into .GlobalEnv if you want, e.g.

names <- ls(V2, all=TRUE)
for (n in names) assign(n, get(n, envir=V2))

Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] eval using a environment X but resultsin .GlobalEnv

2009-01-04 Thread Gabor Grothendieck
Try this:

.GlobalEnv$x <- 3

Also

x <<- 3

will work if there is no x between V and the global environment but if
there is then that one will get set rather than the one in the global
environment.

On Mon, Jan 5, 2009 at 1:52 AM, Saptarshi Guha  wrote:
> Hello,
> Suppose I have an expression, E, which accesses some variables present
> in an environment V.
> I do this via
> eval(E,envir=V)
> however all assignments end up in V. I would like the results of
> assignments in E to end up in the .GlobalEnv ? Or at least the calling
> environment.
> Is there a quick way to this instead of iterating over all objects  E
> and assigning into .GlobalEnv?
>
> Thank you
> Saptarshi
>
>
> --
> Saptarshi Guha - saptarshi.g...@gmail.com
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] eval using a environment X but resultsin .GlobalEnv

2009-01-04 Thread Saptarshi Guha
Hello,
Suppose I have an expression, E, which accesses some variables present
in an environment V.
I do this via
eval(E,envir=V)
however all assignments end up in V. I would like the results of
assignments in E to end up in the .GlobalEnv ? Or at least the calling
environment.
Is there a quick way to this instead of iterating over all objects  E
and assigning into .GlobalEnv?

Thank you
Saptarshi


-- 
Saptarshi Guha - saptarshi.g...@gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.