similar to: Capturing environment associated with a promise

Displaying 20 results from an estimated 30000 matches similar to: "Capturing environment associated with a promise"

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
2009 Sep 09
2
Finding the environment of a promise
Hi all, Is it possible to determine the environment in which a promise will be evaluated? e.g. f <- function(code) { force(code) } f({ a <- 1 b <- 2 }) Is there any way to tell from within f that a and b will be created in the global environment? Thanks, Hadley -- http://had.co.nz/
2015 Jun 30
2
Defining a `show` function breaks the print-ing of S4 object -- bug or expected?
Same thing happens with S3 if you redefine print(). I thought that code was actually calculating the function to call rather than the symbol to use, but apparently not. Shouldn't be too hard to fix. luke On Tue, 30 Jun 2015, Hadley Wickham wrote: > On Tue, Jun 30, 2015 at 2:20 PM, Duncan Murdoch > <murdoch.duncan at gmail.com> wrote: >> On 30/06/2015 1:57 PM, Hadley
2013 Feb 18
2
quote() vs quote(expr=)
Hi all, I think there's a small buglet in quote: str(quote()) # Error in quote() : 0 arguments passed to 'quote' which requires 1 str(quote(expr = )) # symbol I bring this up because this seems like the most natural way of capturing the "missing" symbol with pure R code, compared to substitute() or bquote() or formals(plot)$x Hadley -- Chief Scientist, RStudio
2003 Aug 11
1
An inconsistency with promise in attributes
When an attribute is a delayed expression sometimes it is not forced when it is extracted. > x <- list() > attr(x, "p") <- delay(1) > x list() attr(,"p") <promise: 0x11e4bb8> > val <- attr(x, "p") > val [1] 1 > attr(x, "p") <promise: 0x11e4bb8> I am not quite sure whether the above is a bug or not but I think
2015 Jun 30
2
Defining a `show` function breaks the print-ing of S4 object -- bug or expected?
On 30/06/2015 5:27 PM, Lorenz, David wrote: > There is something I'm really missing here. The function show is a > standardGeneric function, so the correct way to write it as method like > this: That describes methods::show. The problem is that the default print mechanism isn't calling methods::show() (or base::print() as Luke says), it's calling show() or print() in the
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,
2015 Mar 30
1
Segfault with match()
I left out the warning - it's still there. The output object is malformed but either +.factor should prevent this or match() should check. Hadley On Mon, Mar 30, 2015 at 3:50 PM, William Dunlap <wdunlap at tibco.com> wrote: > Did you leave out the warning from "+", which should be an error, > as it produces an illegal ordered factor in this case and factor+factor >
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 >
2011 May 04
4
Recursive objects
Hi all, Does anyone have a comprehensive list of recursive-type objects in R? is.recursive defines them as by exclusion: "most types of objects are regarded as recursive, except for vector types, ?NULL? and symbols (as given by ?as.name?)." I think this that means recursive objects are: * lists * pairlists * calls * expressions Did I miss anything? Hadley -- Assistant
2015 Jun 30
2
Defining a `show` function breaks the print-ing of S4 object -- bug or expected?
On 30/06/2015 1:57 PM, Hadley Wickham wrote: > A slightly simpler formulation of the problem is: > > show <- function(...) stop("My show!") > methods::setClass("Person", slots = list(name = "character")) > methods::new("Person", name = "Tom") > #> Error in (function (...) : My show! Just to be clear: the complaint is
2015 Jun 30
1
Defining a `show` function breaks the print-ing of S4 object -- bug or expected?
On 30/06/2015 7:04 PM, Paul Gilbert wrote: > > > On 06/30/2015 11:33 AM, Duncan Murdoch wrote: >> On 30/06/2015 5:27 PM, Lorenz, David wrote: >>> There is something I'm really missing here. The function show is a >>> standardGeneric function, so the correct way to write it as method like >>> this: >> >> That describes methods::show. The
2024 Jun 07
1
clarifying and adjusting the C API for R
Thanks for working on this Luke! We appreciate your efforts to make it easier to tell what's in the exported API and we're very happy to work with you on any changes needed to tidyverse/r-lib packages. Hadley On Thu, Jun 6, 2024 at 9:47?AM luke-tierney--- via R-devel < r-devel at r-project.org> wrote: > This is an update on some current work on the C API for use in R >
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
2009 Sep 02
1
Tracebacks & try
Hi all, The help for traceback states: Errors which are caught _via_ 'try' or 'tryCatch' do not generate a traceback, so what is printed is the call sequence for the last uncaught error, and not necessarily for the last error. Is there any way to get a traceback (or something similar) for an error raised inside a try block? Regards, Hadley -- http://had.co.nz/
2020 Sep 08
1
some questions about R internal SEXP types
On Tue, Sep 8, 2020 at 4:12 AM Tomas Kalibera <tomas.kalibera at gmail.com> wrote: > > > The general principle is that R packages are only allowed to use what is > documented in the R help (? command) and in Writing R Extensions. The > former covers what is allowed from R code in extensions, the latter > mostly what is allowed from C code in extensions (with some references
2014 Feb 11
1
getting environment from "top" promise
Hi all, It seems that there is a use case for obtaining the environment for the "top" promise. By "top", I mean following the promise chain up the call stack until hitting a non-promise. S4 data containers often mimic the API of base R data structures. This means writing S4 methods for functions that quote their arguments, like with() and subset(). The methods package
2024 Mar 08
1
Function environments serialize to a lot of data until they don't
Hello R-help, I've noticed that my 'parallel' jobs take too much memory to store and transfer to the cluster workers. I've managed to trace it to the following: # `payload` is being written to the cluster worker. # The function FUN had been created as a closure inside my package: payload$data$args$FUN # function (l, ...) # withCallingHandlers(fun(l$x, ...), error =
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