similar to: getting caller's environment

Displaying 20 results from an estimated 50000 matches similar to: "getting caller's environment"

2009 Jan 23
1
overwriting '<-' and infinite recursions
Hello all, I'm having a problem when overwriting the '<-' function and was told I'd better post it here for help. The reason why I need to overwrite it is complicated and not easy to tell in a few words; but this seems the only clean option other than hacking R's core source code. My code looks like: # in .onLoad of a package; or if you want to test, put it in a function
2009 Jan 22
3
how to get a primitive function object
Hi, I want to create an alias for the "<-" function and then later overwrite it. Any idea how I can get the "<-" function object? I know for other functions it's easy, something like "f <- seq" will do; how really no clue for this one. Thanks!
2010 Jul 21
2
Variance of the prediction in the linear regression model (Theory and programming)
Hi, folks, Here are the codes: ############## y=1:10 x=c(1:9,1) lin=lm(log(y)~x) ### log(y) is following Normal distribution x=5:14 prediction=predict(lin,newdata=x) ##prediction=predict(lin) ############### 1. The codes do not work, and give the error message: Error in eval(predvars, data, env) : numeric 'envir' arg not of length one. But if I use the code after the pound sign, it
2011 Mar 10
2
Create an environment and assign objects to it in one go?
Hi, I've just created: newEnvEval <- function(..., hash=FALSE, parent=parent.frame(), size=29L) { envir <- new.env(hash=hash, parent=parent, size=size); evalq(..., envir=envir); envir; } # newEnvEval() so that I can create an environment and assign objects to it in one go, e.g. env <- newEnvEval({ a <- 1; b <- 2; }); print(env$a); Does this already exists somewhere?
1999 Jun 15
1
Accessing a function's environment
In a short course he is teaching here, Bill Venables has shown how to cache the results of a recursive calculation so that later invocations of the functions are speeded up. His example is an ingenious way of calculating all the subsets of size r from a set of size n. His version of this function for R stored these cached values in the global environment. I suggested that it might be preferable
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 <-
2013 Jun 25
1
Perplexed with environment
Hi I migrated from Linux to Mac, but I don't this has anything to do with it, but I am not sure. I am writing a small logger package, in which I have a file aaa.R: ,---- | .logData <- new.env() | assign("loggingThreshold", 10, envir = .logData) | assign("logToFile", FALSE, envir = .logData) | assign("logFileName", NULL, envir = .logData) | |
2016 Apr 20
1
locked environments
Shouldn't the following 4 ways to alter an object in a locked environment either all work or all fail? (All working would be nice, I think.) E <- new.env() assign("var", c(1,2,3,4), envir=E) lockEnvironment(E, bindings=FALSE) E$var[1] <- 101 ; E$var #[1] 101 2 3 local(var[2] <- 102, envir=E) #Error in eval(expr, envir, enclos) : # cannot add
2006 Apr 04
2
Return function from function with minimal environment
Hi, this relates to the question "How to set a former environment?" asked yesterday. What is the best way to to return a function with a minimal environment from a function? Here is a dummy example: foo <- function(huge) { scale <- mean(huge) function(x) { scale * x } } fcn <- foo(1:10e5) The problem with this approach is that the environment of 'fcn' does not
2008 Jul 29
1
environment question
Hi R users! I was looking at some of the example code for the "environment" function. Here it is: e1 <- new.env(parent = baseenv()) # this one has enclosure package:base. e2 <- new.env(parent = e1) assign("a", 3, envir=e1) ls(e1) ls(e2) exists("a", envir=e2) # this succeeds by inheritance exists("a", envir=e2, inherits = FALSE)
2009 Feb 15
2
Passing environments: why doesn't this work???
This is a trivial example I set up to see if I could pass an environment and use the variables in it (this is for a function that will be called many times and might need to use a lot of variables that won't be changing, so it seemed more sensible to use an environment). Here's the code: ######################### #The outer function run.internal.env <- function(x) { in.env <-
2005 Feb 08
1
Environment with no parent?
Is it possible to create an environment that has no parent (or an empty parent)? I would have thought e <- new.env(parent=NULL) would work, but it acts as though the parent is the base namespace: > get("close", envir = e) function (con, ...) UseMethod("close") <environment: namespace:base> I can use inherits = FALSE in this case: > get("close",
2008 May 10
2
Hashes as S4 Classes, or: How to separate environments
For learning purposes mainly I attempted to implement hashes/maps/dictionaries (Python lingua) as S4 classes, see the coding below. I came across some rough S4 edges, but in the end it worked (for one dictionary). When testing ones sees that the dictionaries D1 and D2 share their environments D1 at hash and D2 at hash, though I thought a new and empty environment would be generated each time
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
2005 Mar 08
4
how modify object in parent.env
Hi, Is it possible to modify an object in the parent.env (as opposed to re-bind)? Here is what I tried: > x = 1:3 # try to modify the first element of x from within a new environment > local(get("x", parent.env(environment()))[1] <- NA) Error in eval(expr, envir, enclos) : Target of assignment expands to non-language object # On the other hand retrieval works just fine >
2011 Jun 03
2
S4 Slot assignment within function
Is there a simple way to assign values to S4 slots from within a function? Doing this doesn't work: > assign_slot<-function(x){ assign("OBJECT at slot",x,envir=parent.env(environment()) } >assign_slot(x) All I get from this is a new object with the name OBJECT at slot, the slot assignment of OBJECT doesn't change. I have thought about solutions such as
2006 Jun 02
4
function environment
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, how can I automatically access the functions that I loaded into a separate environment? > save(A,B,file="myfun.r") > load("myfun.r",envir=(ENV<-new.env())) > ls(ENV) [1] "A" "B" ?"[" turned up that I can access the functions via > ENV$A function () { } > ENV$A() NULL Now, how
2017 May 09
3
R-3.3.3/R-3.4.0 change in sys.call(sys.parent())
Some formula methods for S3 generic functions use the idiom returnValue$call <- sys.call(sys.parent()) to show how to recreate the returned object or to use as a label on a plot. It is often followed by returnValue$call[[1]] <- quote(myName) E.g., I see it in packages "latticeExtra" and "leaps", and I suspect it used in "lattice" as well. This idiom
2011 Aug 23
2
Increase transparency: suggestion on how to avoid namespaces and/or unnecessary overwrites of existing functions
aDear list, I'm aware of the fact that I posted on something related a while ago, but I just can't sweat this off and would like to ask your for an opinion: The problem: Namespaces are great, but they don't resolve certain conflicts regarding name clashes. There are more and more people out there trying to come up with their own R packages, which is great also! Yet, it becomes
2005 May 14
2
help with eval
I've been looking at the help page for eval for a while, but I can't make sense of why this example does not work. show.a <- function() { a } init.env <- function() { a <- 200 environment() } my.env <- init.env() ls(envir=my.env) # returns this: # > ls(envir=my.env) # [1] "a" # but this does not work: eval(expression(show.a()),envir=my.env) # >