Henrik Bengtsson
2016-Oct-12 16:20 UTC
[Rd] How to assign NULL value to pairlist element while keeping it a pairlist?
Hi, I seem to not be able to assign NULL to an element of a pairlist without causing it to be coerced to a plain list. For example:> x <- pairlist(1, 2) > class(x)[1] "pairlist"> x[1] <- list(NULL) > class(x)[1] "list" This actually true for all [()<- assignments regardless of list value, e.g.> x <- pairlist(1, 2) > x[1] <- list(0)[1] "list" I also tried assigning a pairlist(), but still the same problem:> x <- pairlist(1, 2) > x[1] <- pairlist(0)[1] "list" The only workaround I'm aware of is to: x <- as.pairlist(x) at the end. Any other suggestions? Thanks, Henrik
Michael Lawrence
2016-Oct-12 16:40 UTC
[Rd] How to assign NULL value to pairlist element while keeping it a pairlist?
The coercion is probably the most viable workaround for now, as it's consistent with what happens internally for calls. All pairlists/calls are converted to list for subassignment, but only calls are converted back. My guess is that the intent was for users to move from using a pairlist to the "new" (almost 20 years ago) list. In my opinion, consistency trumps "convenience" in this case. If others agree, I'll change it to also coerce back to pairlist. Michael On Wed, Oct 12, 2016 at 9:20 AM, Henrik Bengtsson <henrik.bengtsson at gmail.com> wrote:> Hi, I seem to not be able to assign NULL to an element of a pairlist > without causing it to be coerced to a plain list. For example: > >> x <- pairlist(1, 2) >> class(x) > [1] "pairlist" > >> x[1] <- list(NULL) >> class(x) > [1] "list" > > This actually true for all [()<- assignments regardless of list value, e.g. > >> x <- pairlist(1, 2) >> x[1] <- list(0) > [1] "list" > > I also tried assigning a pairlist(), but still the same problem: > >> x <- pairlist(1, 2) >> x[1] <- pairlist(0) > [1] "list" > > The only workaround I'm aware of is to: > > x <- as.pairlist(x) > > at the end. Any other suggestions? > > Thanks, > > Henrik > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Michael Lawrence
2016-Oct-12 17:53 UTC
[Rd] How to assign NULL value to pairlist element while keeping it a pairlist?
Hi Henrik, It would help to understand your use case for pairlists. Thanks, Michael On Wed, Oct 12, 2016 at 9:40 AM, Michael Lawrence <michafla at gene.com> wrote:> The coercion is probably the most viable workaround for now, as it's > consistent with what happens internally for calls. All pairlists/calls > are converted to list for subassignment, but only calls are converted > back. My guess is that the intent was for users to move from using a > pairlist to the "new" (almost 20 years ago) list. In my opinion, > consistency trumps "convenience" in this case. If others agree, I'll > change it to also coerce back to pairlist. > > Michael > > On Wed, Oct 12, 2016 at 9:20 AM, Henrik Bengtsson > <henrik.bengtsson at gmail.com> wrote: >> Hi, I seem to not be able to assign NULL to an element of a pairlist >> without causing it to be coerced to a plain list. For example: >> >>> x <- pairlist(1, 2) >>> class(x) >> [1] "pairlist" >> >>> x[1] <- list(NULL) >>> class(x) >> [1] "list" >> >> This actually true for all [()<- assignments regardless of list value, e.g. >> >>> x <- pairlist(1, 2) >>> x[1] <- list(0) >> [1] "list" >> >> I also tried assigning a pairlist(), but still the same problem: >> >>> x <- pairlist(1, 2) >>> x[1] <- pairlist(0) >> [1] "list" >> >> The only workaround I'm aware of is to: >> >> x <- as.pairlist(x) >> >> at the end. Any other suggestions? >> >> Thanks, >> >> Henrik >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel
Maybe Matching Threads
- How to assign NULL value to pairlist element while keeping it a pairlist?
- How to assign NULL value to pairlist element while keeping it a pairlist?
- How to assign NULL value to pairlist element while keeping it a pairlist?
- How to assign NULL value to pairlist element while keeping it a pairlist?
- How to assign NULL value to pairlist element while keeping it a pairlist?