search for: emptyenv

Displaying 20 results from an estimated 65 matches for "emptyenv".

2019 Mar 23
4
topenv of emptyenv
I was surprised just now to find out that `topenv(emptyenv())` equals ? `.GlobalEnv`, not `emptyenv()`. From my understanding of the description of `topenv`, it should walk up the chain of enclosing environments (as if by calling `e = parent.env(e)` repeatedly; in fact, that is almost exactly its implementation in envir.c) until it hits a top level. Howeve...
2019 Mar 28
0
topenv of emptyenv
>>>>> Konrad Rudolph >>>>> on Sat, 23 Mar 2019 14:26:40 +0000 writes: >>>>> Konrad Rudolph >>>>> on Sat, 23 Mar 2019 14:26:40 +0000 writes: > I was surprised just now to find out that `topenv(emptyenv())` equals > ? `.GlobalEnv`, not `emptyenv()`. From my understanding of the > description of `topenv`, it should walk up the chain of enclosing > environments (as if by calling `e = parent.env(e)` repeatedly; in > fact, that is almost exactly its implementation in envir....
2010 Sep 01
2
testing for emptyenv
...onments e1 and e2 are equal? I tried a couple of ways to compare environments, but neither seem to work: > e1 <- new.env() > e2 <- new.env() > e1 == e2 Error in e1 == e2 : comparison (1) is possible only for atomic and list types > all.equal(e1, e2) [1] TRUE > all.equal(e1, emptyenv()) [1] TRUE My ultimate goal is to make a list of all variables in the lexical scope (enclosure?) of a function FUN. So I thought I'd start with environment(FUN) and apply parent.env() until I reach emptyenv(). But for this to work I need to be able to detect that I reached emptyenv(). Thank...
2013 Apr 18
2
how to control the environment of a formula
...lt;- rnorm(1000000) | out <- list() | out$f <- a~b | out | } | v <- test(1) | save(v,file="~/tmp/v.rda") | system("ls -lah ~/tmp/v.rda") | | -rw-rw-r-- 1 tag tag 7,4M Apr 18 06:41 /home/tag/tmp/v.rda `---- I tried to replace line 3 by ,---- | as.formula(a~b,env=emptyenv()) | or | as.formula(a~b,env=NULL) `---- without the desired effect. Instead adding either ,---- | environment(out$f) <- emptyenv() | or | environment(out$f) <- NULL `---- has the desired effect (i.e. the saved object size is shrunken). unfortunately there is a new problem: ,---- | test &...
2015 Oct 13
1
A where() functions that does what exists() does but return the environment when object lives?
On Tue, Oct 13, 2015 at 4:43 PM, Hadley Wickham <h.wickham at gmail.com> wrote: > Seems easy enough to write yourself: > > where <- function(x, env = parent.frame()) { > if (identical(env, emptyenv())) > return(NULL) > if (exists(x, envir = env, inherits = FALSE)) > return(env) > where(x, parent.env(env)) > } > > sample2 <- base::sample > where("sample2") > #> <environment: 0x1154d3c28> And that returns a random environ...
2020 Aug 10
1
lm() takes weights from formula environment
Thank you for your suggestion. I do know how to work around the issue. I usually build a fresh environment as a child of base-environment and then insurt the weights there. I was just trying to provide an example of the issue. emptyenv() can not be used, as it is needed for the eval (errors out even if weights are not used with "could not find function list"). For some applications one doesn't want the formula to have a non-trivial environment with respect to serialization. Nina Zumel wrote about reference leaks i...
2006 Apr 25
7
R 2.3.0: Use of NULL as an environment is deprecated
...subscriber, first, let me express my thank to the R-Core team for the new release! I appreciate their efforts and time spent to enhance R. In accordance with the 'NEWS' file (see excerpt of it below), [... o Changed the environment tree to be rooted in an empty environment, available as emptyenv(). baseenv() has been modified to return an environment with emptyenv() as parent, rather than NULL. ... o Use of NULL as an environment is deprecated and gives a warning. ...] I detected the warning message as announced for a couple of contributed packages, e.g. library(ape) library(car) li...
2006 Apr 25
7
R 2.3.0: Use of NULL as an environment is deprecated
...subscriber, first, let me express my thank to the R-Core team for the new release! I appreciate their efforts and time spent to enhance R. In accordance with the 'NEWS' file (see excerpt of it below), [... o Changed the environment tree to be rooted in an empty environment, available as emptyenv(). baseenv() has been modified to return an environment with emptyenv() as parent, rather than NULL. ... o Use of NULL as an environment is deprecated and gives a warning. ...] I detected the warning message as announced for a couple of contributed packages, e.g. library(ape) library(car) li...
2006 Apr 04
2
Return function from function with minimal environment
...ir=env); bar <- function(x) { scale * x }; environment(bar) <- env; bar; } fcn <- foo3(1:10e5) But, env <- environment(fcn) save(env, file="temp.RData"); file.info("temp.RData")$size # [1] 2007720 When I try to set the parent environment of 'env' to emptyenv(), it does not work, e.g. fcn(2) # Error in fcn(2) : attempt to apply non-function but with the new.env(parent=baseenv()) it works fine. The "base" environment has the empty environment as a parent. So, I try to do the same myself, i.e. new.env(parent=new.env(parent=emptyenv())), but o...
2005 Nov 04
1
Changes to environments in R-devel
...conversion in place, and use of NULL will cause an error; please let me know if you find any of those. The intention is that NULL will be usable with warnings through to the end of the 2.3.x releases. - baseenv() is no longer its own parent. Its parent is an empty environment, available as emptyenv(). - You can now create your own environment with emptyenv() as its parent. Searches for variables in such an environment will not automatically proceed to baseenv(), as searches do in current R releases. Duncan Murdoch
2008 Nov 17
4
functional (?) programming in r
...ual(envs[[i]], envs[[j]])) check(identical) check(compare) compare seems to cast environments to character; for identical, the docs give an example where environments are compared, but compare fails (i.e., succeeds) miserably (the docs do not warn not to compare environments): e1 = new.env(parent=emptyenv()) e2 = new.env(parent=emptyenv()) assign("foo", "bar", e1) compare(e1, e2) # oops? back to the original example, how come? vQ ---- for those curious, try the following in python: map(lambda func: func(), [lambda: i for i in range(5)]) map(lambda func: func(), (lambda: i f...
2020 Aug 10
3
lm() takes weights from formula environment
I wish I had started with "I am disappointed that lm() doesn't continue its search for weights into the calling environment" or "the fact that lm() looks only in the formula environment and data frame for weights doesn't seem consistent with how other values are treated." But I did not. So I do apologize for both that and for negative tone on my part. Simplified
2008 May 10
2
Hashes as S4 Classes, or: How to separate environments
...her corrections and improvements as well. Working in R 2.7.0 under Windows. Hans Werner #-- Class and method definition for dictionaries ------------------------------- setClass("Dict", representation (hash = "environment"), prototype (hash = new.env(hash=T, parent = emptyenv())) ) setMethod("show", signature(object="Dict"), definition = function(object) ls(object at hash) ) setGeneric("hclear", function(object) standardGeneric("hclear")) setMethod("hclear", signature(object="Dict"), function(object)...
2016 Aug 05
2
Extra copies of objects in environments when using $ operator?
...ult in a copy: e <- list(x = list(1)) tracemem(e$x) # [1] "<0x11b3a4b38>" e$x[[1]] <- 2 # (No output) However, modifying a list contained in an environment *does* result in a copy -- tracemem prints out some info when we do the assignment: e <- new.env(parent = emptyenv()) e$x <- list(1) tracemem(e$x) # [1] "<0x1148c1708>" e$x[[1]] <- 2 # tracemem[0x1148c1708 -> 0x11b2fc1b8]: This is surprising to me. Why is a copy made in this case? It also results in slower performance for these situations. The most that I've been able t...
2011 Jun 09
2
Coercing Output from mget() into Proper Data Frame
...other words, I want the word in the first column and the frequency in the second column. Any help would be very much appreciated. Regards, Na'im library(Rstem) # make a data frame of stems and their frequencies stem_freq_list <- function(freqFile) { stem_dict <- new.env(parent=emptyenv(), hash=TRUE) freq_dist <- read.csv(freqFile,header=TRUE) words <- as.character(freq_dist[,1]) freqs <- as.numeric(freq_dist[,2]) stems <- wordStem(words, language="english") uniq_stems <- c() # make a hash table of stems and their frequencies...
2009 Jun 02
2
formal argument "envir" matched by multiple actual arguments
...ironmentORNULL", c("environment", "NULL")) setClass("A", representation( aa="integer", groupname="character", groupanchor="environmentORNULL" ) ) .A.group.sizes <- new.env(hash=TRUE, parent=emptyenv()) .inc.A.group.size <- function(groupname) { group.size <- 1L if (exists(groupname, envir=.A.group.sizes, inherits=FALSE)) group.size <- group.size + get(groupname, envir=.A.group.sizes, inherits=FALSE) assign(groupname, group.size, en...
2010 Nov 06
1
Hashing and environments
...ell how hashing works, so I'm having trouble. Here is an example of what I've done so far: *** setClass("Lexicon",representation(e="environment")) setMethod("initialize","Lexicon",function(.Object,wfreqs) { .Object at e <- new.env(hash=T,parent=emptyenv()) assign("wfreqs",wfreqs,envir=.Object at e) return(.Object) }) ## function to access word frequencies wfreq <- function(lexicon,word) { return(get("wfreqs",envir=lexicon at e)[word]) } ## example of use my.lexicon <- new("Lexicon",wfreqs=c("the"...
2020 Aug 10
0
lm() takes weights from formula environment
...t seem consistent with how other values are treated." Normally searching is done automatically by following a chain of environments. It's easy to add something to the head of the chain (e.g. data), it's hard to add something in the middle or at the end (because the chain ends with emptyenv(), which is not allowed to have a parent). So I'd suggest using environment(f) <- environment() before calling lm() if you want the calling environment to be in the search. Setting it to baseenv() doesn't really make sense, unless you want to disable all searches except in data,...
2011 Mar 17
1
assigning to list element within target environment
I would like to assign an value to an element of a list contained in an environment. The list will contain vectors and matrices. Here's a simple example: # create toy environment testEnv = new.env(parent = emptyenv()) # create list that will be in the environment, then assign() it x = list(a=1,b=2) assign("xList",x,testEnv) # create new element, to be inserted into xList c = 5:7 Now, what I'd like to do is something like this: assign("xList[[3]]",c,testEnv) But the assign() help s...
2005 Feb 08
1
Environment with no parent?
...ction (con, ...) UseMethod("close") <environment: namespace:base> Looking in envir.c, I see this: /* env is now R_NilValue, the base environment */ which doesn't give me much hope, but maybe there's a trick.... If not, would it be reasonable to install a magic "EmptyEnv" to use as a parent in this sort of situation? Duncan Murdoch