search for: delayedassign

Displaying 20 results from an estimated 46 matches for "delayedassign".

2012 Apr 25
4
delayedAssign changing values
I'm not sure if this is a known peculiarity or a bug, but I stumbled across what I think is very odd behavior from delayedAssign. In the below example x switches values the first two times it is evaluated. > delayedAssign("x", {x <- 2; x+3}) > x==x [1] FALSE > delayedAssign("x", {x <- 2; x+3}) > x [1] 5 > x [1] 2 The ?delayedAssign documentation says that "after [evaluation],...
2012 Apr 29
1
A doubt about substitute() after delayedAssign()
Hello, ?delayedAssign presents substitute() as a way to look at the expression in the promise. However, msg <- "old" delayedAssign("x", msg) msg <- "new!" x #- new! substitute(x) #- x (was 'msg' ?) Here, we just got 'x'... shouldn't we got 'msg'? Same r...
2013 May 16
3
Substitute / delayedAssign (was: Substitute unaware when promise objects are evaluated)
Duncan, Thank you for the clarification on how delayedAssign works. Should R-level interfaces to promise objects ever become available, I expect they would at time come in handy. On the subject of substitute and delayedAssign, I do have a follow-up question for the list. I'm trying to convert a named list of expression objects into an environment of pro...
2007 Feb 13
1
question on docs for delayedAssign and substitute
The help files for delayedAssign and substitute both say that substitute() can be used to see the expression associated with a promise. However, I can't see how to do that. When I try the example in help file for delayedAssign I don't see substitute() extracting the promise, e.g.: > msg <- "old" &g...
2006 May 19
2
delayedAssign and interrupts
I noticed something recently that I thought was odd: delayedAssign("x", { Sys.sleep(5); 1 }) x ## Hit Ctrl-C within the first second or 2 gives me: > delayedAssign("x", { Sys.sleep(5); 1 }) > x ## Hit Ctrl-C within the first second or two > x Error: recursive default argument reference > My only problem here is that now I&...
2011 May 02
2
Using substitute to access the expression related to a promise
Hi all, The help for delayedAssign suggests that you can use substitute to access the expression associated with a promise, and the help for substitute says: "If it is a promise object, i.e., a formal argument to a function or explicitly created using ?delayedAssign()?, the expression slot of the promise replaces the symbol. B...
2007 Sep 19
3
delayedAssign
The last two lines of example(delayedAssign) give this: > e <- (function(x, y = 1, z) environment())(1+2, "y", {cat(" HO! "); pi+2}) > (le <- as.list(e)) # evaluates the promises $x <promise: 0x032b31f8> $y <promise: 0x032b3230> $z <promise: 0x032b3268> which contrary to the comment appears...
2012 Jan 30
4
replacing characters in matrix. substitute, delayedAssign, huh?
...thing to numeric newBM <- apply(BM, c(1,2), as.numeric) and use newBM for some big calculation. Then re-set new values for a, b, d, do the same over again. I've been trying lots of variations on parse, substitute, and eval. The most interesting function I learned about this morning was delayedAssign. If I had only to work with one scalar, it does what I want > delayedAssign("a", whatA) > whatA <- 91 > a [1] 91 I can't see how to make that work in the matrix context, though. Got ideas? pj > sessionInfo() R version 2.14.1 (2011-12-22) Platform: x86_64-pc-linux-g...
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 and odd. Unfortunately, this doesn't seem to help for reaching into the namespace of hgu133a.db and inspect...
2013 Apr 03
1
Documentation error in subsitute
Hi all, The documentation for substitute currently reads: Substitution takes place by examining each component of the parse tree as follows: If it is not a bound symbol in ?env?, it is unchanged. If it is a promise object, i.e., a formal argument to a function or explicitly created using ?delayedAssign()?, the expression slot of the promise replaces the symbol. If it is an ordinary variable, its value is substituted, unless ?env? is ?.GlobalEnv? in which case the symbol is left unchanged. Since the clause referring to the globalenv() is attached to the discussion of ordinary variables, I though...
2005 Mar 11
3
delay() has been deprecated for 2.1.0
...be error-prone in usage (e.g. this was the cause of the bug that makes the curve() function create a "pu" object in the global environment); and it was generally difficult to figure out exactly what the semantics of it should be in order to be consistent. delay() has been replaced with delayedAssign(). This new function creates a promise and assigns it into an environment. Once one more set of changes is made and delay() is gone, there should be no way to see a <promise: ...> object in R: as soon as the object is accessed, it will be evaluated and you'll see the value. A few pack...
2007 Feb 15
2
Problems with 'delay'/'delayedAssign' when installing data package
...:43:00 2005; biocbuild It is an example database of the geneplotter library. Trying to install, I got: $ R CMD INSTALL hgu95av2_1.7.0.tar.gz * Installing *source* package 'hgu95av2' ... ** R ** data ** preparing package for lazy loading Error: 'delay' is defunct. Use 'delayedAssign' instead. See help("Defunct") Execution halted ERROR: lazy loading failed for package 'hgu95av2' ** Removing '/usr/local/lib64/R-2.4.1/library/hgu95av2' How to by-pass this problem? Thanks - Wolfram
2006 Oct 18
1
Error condition in evaluating a promise
Is there a way to raise an error condition when a promise is evaluated such that is can be evaluated again? Right now strange things happen when the evaluation fails: > delayedAssign("x", if (failed) stop("you have to initialize me first!") else foo) > foo <- "I'm foo" > failed<-TRUE > x Error: you have to initialize me first! > x Error: recursive default argument reference ^^-- from now on x is completely unusable - it...
2015 Jan 26
2
Inspect a "delayed" assigned whose value throws an error?
Hi, I got an interesting programming challenge: How do you inspect an object which is assigned via delayedAssign() and that throws an error as soon as it is "touched" (=the value is evaluated)? Is it possible? MINIMAL EXAMPLE: $ R --vanilla > delayedAssign("foo", stop("Hey!")) (If you find this minimal example silly/obvious, please skip down to the real example at the end...
2011 Apr 08
1
R and lazy evaluation
Haskell is the prototypical lazy evaluation language. One can compute a Fibonacci sequence by the Haaskell equivalent of the following R code. > fibs <- c(0, 1, rep(0, 8)) > fibs[3:10] <- fibs + fibs[-1] This works as follows. fibs = 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 fibs = 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 When one adds fibs to fibs[-1], one is effectively adding diagonally: fibs[3] <-
2007 Sep 20
1
copying promise
...x. Thus the answer to the code below is desired to be z=2 but its 1, 1 and y in the next three examples so they are not the answer. See examples at end. 2. Is there some way to determine if a variable holds a promise without evaluating it? This code relates to question 1. # example 1 x <- 0 delayedAssign("y", x) x <- 1 # this forces y which is not what we want z <- y x <- 2 z # 1 # example 2 # this connects to z to x via y which is not what we want # since if y is forced then z takes its value from that, not x x <- 0 delayedAssign("y", x) delayedAssign("z&quot...
2015 Jan 27
0
Inspect a "delayed" assigned whose value throws an error?
...;>> on Mon, 26 Jan 2015 12:41:48 -0800 writes: > 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 and odd. > Unfortunately, this doesn't seem to help for re...
2015 Jan 26
0
Inspect a "delayed" assigned whose value throws an error?
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) Hadley On Mon, Jan 26, 2015 at 12:53 PM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote: > Hi, I got an interesting programming challenge:...
2012 May 22
2
how to remove the 'promise' attribute of an R object (.Random.seed)?
Hi, The problem arises when I lazyLoad() the .Random.seed from a previously saved database. To simplify the process of reproducing the problem, see the example below: ## this assignment may not really make sense, but illustrates the problem delayedAssign('.Random.seed', 1L) typeof(.Random.seed) # [1] "integer" rnorm(1) # Error in rnorm(1) : # .Random.seed is not an integer vector but of type 'promise' typeof(.Random.seed) # [1] "integer" So there must be an "attribute" "promise" somewhere...
2012 May 22
2
how to remove the 'promise' attribute of an R object (.Random.seed)?
Hi, The problem arises when I lazyLoad() the .Random.seed from a previously saved database. To simplify the process of reproducing the problem, see the example below: ## this assignment may not really make sense, but illustrates the problem delayedAssign('.Random.seed', 1L) typeof(.Random.seed) # [1] "integer" rnorm(1) # Error in rnorm(1) : # .Random.seed is not an integer vector but of type 'promise' typeof(.Random.seed) # [1] "integer" So there must be an "attribute" "promise" somewhere...