Displaying 20 results from an estimated 7000 matches similar to: "delayedAssign"
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 promise objects. After conversion, each
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 result when the promise is not evaluated yet:
delayedAssign("x",
2013 May 15
1
Substitute unaware when promise objects are evaluated
R-devel,
I used the 'substitute' function to create labels for objects inside an environment, without actually evaluating the objects, as the objects might be promises.
However, I was surprised to see that 'substitute' returns the expression slot of the original promise even after the promise has been forcibly evaluated. (Doesn't the promise go away after evaluation?) This
2007 Sep 20
1
copying promise
1. Is there some way to copy a promise so that the copy has the same
expression in its promise as the original. In the following we
y is a promise that we want to copy to z. We
want z to be a promise based on the expression x since y is a
promise based on the expression 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
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
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'm stuck---there's no way
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"
> delayedAssign("x", msg)
> msg <-
2007 Sep 24
1
Inspecting promises
Is there some way of displaying the expression and evaluation environment
associated with a promise? I have found the following:
> # first run these two commands to set up example
> e <- new.env()
> delayedAssign("y", x*x, assign.env = e)
> # method 1. shows expression but not evaluation environment
> str(as.list(e))
List of 1
$ y: promise to language x * x
>
2012 Jan 30
4
replacing characters in matrix. substitute, delayedAssign, huh?
A user question today has me stumped. Can you advise me, please?
User wants a matrix that has some numbers, some variables, possibly
even some function names. So that has to be a character matrix.
Consider:
> BM <- matrix("0.1", 5, 5)
Use data.entry(BM) or similar to set some to more abstract values.
> BM[3,1] <- "a"
> BM[4,2] <- "b"
>
2005 Mar 11
3
delay() has been deprecated for 2.1.0
After a bunch of discussion in the core group, we have decided to
deprecate the delay() function (which was introduced as "experimental"
in R 0.50). This is the function that duplicates in R code the
delayed evaluation mechanism (the promise) that's used in evaluating
function arguments.
The problem with delay() was that it was handled inconsistently (e.g.
sometimes you would see
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
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
2007 Sep 12
1
warning upon automatic close of connection
I noticed that under R 2.6.0 there is a warning about closing the connection
in the code from this post:
https://stat.ethz.ch/pipermail/r-help/2007-September/140601.html
which is evidently related to the following from the NEWS file:
o Connections will be closed if there is no R object referring to
them. A warning is issued if this is done, either at garbage
collection or if all the
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
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
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
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.
But this doesn't seem to work:
> a <- 1
> b <- 2
2007 Feb 15
2
Problems with 'delay'/'delayedAssign' when installing data package
I downloaded:
http://www.bioconductor.org/data/metaData/hgu95av2_1.7.0.tar.gz
described as:
Package: hgu95av2
Title: A data package containing annotation data for hgu95av2
Version: 1.7.0
Created: Wed Jan 12 16:57:23 2005
Author: Lin,Chenwei
Description: Annotation data file for hgu95av2 assembled using data
from public data repositories
Maintainer:
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,
2006 Nov 14
2
Problem with file size
Hi everyone,
I have 2 environments (2 different R sessions) as described below:
Session 1:
Name of the environment: "CrlmmInfo"
Objects in the environment:
index1: logical index - length 238304
index2: logical index - length 238304
priors: list of 4 - (matrix 6x6, 2 vectors of length 6, vector of
length 2) - all num
params: list of 4:
centers [238304 x 3 x