Displaying 20 results from an estimated 700 matches similar to: "copying promise"
2010 Oct 20
1
Loading Cached Weaver Objects
Hello,
I'm looking for a way to extract objects from what gets created when I Sweave with driver = weaver(). I found where the .Rdata objects are, but when I load one into R, I don't see anything that looks like the objects that were created in that code chunk.
> load("/home/darstr/r_env_cache/2.11.0/AbsMeth_5/ac047940aaa9cf1a1ec09f1628b13381.RData")
> ls()
[1]
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 unevaluated. Is the comment
wrong or is it supposed to
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
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
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
2014 Oct 17
1
Making parent.env<- an error for package namespaces and package imports
I'd like to propose a change to the R language so that calling
'parent.env<-' on a package namespace or package imports is a runtime
error.
Currently the documentation warns that it's dangerous behaviour and
might go away:
The replacement function ?parent.env<-? is extremely dangerous as
it can be used to destructively change environments in ways that
violate
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
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
2024 May 11
1
R hang/bug with circular references and promises
The following code snippet causes R to hang. This example might be a
bit contrived as I was experimenting and trying to understand
promises, but uses only base R.
It looks like it is looking for "not_a_variable" recursively but since
it doesn't exist it goes on indefinitely.
x0 <- new.env()
x1 <- new.env(parent = x0)
parent.env(x0) <- x1
delayedAssign("v",
2004 Oct 08
2
R-2.0.0 findVar and findFun question
Dear all,
when working on a project with embedded R, I found out that R-2.0.0 causes
a problem where older versions worked OK.
Rf_findVar(...) causes the following error when used to find a generic function
(such as print):
fun = Rf_findVar(...);
R_tryEval(fun, ...);
Error in function (object, ...) : Invalid generic function in usemethod
Alternatively, using Rf_findFun(...) seems OK in this
2024 May 11
1
[External] R hang/bug with circular references and promises
On Sat, 11 May 2024, Travers Ching wrote:
> The following code snippet causes R to hang. This example might be a
> bit contrived as I was experimenting and trying to understand
> promises, but uses only base R.
>
> It looks like it is looking for "not_a_variable" recursively but since
> it doesn't exist it goes on indefinitely.
>
> x0 <- new.env()
> x1
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",
2012 Sep 15
1
Question about copying arguments in C.
Hi List,
I'd imagine this is a question that has been answered before, but I
can't seem to track it down, sorry for the duplication if it has.
I am writing an interface for a C library and want to return an S4
class from the 'constructing' method. One of the slots of the argument
to be returned will be filled with one of the arguments passed to the
function. My question is about
2020 Mar 24
2
help with rchk warnings on Rf_eval(Rf_lang2(...))
> Shield<SEXP> res(Rcpp_fast_eval(Rf_lang2(asEnvironmentSym, x), R_GlobalEnv));
The call should be protected before evaluation though. So more like:
Shield<SEXP> call(Rf_lang2(asEnvironmentSym, x));
return Rcpp_fast_eval(call, R_GlobalEnv);
Best,
Lionel
On 3/23/20, Dirk Eddelbuettel <edd at debian.org> wrote:
>
>
> On 23 March 2020 at 17:07, Ben Bolker wrote:
>
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
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
>
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 <-
2015 Jan 27
0
Inspect a "delayed" assigned whose value throws an error?
>>>>> Henrik Bengtsson <hb at biostat.ucsf.edu>
>>>>> 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()
>>
2009 Sep 03
1
Running an expression 1MN times using embedded R
Hello,
I'm evaluating this expression
expression({ for(x in 1:5){ .Call('rh_status','x') }})
a million times from a program with R embedded in it. I have attached
reproducible code that crashes with
Program received signal SIGSEGV, Segmentation fault.
0x00002b499ca40a6e in R_gc_internal (size_needed=0) at memory.c:1309
1309 FORWARD_NODE(R_PPStack[i]);
Current language: