Displaying 20 results from an estimated 90000 matches similar to: "evaluation revisited"
2020 Jun 01
1
eval and Calling Frames
I ran into an interesting issue with `evalq` (and also
`eval(quote(...))`):
???? f <- function() {
?????? list(
???????? sys.parent(1),
???????? evalq(sys.parent(1)),
???????? evalq((function() sys.parent(2))()),? # add an anon fun layer
???????? evalq((function() sys.parent(1))())
?????? )
???? }
???? res <- f()
???? str(res)
???? ## List of 4
???? ##? $ : int 0???????? # sys.parent(1)
2015 Apr 01
4
evaluation in transform versus within
On 01/04/2015 1:35 PM, Gabriel Becker wrote:
> Joris,
>
>
> The second argument to evalq is envir, so that line says, roughly, "call
> environment() to generate me a new environment within the environment
> defined by data".
I think that's not quite right. environment() returns the current
environment, it doesn't create a new one. It is evalq() that created
2015 Apr 01
1
evaluation in transform versus within
On 01/04/2015 2:33 PM, Joris Meys wrote:
> Thank you for the insights. I understood as much from the code, but I
> can't really see how this can cause a problem when using with() or
> within() within a package or a function. The environments behave like
> I would expect, as does the evaluation of the arguments. The second
> argument is supposed to be an expression, so I
2002 Sep 04
3
strange things with eval and parent frames
Dear mailing list,
I have found some strange behaviour which I think relates to parent frames
and eval. Can anyone explain what's going on here?
First example:
> test.parent.funcs_ function() {
outer.var_ 5
subfunc1_ function() substitute( outer.var, envir=parent.frame())
print( subfunc1())
subfunc2b_ function() eval( quote( outer.var), envir=parent.frame())
print(
2015 Apr 01
2
evaluation in transform versus within
Dear list members,
I'm a bit confused about the evaluation of expressions using with() or
within() versus subset() and transform(). I always teach my students to use
with() and within() because of the warning mentioned in the helppages of
subset() and transform(). Both functions use nonstandard evaluation and are
to be used only interactively.
I've never seen that warning on the help
2007 May 27
2
Question about "evalq"
The help page of eval says: The 'evalq' form is equivalent to
'eval(quote(expr), ...)'. But the following is not equivalent. Can
anyone give me some explaination? Thanks very much.
> f1 <- function(x,digits=5) lapply(x, f2)
> f2 <- function(x) eval(quote(print(x+1,digits=digits)),list(x=x),parent.frame(2))
> f1(list(x1=1))
[1] 2
$x1
[1] 2
>
> f1 <-
2015 Jul 15
2
bquote/evalq behavior changed in R-3.2.1
On Jul 15, 2015, at 12:51 PM, William Dunlap wrote:
> I think rapply() was changed to act like lapply() in this respect.
>
When I looked at the source of the difference, it was that typeof() returned 'language' in 3.2.1, while it returned 'list' in the earlier version of R. The first check in rapply's code in both version was:
if (typeof(object) != "list")
2015 Jul 15
2
bquote/evalq behavior changed in R-3.2.1
David,
If you are referring to the solution that would be:
rapply(list(test), eval, envir = fenv)
I thought I explained in the question that the above code does not work. It
does not throw an error, but the behavior is no different (at least in the
output or result). Using the above code still results in the x object not
being stored in fenv on 3.1.2.
Dayne
On Wed, Jul 15, 2015 at 4:40 PM,
2010 Jan 07
1
question on 'within' and 'parse' commands
Hi,
Why can't I pass an expression to `within' by way of textual input to
the 'parse' function?
e.g.,
> x <- data.frame(a=1:5,b=LETTERS[1:5])
> x
a b
1 1 A
2 2 B
3 3 C
4 4 D
5 5 E
> within(x, parse(text="a<-a*10; b<-2:6"))
a b
1 1 A
2 2 B
3 3 C
4 4 D
5 5 E
> within(x, parse(text="a<-a*10; b<-2:6")[[1]])
a b
1 1 A
2 2 B
3
2007 Jun 08
1
evaluating variables in the context of a data frame
Given
> D = data.frame(o=gl(2,1,4))
this works as I expected:
> evalq(o, D)
[1] 1 2 1 2
Levels: 1 2
but neither of these does:
> f <- function(x, dat) evalq(x, dat)
> f(o, D)
Error in eval(expr, envir, enclos) : object "o" not found
> g <- function(x, dat) eval(x, dat)
> g(o, D)
Error in eval(x, dat) : object "o" not found
What am I doing wrong?
2015 Jul 15
3
bquote/evalq behavior changed in R-3.2.1
In 3.1.2 eval does not store the result of the bquote-generated call in the
given environment. Interestingly, in 3.2.1 eval does store the result of
the bquote-generated call in the given environment.
In other words if I run the given example with eval rather than evalq, on
3.1.2 "x" is never stored in "fenv," but it is when I run the same code on
3.2.1. However, the given
2015 Feb 09
1
WISH: eval() to preserve the "visibility" (now value is always visible)
Sorry to intervene.
Argument passed to 'eval' is evaluated first.
So,
eval(x <- 2)
is effectively like
{ x <- 2; eval(2) } ,
which is effectively
{ x <- 2; 2 } .
The result is visible.
eval(expression(x <- 2))
or
eval(quote(x <- 2))
or
evalq(x <- 2)
gives the same effect as
x <- 2 .
The result is invisible.
In function 'eval2',
res <-
2015 Apr 01
0
evaluation in transform versus within
Thank you for the insights. I understood as much from the code, but I can't
really see how this can cause a problem when using with() or within()
within a package or a function. The environments behave like I would
expect, as does the evaluation of the arguments. The second argument is
supposed to be an expression, so I would expect that expression to be
evaluated in the data frame first.
I
2015 Jul 15
3
bquote/evalq behavior changed in R-3.2.1
Hello,
I upgraded from 3.1.2 to 3.2.1 and am receiving errors on code that worked
as I intended previously. Briefly, I am using bquote to generate
expressions to modify data.table objects within a function, so I need the
changes to actually be stored in the given environment. Previously, I used
code like the following:
test <- list(bquote(x <- 10))
fenv <- environment()
rapply(test,
2005 Jun 29
1
Failed "make check" under Fedora Core 4 (PR#7979)
I downloaded R v2.1.1 earlier this morning to compile under Fedora Core
4. It compiled without incident, but 'make check' failed. Below is the
relevant part of its report. Is this a known problem?
I used a locally compiled version of GCC v4.0.0 that reports
[kent at d89h102 R-2.1.1]$ gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.0.0/configure
2015 Apr 01
0
evaluation in transform versus within
Joris,
The second argument to evalq is envir, so that line says, roughly, "call
environment() to generate me a new environment within the environment
defined by data".
Note that that is is only generating e, the environment that expr will be
evaluated within in the next line (the call to eval). This means that expr
is evaluated in an environment which is inside the environment defined
2005 May 14
2
help with eval
I've been looking at the help page for eval for a while, but I can't
make sense of why this example does not work.
show.a <- function() {
a
}
init.env <- function() {
a <- 200
environment()
}
my.env <- init.env()
ls(envir=my.env)
# returns this:
# > ls(envir=my.env)
# [1] "a"
# but this does not work:
eval(expression(show.a()),envir=my.env)
# >
2001 Oct 16
4
Assignment of structures on a given environment
Hi,
In order to avoid deep copies by passing large arguments to functions or
returning values, I'm trying to do the assignment of variables in a
given environment. The problem is when I try to assign a structure: a
list for example.
If I have:
ind <- c("a","b")
my idea is doing something like
l <- alist()
l[ind] <- as.list(c(20,40))
in a given
2011 Apr 09
2
best practice(s) for retrieving a local variable from a closure
Greetings,
Say I have defined
mp <- function(a) function(x) x^a
f2 <- mp(2)
and I would like to retrieve the "a" which is local to f2. Two options
come to mind;
get("a", envir=environment(f2))
eval(substitute(a), environment(f2))
I'm curious if one of these is preferred over the other in terms of
efficiency, robustness, aesthetics, etc. Or perhaps
2015 Jan 14
2
Is the tcltk failure in affylmGUI related to R bug 15957
I maintain the package affylmGUI. It works when installed on many
previous versions of R. I have today tested exactly the same code under
R-2.15.3, R-3.0.2, R-3.1.0, R-3.1.1, R-3.1.2 and R-devel.
I have also tested the versions of affylmGUI downloaded by biocLite for
each version of R and the same result applies.
I have no errors under 2.15.3, 3.0.2, 3.1.0 and 3.1.1. The following
error