similar to: About the scope of a variable and the save() method

Displaying 20 results from an estimated 70000 matches similar to: "About the scope of a variable and the save() method"

2014 May 17
1
environment question
According to :https://stat.ethz.ch/R-manual/R-devel/library/base/html/environment.html "If |fun| is a function or a formula then |environment(fun)| returns the environment associated with that function or formula. If |fun| is |NULL| then the current evaluation environment is returned." > environment() <environment: R_GlobalEnv> > environment(environment)
2016 Dec 08
2
methods(`|`) lists all functions?
Dear R-Devel, I was attempting an exercise in Hadley Wickam's book "Advanced R". The exercise is to find the generic with the greatest number of methods. I found that 'methods(`|`)' produces a list of length 2506, in R 3.3.1. Similar behavior is found in 3.4.0. It seems to include all functions and methods. I imagine something is being passed to "grep" without
2006 May 23
2
Environment problems
Dear list readers, Can someone of you explain this behavior. Here's a toy example: Start by constructing a function tmp >fix(tmp) In the default editor enter this one-liner: hist(rnorm(10)) close the editor and run environment on the function. > environment(tmp) <environment: R_GlobalEnv> Open the editor and remove the last parenthesis, this will make the editor choke.
2016 Dec 12
2
why does parent.frame() cycle when called from inside capture.output()?
Hello R devel/help, I ran into this strange behavior: # showstack is supposed to walk through the stack of parent # environments when it is called: showstack = function() { env = environment() for(i in 1:12) { env = do.call(parent.frame, list(), env=env) print(env) } } # a simple chain of functions: g3=function(t) showstack()
2016 Dec 12
2
why does parent.frame() cycle when called from inside capture.output()?
Hello R devel/help, I ran into this strange behavior: # showstack is supposed to walk through the stack of parent # environments when it is called: showstack = function() { env = environment() for(i in 1:12) { env = do.call(parent.frame, list(), env=env) print(env) } } # a simple chain of functions: g3=function(t) showstack()
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. However, `emptyenv()` has no enclosing
2023 Apr 05
1
on lexical scoping....
It seems mostly correct. Here are a few quibbles: - I don't think "owner" is a good description of the parent environment. Usually when I use owner in computing, there's an implication that the owner controls what it owns, is responsible for allocating and destroying it, etc. Parent environments are targets of a pointer from other environments that list them as their
2009 Apr 20
1
Sharing variables in seperate workspace
Hi all. I'm for the first time trying to make a library in R 2.8.1 on Ubuntu Linux. The library is very simple, R functions just need to share a variable (that is defined in the R code) and maybe functions and export functions for the user to .GlobalEnv. This variable should only be directly accessible from the global workspace (without change of environment) via a hereto dedicated function.
2011 Mar 16
4
Scope of variable?
I know this is a very elementary question... I could not find a solution looking at old posts. I am unable to access a variable outside the scope of a for loop, even when the variable was defined before the loop: haar <- function() { a = c(1.4560773, 2.3752412, 0.9798882, 3.0909252, 2.3986487, 1.8581543) for (i in c(1:100)) { m = matrix(rnorm(36)+1i*rnorm(36),6) qrm = qr(m) Q = qr.Q(qrm)
2009 Sep 29
3
How do I access class slots from C?
Hi I'm trying to implement something similar to the following R snippet using C. I seem to have hit the wall on accessing class slots using C. library(fPortfolio) lppData <- 100 * LPP2005.RET[, 1:6] ewSpec <- portfolioSpec() nAssets <- ncol(lppData) setWeights(ewSpec) <- rep(1/nAssets, times = nAssets) ewPortfolio <- feasiblePortfolio( data = lppData, spec = ewSpec,
2010 Aug 26
1
my function decided to stop working, problem with scoping?
Hello list. Until last week, I've been using my function without a problem. I can only imagine what has changed (no package updates), but all of a sudden, a custom function that uses raster::xyValues stopped working. For some reason, one of the values is not found, even though it's there. Here is a snippet of code from browser() call from within my custom function where everything goes
2009 Mar 31
2
scope of variables in R
I need to allocate (using C nomenclature) a set of "global" variables, some integer scalars and some double vectors. I have placed the name of such variables in the file containing the main script and the called functions: # ---------------------------------------------------------------------------- # --------------------------- GLOBAL DATA & CONSTANTS ----------------------
2002 Aug 06
1
Questions about lexical scope
Dear R-users, The numerical integration example given in Gentleman and Ihaka (2000), "Lexical Scope and Statistical Computing," JCGS, 9, 491-508, is very interesting and helpful in understanding how lexical scope is about. However, I got some questions that I just can't figure out. First all, allow me to copy the two functions given by the authors: midpoint <- function(f, a,
2009 Sep 16
2
I want to get a reference to this time series object
I'm trying to get a reference to this object in C SWX.RET[1:6,c("SBI,"SPI","SII")] While i am able to access and use a plain SWX.RET object, I'm getting confused on how to create an object with the array subscripts like above. Here is what I tried to do. It doesn't work because "[" is obviously not an operation or function on SWX.RET. So how do I
2016 Mar 27
2
sys.function(0)
As I understand https://stat.ethz.ch/R-manual/R-devel/library/base/html/sys.parent.html sys.function(n) returns the function associated with stack frame n. Since frame 0 is defined as .GlobalEnv which is not associated with a function, I would expect this to always return NULL. However, it does not: > sys.function() NULL > f <- function(x) sys.function(x) > f(0) function(x)
2006 Apr 27
1
scope of variable/object ?
Hi, I must be missing something here...Essentially, a short piece of code works if it's standalone, but doesn't work if it's divided into two functions. The code that works is: ################### WORKS ############### library(pamr) set.seed(120) x <- matrix(rnorm(1000*20),ncol=20) y <- sample(c(1:4),size=20,replace=TRUE) mydata <- list(x=x,y=y)
2008 Jul 17
2
nested calls, variable scope
Below is an example of a problem I encounter repeatedly when I write functions. A call works at the command line, but it does not work inside a function, even when I have made sure that all required variables are available within the function. The only way I know to solve it is to make the required variable global, which of course is dangerous. What is the elegant or appropriate way to solve
2023 Apr 04
2
on lexical scoping....
obviously, everyone has different opinions on what's useful but I always found this document quite helpful. I think, in the past, someone said that there are some incorrect statements in but I'm not sure what they are. https://askming.github.io/study_notes/Stats_Comp/Note-How%20R%20searches%20and%20finds%20stuff.html On Tue, Apr 4, 2023 at 7:06?PM Bert Gunter <bgunter.4567 at
2015 Oct 09
4
A where() functions that does what exists() does but return the environment when object lives?
Hi, exists("foo", inherits=TRUE) check whether an object named "foo" exists, and get("foo", inherits=TRUE) retrieves it. I'm looking for a similar function to exists() that returns the environment where the object "foo" exists, iff at all. If not found, NULL is returned. Does that exist? EXAMPLE #1: > sample2 <- base::sample > env <-
2002 Nov 02
1
problem with expand.model.frame
Dear R list members, I'm encountering a problem with expand.model.frame(): Suppose that I define the following simple function (meant just to illustrate the problem): > fun <- function(model){ + expand.model.frame(model, all.vars(formula(model))) + } > and I have the following model, created with an explicit data argument: > mod Call: