Displaying 20 results from an estimated 1000 matches similar to: "eval and Calling Frames"
2020 Feb 26
1
Profiling: attributing costs to place of invocation (instead of place of evaluation)?
Hi
Consider the following example:
f <- function(expr) g(expr)
g <- function(expr) {
? h(expr)
}
h <- function(expr) {
? expr # evaluation happens here
? i(expr)
}
i <- function(expr) {
? expr # already evaluated, no costs here
? invisible()
}
rprof <- tempfile()
Rprof(rprof)
f(replicate(1e2, sample.int(1e4)))
Rprof(NULL)
cat(readLines(rprof), sep = "\n")
#>
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 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,
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
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
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,
2009 Jan 28
1
evaluation revisited
I'm still going over old emails and trying to get my head around
evaluation so I'm persistent if nothing else.
A while back , an expert sent me below as an exercise in understanding
and I only got around to it tonight. I understand some of the output but
not all of it and I put "Why not Zero ?" next to the ones that I don't
understand based on my reading of the various
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
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 <-
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?
2007 May 18
1
subset arg in (modified) evalq
Hi,
When using evalq to evaluate expressions within a say data.frame context I often wish there was a 'subset' argument, much like in lm() or any ather advanced regression model. I would be grateful for a tip how to do this.
Here is an illustration of what I want:
n <- 100
data <- data.frame(x=rnorm(n), y=rnorm(y), z=rnorm(z))
# this works
evalq({ i <- 0<x;
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
2017 Jun 27
0
Seg Fault memory violation
Greetings all,
Recently ran into a seg fault the keeps reoccurring whenever R-java is used (I believe). Not sure if this is an R issue or an openjdk issue so I'm trying to cover all bases with this report. I tried downgrading R version from 3.4.0 to 3.3.3 with the same results. Also tried downgrading java version from 1.8 to 1.7 with no luck. Running on a fully updated CentOS 7 x86_64,
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
2015 Jan 26
2
Inspect a "delayed" assigned whose value throws an error?
On Mon, Jan 26, 2015 at 12:24 PM, Hadley Wickham <h.wickham at gmail.com> wrote:
> If it was any other environment than the global, you could use substitute:
>
> e <- new.env()
> delayedAssign("foo", stop("Hey!"), assign.env = e)
> substitute(foo, e)
>
> delayedAssign("foo", stop("Hey!"))
> substitute(foo)
Hmm... interesting
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
2011 Mar 10
2
Create an environment and assign objects to it in one go?
Hi,
I've just created:
newEnvEval <- function(..., hash=FALSE, parent=parent.frame(), size=29L) {
envir <- new.env(hash=hash, parent=parent, size=size);
evalq(..., envir=envir);
envir;
} # newEnvEval()
so that I can create an environment and assign objects to it in one go, e.g.
env <- newEnvEval({ a <- 1; b <- 2; });
print(env$a);
Does this already exists somewhere?
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
2018 Aug 06
2
SIGSEGV in R_RunWeakRefFinalizer, object allocated with Rcpp
Hi all,
I'm not sure if I'm not supposed to do the following (the dyn.unload
part, I mean) or this could be a bug (in R or Rcpp):
```
Rcpp::sourceCpp(code='
#include <Rcpp.h>
class Object {};
//[[Rcpp::export]]
SEXP new_object() {
return Rcpp::XPtr<Object>(new Object());
}'
)
new_object()
dyn.unload(list.files(tempdir(), ".(so|dll)$",