similar to: help with eval

Displaying 20 results from an estimated 10000 matches similar to: "help with eval"

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 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 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,
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 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 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,
2004 Nov 18
5
Lexical Scoping: eval(expr,envir=)
Hi R-listers, I am trying to better undertand what we would call "functional paradigm" use of S/R to better map my programming activities in other languages. This little function is aimed to create an object (at the end end, it would have it's own class): -- myObject =function(){ list( a=1, foo=function(b) { cat("b:",b)
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?
2017 May 09
3
R-3.3.3/R-3.4.0 change in sys.call(sys.parent())
Some formula methods for S3 generic functions use the idiom returnValue$call <- sys.call(sys.parent()) to show how to recreate the returned object or to use as a label on a plot. It is often followed by returnValue$call[[1]] <- quote(myName) E.g., I see it in packages "latticeExtra" and "leaps", and I suspect it used in "lattice" as well. This idiom
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 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
2005 Sep 13
1
possible bug in model.matrix
Is this a bug, or have I misunderstood the proper use of lm? Thanks, Whit code: x <- rnorm(50) y <- matrix(as.logical(round(runif(100),0)),ncol=2) NROW(x)==NROW(y) lm(x~y) > x <- rnorm(50) > y <- matrix(as.logical(round(runif(100),0)),ncol=2) > NROW(x)==NROW(y) [1] TRUE > lm(x~y) Error in "[[<-.data.frame"(`*tmp*`, nn, value = c(2, 1, 2, 1, 1, 1, 2, :
2008 May 13
8
static private and multi-inherit
/*author:csf178-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org*/ function Class(Initalizer,SuperClasses) { if(!SuperClasses)SuperClasses=[]; var ret=function(){ for(var i=0;i<SuperClasses.length;i++) { SuperClasses[i].call(this); } var $private={}; var $public=this; var $static=ret; with($static){ with($private){ with($public){
2012 Apr 12
1
deferred call
I must admit I'm a little ashamed to have been using R for so long, and still lack a sound understanding of deferred calls, eval, deparse, substitute, and friends. I'm attempting to make a deferred call to a function which has default arguments in the following way: call.foo <- function(f) { x <- f() } x <- 1:10 f <- function(x=x) { x^2 } call.foo(f) However, I'm
2016 Oct 27
1
using with inside loop breaks next
If I want to use with inside a loop, it seems that next gets confused. To reproduce: for(lst in list(list(a = 1), list(a = 2), list(a = 3))) { with(lst, if(a == 2) next else print(a)) } I expect 1 and 3 to be printed, but I see [1] 1 Error in eval(expr, envir, enclos) : no loop for break/next, jumping to top level Is this a) by design, or b) a bug, or c) a thing that is rare enough that I
2009 Mar 31
4
what is the preferred method to create a package local variable?
for the moment, I'm using: .onAttach <- function(libname, pkgname) { .bbg.db.conn <<- dbConnect(dbDriver("PostgreSQL"), user="blah","blah") } .onUnload <- function(libpath) { dbDisconnect(.bbg.db.conn) } which results in a hidden global variable in the global environment. I would prefer to make the assignment only in the package namespace.
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 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
2011 Nov 24
1
capture.output(eval(..., envir)) not evaluate in the expected(?) environment
I've noticed the following oddity where capture.output() prevents eval() from evaluating an expression in the specified environment. I'm not sure if it is an undocumented feature or a bug. It caused me many hours of troubleshooting. By posting it here, it might save someone else from doing the same exercise. Start by defining foo() which evaluates an expression locally in a given