search for: superassignment

Displaying 20 results from an estimated 23 matches for "superassignment".

2023 Mar 19
2
WISH: Optional mechanism preventing var <<- value from assigning non-existing variable
...altered variable is in any environment on the search list. -Bill On Sun, Mar 19, 2023 at 10:54?AM Duncan Murdoch <murdoch.duncan at gmail.com> wrote: > I think that should be the default behaviour. It's pretty late to get > that into R 4.3.0, but I think your proposal (with check.superassignment > = FALSE being the default) could make it in, and 4.4.0 could change the > default to TRUE. > > Duncan > > > > On 19/03/2023 12:08 p.m., Henrik Bengtsson wrote: > > I'd like to be able to prevent the <<- assignment operator ("super > > assignment&...
2023 Mar 19
1
WISH: Optional mechanism preventing var <<- value from assigning non-existing variable
I think that should be the default behaviour. It's pretty late to get that into R 4.3.0, but I think your proposal (with check.superassignment = FALSE being the default) could make it in, and 4.4.0 could change the default to TRUE. Duncan On 19/03/2023 12:08 p.m., Henrik Bengtsson wrote: > I'd like to be able to prevent the <<- assignment operator ("super > assignment") from assigning to the global environm...
2023 Mar 19
1
WISH: Optional mechanism preventing var <<- value from assigning non-existing variable
...ked. If it does not exist or is locked, I'd like an error to be produced. This would allow me to evaluate expressions with this temporarily set to protect against mistakes. For example, I'd like to do something like: $ R --vanilla > exists("a") [1] FALSE > options(check.superassignment = TRUE) > local({ a <<- 1 }) Error: object 'a' not found > a <- 0 > local({ a <<- 1 }) > a [1] 1 > rm("a") > options(check.superassignment = FALSE) > local({ a <<- 1 }) > exists("a") [1] TRUE BACKGROUND: >From help(&qu...
2023 Mar 19
1
WISH: Optional mechanism preventing var <<- value from assigning non-existing variable
...t on the search list. > > -Bill > > On Sun, Mar 19, 2023 at 10:54?AM Duncan Murdoch <murdoch.duncan at gmail.com> > wrote: > > > I think that should be the default behaviour. It's pretty late to get > > that into R 4.3.0, but I think your proposal (with check.superassignment > > = FALSE being the default) could make it in, and 4.4.0 could change the > > default to TRUE. > > > > Duncan > > > > > > > > On 19/03/2023 12:08 p.m., Henrik Bengtsson wrote: > > > I'd like to be able to prevent the <<- assignmen...
2008 Feb 28
0
use of step.gam (from package 'gam') and superassignment inside functions
...y build the model, but step.gam() is unable to see the dataframe that was created in my personal function and upon which my gam model was built. I've included stand-alone code below that will recreate the error. My code shows that this behavior doesn't occur with step(). If I use the superassignment operator "<<-" to define the dataframe "gam.jack" in the example below, I do not get an error. It seems like gam() finds gam.jack in the local environment of fxn, but step.gam() is looking only in the global environment for gam.jack. If anyone has further insight int...
2004 Oct 08
2
Evaluating Assignment-Operator R 2.0.0
Dear Helpers, in which way I have to use the assignment-operator evaluating left to right with R 2.0.0? With R 2.0.0 (w2k-installation) the "superassignment" operator '<<-' seems to have a different behaviour compared with R 1.9.1 : > x<<-4 > x [1] 4 > attr(x,'y')<<-5 Error: Object "x" not found > Using earlier versions of R I never got this error. In the NEWS file and the doc...
2005 Sep 02
2
Superassignment (<<-) and indexing
In a clean environment under R-2.1.0 on Linux: > x <- 1:5 > x[3] <<- 9 Error: Object "x" not found Isn't that odd? (Note x <<- 9 works just fine.) Why am I doing this? Because I'm stepping through code that normally lives inside a function, where "<<-" is appropriate. -- David Brahm (brahm at alum.mit.edu)
2007 Mar 21
1
Snow Package and SPRNG: Will it solve my problem?
Hello and thanks in advance for your time. I currently have a simulation running on my cluster with the help of snow that relies on global variables being changes regularly to random values. It uses these values, lets call them x1 x2 and x3, in custom functions for logliklyhood and score that gets used in the standard optim function. To get set in the global table on the different
2000 Jun 08
3
Output args?
Hi, Is there a way to find out if a function was called with an output argument? Or to prevent the printing of large amount of data if the function was called without output argument? Thanks YG -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20000608/8d7a01ec/attachment.html
2011 Apr 21
6
What does the "<<-" operator mean?
I've been reading some code from an example in a blog post ( http://www.maxdama.com/ here ) and I came across an operator that I hadn't seen before. The author used a <<- operator to update a variable, like so: ecov_xy <<- ecov_xy+decay*(x[t]*y[t]-ecov_xy) At first I thought it was a mistake and tried replacing it with the usual <- assignment operator, but I didn't
2009 Jun 03
3
Return variable assignments from a function
...1 2 3 ================================= Then I could assign each variable like this (which is what I'd like to avoid): ================================= A=stuff$A B=stuff$B c=stuff$c rm(stuff) #stuff isn't needed anymore. ================================= I've even toyed with the superassignment operator, which also works, but I think it doesn't work for functions of functions. The following example works. ================================= simple2 <- function(m,n) { A <<- matrix(c(3,3,2,3),2,2) B <<- m c <<- 1:n } > stuff2=simple2(2,3) > stuff2 [1] 1...
2009 Feb 11
1
Variables captured in closures get copied?
Hi list! I have a data frame called fix and a list of index vectors called rois: > head(rois, 3) [[1]] [1] 2 1 [[2]] [1] 3 [[3]] [1] 6 7 28 26 27 24 25 The part that's causing the issue is the following line: lapply(rois, function(roi) fix$x[roi] <- 100) So for every index vector I'd like to set the respective entries in the data frame (fix) to 100. I
2001 Jun 11
0
mult.fig() utility [was "margin text mtext"]
...a public library, however clever and useful the code might be. It just is not safe. As a quick way round this I suggest the following (R only) solution: 1. Give the function mult.fig an explicit local environment on definition: > environment(mult.fig) <- new.env() 2. Instead of using the superassignment operator, assign the restore list to the local environment of multi.fig (from within multi.fig): assign("old.par", ......, envir = environment(mult.fig)) 3. Provide a special argument to mult.fig so that instead of using par(old.par) to restore the original graphics parameters the use...
2008 Sep 02
2
How is the binding for a super assignment made visible?
The statement Globals <<- list() in the body of a function in a package was intended to write an empty list to the R workspace to collect results during the computations of the function. A package name space has not been specified. The package appears to function correctly, but during the R CMD check of the package while "checking R code for possible problems ... NOTE", no
2009 Jul 17
2
Remembering a value in multiple calls of a function
Hello, I tried this pseudo-generator style experiment (see below). The "<<-" operator assigns to in the calling environment which would be the environment of "getN". Yet when the function incr is returned, isn't this environment lost? Also the print displays GlobalEnv, yet the globalenv does not have any mention of startgiven. This code was inspired from and old
2009 Jul 02
3
Question about <<- assignment
Is this expected behavior? > z <- 1:5 > z[1] <<- 0 Error in z[1] <<- 0 : object "z" not found The documentation seems to suggest that z will be found in the global environment and modified accordingly. Best, Hsiu-Khuern.
2010 Nov 01
1
Function not working
Below is the (really basic) script I am creating to call a function that sets the working directory, determines the number of files it will need to process in that directory, and creates a mask. A "for" loop will eventually be added that will loop through the files (arrays) in that directory performing a baseline/zero correction and apply the mask - that will probably be a later plea
2007 Apr 02
2
(Newbie)Basic Basic global vs. local variables
My R code has got too complex to have a non-modular approach. Ive done some coding in other languages before, but I somehow cant figure out R's general rules for global and local variables. I have put a simple code below, if anyone can show me what i need to add to make this work, i would greatly appreciate it! #---------------------------------------- g_Means<-numeric()
1998 Feb 20
1
R-beta: scoping etc
A non-text attachment was scrubbed... Name: not available Type: text Size: 1538 bytes Desc: not available Url : https://stat.ethz.ch/pipermail/r-help/attachments/19980220/040a76f5/attachment.pl
2010 Dec 26
2
environment question
Hello, everybody. I'm putting together some lecture notes and course exercises on R programming. My plan is to pick some R packages, ask students to read through code and see why things work, maybe make some changes. As I look for examples, I'm running up against the problem that packages use coding idioms that are unfamiliar to me. A difficult thing for me is explaining scope of