[Rd] assignment

2021-12-27 Thread Gabor Grothendieck
In a recent SO post this came up (changed example to simplify it here). It seems that `test` still has the value sin. test <- sin environment(test)$test <- cos test(0) ## [1] 0 It appears to be related to the double use of `test` in `$<-` since if we break it up it works as expected:

Re: [Rd] Assignment operator and deep copy for calling C functions

2016-04-07 Thread Martyn Plummer
This is discussed in the "Writing R Extensions" manual section 5.9.10: Named objects and copying. .Call does not copy its arguments and it is not safe to modify them, as you have found, since multiple symbols may refer to the same object. If you are going to modify an argument to .Call you should

[Rd] Assignment operator and deep copy for calling C functions

2016-04-06 Thread Thorsten R
Hi All, i have a problem in understanding what the assignment operator '<-' really is doing. If i create two numeric arrays in R and copy one into the other with '<-' and afterwards change one array by calling a C function, both arrays are changed! The problem I am facing can easily be seen in

Re: [Rd] Assignment in environment

2016-02-07 Thread Duncan Murdoch
On 07/02/2016 9:15 AM, peter dalgaard wrote: On 07 Feb 2016, at 14:46 , Duncan Murdoch wrot8[e: [snippage] but in fact, this doesn't work: getValue(fn)[[1]] <- 3 Error in getValue(fn)[[1]] <- 3 : could not find function "getValue" I suspect this is a parser problem. Umm, no... The can

Re: [Rd] Assignment in environment

2016-02-07 Thread Daniel Kaschek
On So, Feb 7, 2016 at 2:46 , Duncan Murdoch wrote: An assignment function should return the modified value. So it looks like you would need 'getValue<-' <- function(x, value) { environment(x)$mylist <- value x } Thanks. I have not thought of a return value. That makes the differen

Re: [Rd] Assignment in environment

2016-02-07 Thread peter dalgaard
> On 07 Feb 2016, at 14:46 , Duncan Murdoch wrot8[e: > [snippage] > > but in fact, this doesn't work: > > getValue(fn)[[1]] <- 3 > Error in getValue(fn)[[1]] <- 3 : could not find function "getValue" > > I suspect this is a parser problem. Umm, no... The canonical semantics are that foo(x

Re: [Rd] Assignment in environment

2016-02-07 Thread Duncan Murdoch
On 07/02/2016 8:08 AM, Daniel Kaschek wrote: Dear all, I have a function "fn" with its own environment, i.e. env <- environment(fn) and env is not .GlobalEnv. And another function getValue <- function(x) environment(x)$mylist which returns the list object "mylist" which is in "env". If I wan

[Rd] Assignment in environment

2016-02-07 Thread Daniel Kaschek
Dear all, I have a function "fn" with its own environment, i.e. env <- environment(fn) and env is not .GlobalEnv. And another function getValue <- function(x) environment(x)$mylist which returns the list object "mylist" which is in "env". If I want to modify "mylist", I could write 'getVal

Re: [Rd] Assignment to a slot in an S4 object in a list seems to violate copy rules?

2010-09-30 Thread Prof Brian Ripley
On Thu, 30 Sep 2010, Thomas Lumley wrote: On Thu, Sep 30, 2010 at 8:15 AM, peter dalgaard wrote: On Sep 30, 2010, at 16:19 , Niels Richard Hansen wrote: setClass("A", representation(a = "numeric")) B <- list() myA <- new("A", a = 1) B$otherA <- myA b$oth...@a <- 2 m...@a R version 2.12.0

Re: [Rd] Assignment to a slot in an S4 object in a list seems to violate copy rules?

2010-09-30 Thread Thomas Lumley
On Thu, Sep 30, 2010 at 8:15 AM, peter dalgaard wrote: > > On Sep 30, 2010, at 16:19 , Niels Richard Hansen wrote: > >> setClass("A", representation(a = "numeric")) >> B <- list() >> myA <- new("A", a = 1) >> B$otherA <- myA >> b$oth...@a <- 2 >> m...@a > > R version 2.12.0 Under development (unst

Re: [Rd] Assignment to a slot in an S4 object in a list seems to violate copy rules?

2010-09-30 Thread peter dalgaard
On Sep 30, 2010, at 16:19 , Niels Richard Hansen wrote: > setClass("A", representation(a = "numeric")) > B <- list() > myA <- new("A", a = 1) > B$otherA <- myA > b$oth...@a <- 2 > m...@a R version 2.12.0 Under development (unstable) (2010-09-13 r52905) Platform: i386-apple-darwin9.8.0/i386 (32-b

[Rd] Assignment to a slot in an S4 object in a list seems to violate copy rules?

2010-09-30 Thread Niels Richard Hansen
Dear R-developers I came across the following issue, which I find strange: setClass("A", representation(a = "numeric")) B <- list() myA <- new("A", a = 1) B$otherA <- myA b$oth...@a <- 2 m...@a Assigning a new value to slot 'a' in the _copy_ of myA stored in B$otherA changes the original value

Re: [Rd] Assignment of individual values to data frame columns: intentional or unintentional behavior?

2010-09-02 Thread Peter Ehlers
On 2010-08-05 12:14, Ulrike Grömping wrote: Gabor Grothendieck schrieb: On Thu, Aug 5, 2010 at 12:24 PM, Ulrike Grömping wrote: Dear developeRs, I have just discovered a strange feature when assigning some values to columns of a data frame: The column is matched by partial matching (as docu

Re: [Rd] Assignment of individual values to data frame columns: intentional or unintentional behavior?

2010-08-05 Thread Michael Lachmann
Ulrike Grömping wrote: > > > However, given the documentation that partial matching is not used on > the left-hand side, I would have expected even more that the assignment > > sw$Fert[1] <- 10 > > works differently, because I am using it on the left-hand side. > Probably, extraction ([1])

Re: [Rd] Assignment of individual values to data frame columns: intentional or unintentional behavior?

2010-08-05 Thread Ulrike Grömping
Gabor Grothendieck schrieb: On Thu, Aug 5, 2010 at 12:24 PM, Ulrike Grömping wrote: Dear developeRs, I have just discovered a strange feature when assigning some values to columns of a data frame: The column is matched by partial matching (as documented), but when assigning a value, a new c

Re: [Rd] Assignment of individual values to data frame columns: intentional or unintentional behavior?

2010-08-05 Thread Gabor Grothendieck
On Thu, Aug 5, 2010 at 12:24 PM, Ulrike Grömping wrote: > Dear developeRs, > > I have just discovered a strange feature when assigning some values to > columns of a data frame: The column is matched by partial matching (as > documented), but when assigning a value, a new column with the partial na

[Rd] Assignment of individual values to data frame columns: intentional or unintentional behavior?

2010-08-05 Thread Ulrike Grömping
Dear developeRs, I have just discovered a strange feature when assigning some values to columns of a data frame: The column is matched by partial matching (as documented), but when assigning a value, a new column with the partial name is added to the data frame that is identical to the origina

Re: [Rd] Assignment to string

2009-04-02 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: > On Wed, Apr 1, 2009 at 5:11 PM, Wacek Kusnierczyk < > waclaw.marcin.kusnierc...@idi.ntnu.no> wrote: > > >> Stavros Macrakis wrote: >> ... >> i think this concords with the documentation in the sense that in an >> assignment a string can work as a name. note that >> >>

Re: [Rd] Assignment to string

2009-04-01 Thread Stavros Macrakis
On Wed, Apr 1, 2009 at 5:11 PM, Wacek Kusnierczyk < waclaw.marcin.kusnierc...@idi.ntnu.no> wrote: > Stavros Macrakis wrote: > ... > i think this concords with the documentation in the sense that in an > assignment a string can work as a name. note that > >`foo bar` = 1 >is.name(`foo`) >

Re: [Rd] Assignment to string

2009-04-01 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: > The documentation for assignment says: > > In all the assignment operator expressions, 'x' can be a name or > an expression defining a part of an object to be replaced (e.g., > 'z[[1]]'). A syntactic name does not need to be quoted, though it > can be

Re: [Rd] Assignment to string

2009-04-01 Thread Stavros Macrakis
On Wed, Apr 1, 2009 at 4:21 PM, Simon Urbanek wrote: > > On Apr 1, 2009, at 15:49 , Stavros Macrakis wrote: > > The documentation for assignment says: >> >>In all the assignment operator expressions, 'x' can be a name or >>an expression defining a part of an object to be replaced (e.g., >

Re: [Rd] Assignment to string

2009-04-01 Thread Simon Urbanek
On Apr 1, 2009, at 15:49 , Stavros Macrakis wrote: The documentation for assignment says: In all the assignment operator expressions, 'x' can be a name or an expression defining a part of an object to be replaced (e.g., 'z[[1]]'). A syntactic name does not need to be quoted, thoug

[Rd] Assignment to string

2009-04-01 Thread Stavros Macrakis
The documentation for assignment says: In all the assignment operator expressions, 'x' can be a name or an expression defining a part of an object to be replaced (e.g., 'z[[1]]'). A syntactic name does not need to be quoted, though it can be (preferably by backticks). But the