[Rd] integerOneIndex/get1index/... in vector access error messages
Hi! We noticed that these error messages were changed to include the name of the function that causes them: > { x<-c(1,2); x[[c("a", "b")]] } old: “Error in x[[c("a", "b")]] : attempt to select more than one element” new: “Error in x[[c("a", "b")]] : attempt to select more than one element in vectorIndex” This is the relevant change: https://github.com/wch/r-source/commit/5d6c765bf8b97bf872f760d06622850f43696d8b I don’t think that a user of R is supposed to know the difference between, e.g., integerOneIndex and get1index, so this will confuse, rather than help, a user while diagnosing problems. To be honest, this looks to me like leftover debug code... In FastR, we try to adhere as closely as possible to GNUR in which errors are returned when. Do you think that providing these “in Xyz” suffixes is important? - Lukas __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [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 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@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [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 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 > 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@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to assign NULL value to pairlist element while keeping it a pairlist?
Michael, thanks for this info. I've stumbled upon this in a case where I walk an R expression (the AST) and (optionally) modifies it (part of the globals package). In R expressions, a function definition uses a pairlist to represent the arguments. For example, > expr <- quote(function(x = 1) x) > str(as.list(expr)) List of 4 $ : symbol function $ :Dotted pair list of 1 ..$ x: num 1 $ : symbol x $ :Class 'srcref' atomic [1:8] 1 15 1 29 15 29 1 1 .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' Here the 2nd element is a pairlist: > str(expr[[2]]) Dotted pair list of 1 $ x: num 1 > typeof(expr[[2]]) [1] "pairlist" Now say that I want to update the default value of argument 'x', which is currently 1, to NULL. Then I do: > expr[[2]][1] <- list(x = NULL) At this step, I end up with an expression 'expr' where the arguments are no longer represented by a pairlist: > str(expr[[2]]) List of 1 $ x: NULL > typeof(expr[[2]]) [1] "list" More importantly, at this point 'expr' no longer holds a valid R expression: > expr Error: badly formed function expression The solution is to make sure we have a pairlist: > expr[[2]] <- as.pairlist(expr[[2]]) > expr function(x = NULL) x I agree it would be nice to fix this for consistency, but if you bump into major issues, at least I can live with having to use an explicit as.pairlist(). Thanks Henrik On Wed, Oct 12, 2016 at 10:53 AM, Michael Lawrence wrote: > 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 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 >> 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@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to assign NULL value to pairlist element while keeping it a pairlist?
Thanks, this was what I expected. There is a desire to eliminate the usage of pairlist from user code, which suggests the alternative of allowing for function arguments to be stored in lists. That's a much deeper change though. On Wed, Oct 12, 2016 at 12:31 PM, Henrik Bengtsson wrote: > Michael, thanks for this info. > > I've stumbled upon this in a case where I walk an R expression (the > AST) and (optionally) modifies it (part of the globals package). In R > expressions, a function definition uses a pairlist to represent the > arguments. For example, > >> expr <- quote(function(x = 1) x) >> str(as.list(expr)) > List of 4 > $ : symbol function > $ :Dotted pair list of 1 > ..$ x: num 1 > $ : symbol x > $ :Class 'srcref' atomic [1:8] 1 15 1 29 15 29 1 1 > .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' > > > Here the 2nd element is a pairlist: > >> str(expr[[2]]) > Dotted pair list of 1 > $ x: num 1 >> typeof(expr[[2]]) > [1] "pairlist" > > Now say that I want to update the default value of argument 'x', which > is currently 1, to NULL. Then I do: > >> expr[[2]][1] <- list(x = NULL) > > At this step, I end up with an expression 'expr' where the arguments > are no longer represented by a pairlist: > >> str(expr[[2]]) > List of 1 > $ x: NULL >> typeof(expr[[2]]) > [1] "list" > > More importantly, at this point 'expr' no longer holds a valid R expression: > >> expr > Error: badly formed function expression > > The solution is to make sure we have a pairlist: > >> expr[[2]] <- as.pairlist(expr[[2]]) >> expr > function(x = NULL) x > > > I agree it would be nice to fix this for consistency, but if you bump > into major issues, at least I can live with having to use an explicit > as.pairlist(). > > Thanks > > Henrik > > On Wed, Oct 12, 2016 at 10:53 AM, Michael Lawrence > wrote: >> 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 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 >>> 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel