Re: [Rd] class() |--> c("matrix", "arrary") -- and S3 dispatch
On 1/27/20 23:51, Martin Maechler wrote: >> Pages, Herve >> on Tue, 21 Jan 2020 17:33:01 + writes: > > > Dear Martin, > > What's the ETA for _R_CLASS_MATRIX_ARRAY_=TRUE to become the new > > unconditional behavior in R devel? Thanks! > > > H. > > Thank you, Hervé, for asking / reminding. > > It has been made so now, 3 days ago (svn r77714). Yep, I've seen that. Already deployed on the Bioconductor build machines. Thanks! H. > > Martin > > > > > > On 11/21/19 08:57, Martin Maechler wrote: > >> > >> TLDR: This is quite technical, still somewhat important: > >> 1) R 4.0.0 will become a bit more coherent: a matrix is an array > >> 2) Your package (or one you use) may be affected. > >> > >> > >>> Martin Maechler > >>> on Fri, 15 Nov 2019 17:31:15 +0100 writes: > >> > >>> Pages, Herve > >>> on Thu, 14 Nov 2019 19:13:47 + writes: > >> > >> >> On 11/14/19 05:47, Hadley Wickham wrote: > >> >>> On Sun, Nov 10, 2019 at 2:37 AM Martin Maechler ... wrote: > >> > >> [] > >> > >> > Note again that both "matrix" and "array" are special [see > ?class] as > >> > being of __implicit class__ and I am considering that this > >> > implicit class behavior for these two should be slightly > >> > changed > >> > > >> > And indeed I think you are right on spot and this would mean > >> > that indeed the implicit class > >> > "matrix" should rather become c("matrix", "array"). > >> > >> I've made up my mind (and not been contradicted by my fellow R > >> corers) to try go there for R 4.0.0 next April. > >> > >> >>> I can't seem to find the previous thread, so would you mind being > a > >> >>> bit more explicit here? Do you mean adding "array" to the implicit > >> >>> class? > >> > >> >> It's late in Europe ;-) > >> > >> >> That's my understanding. I think the plan is to have > class(matrix()) > >> >> return c("matrix", "array"). No class attributes added to matrix or > >> >> array objects. > >> > >> >> It's all what is needed to have inherits(matrix(), "array") return > TRUE > >> >> (instead of FALSE at the moment) and S3 dispatch pick up the > foo.array > >> >> method when foo(matrix()) is called and there is no foo.matrix > method. > >> > >> > Thank you, Hervé! That's exactly the plan. > >> > >> BUT it's wrong what I (and Peter and Hervé and ) had assumed: > >> > >> If I just change the class > >> (as I already did a few days ago, but you must activate the change > >> via environment variable, see below), > >> > >> S3 dispatch does *NOT* at all pick it up: > >> "matrix" (and "array") are even more special here (see below), > >> and from Hadley's questions, in hindsight I now see that he's been > aware > >> of that and I hereby apologize to Hadley for not having thought > >> and looked more, when he asked .. > >> > >> Half an hour ago, I've done another source code commit (svn r77446), > >> to "R-devel" only, of course, and the R-devel NEWS now starts as > >> > >> > >> > >> CHANGES IN R-devel: > >> > >> USER-VISIBLE CHANGES: > >> > >> • intention that the next non-patch release should be 4.0.0. > >> > >> • R now builds by default against a PCRE2 library > >> ... > >> ... > >> > >> • For now only active when environment variable > >> _R_CLASS_MATRIX_ARRAY_ is set to non-empty, but planned to be the > >> new unconditional behavior when R 4.0.0 is released: > >> > >> Newly, matrix objects also inherit from class "array", namely, > >> e.g., class(diag(1)) is c("matrix", "array") which invalidates > >> code (wrongly) assuming that length(class(obj)) == 1, a wrong > >> assumption that is less frequently fulfilled now. (Currently > >> only after setting _R_CLASS_MATRIX_ARRAY_ to non-empty.) > >> > >> S3 methods for "array", i.e., .array(), are now also > >> dispatched for matrix objects. > >> > >> > >> (where only the very last 1.5 lines paragraph is new.) > >> > >> Note the following > >> (if you use a version of R-devel, with svn rev >= 77446; which > >> you may get as a binary for Windows in about one day; everyone > >> else needs to compile for the sources .. or wait a bit, maybe > >> also not much longer than one day, for a docker image) : > >> > >> > >>> Sys.unsetenv("_R_CLASS_MATRIX_ARRAY_") # ==> current R behavior > >>> class(m <-
Re: [Rd] class() |--> c("matrix", "arrary") -- and S3 dispatch
> Pages, Herve > on Tue, 21 Jan 2020 17:33:01 + writes: > Dear Martin, > What's the ETA for _R_CLASS_MATRIX_ARRAY_=TRUE to become the new > unconditional behavior in R devel? Thanks! > H. Thank you, Hervé, for asking / reminding. It has been made so now, 3 days ago (svn r77714). Martin > On 11/21/19 08:57, Martin Maechler wrote: >> >> TLDR: This is quite technical, still somewhat important: >> 1) R 4.0.0 will become a bit more coherent: a matrix is an array >> 2) Your package (or one you use) may be affected. >> >> >>> Martin Maechler >>> on Fri, 15 Nov 2019 17:31:15 +0100 writes: >> >>> Pages, Herve >>> on Thu, 14 Nov 2019 19:13:47 + writes: >> >> >> On 11/14/19 05:47, Hadley Wickham wrote: >> >>> On Sun, Nov 10, 2019 at 2:37 AM Martin Maechler ... wrote: >> >> [] >> >> > Note again that both "matrix" and "array" are special [see ?class] as >> > being of __implicit class__ and I am considering that this >> > implicit class behavior for these two should be slightly >> > changed >> > >> > And indeed I think you are right on spot and this would mean >> > that indeed the implicit class >> > "matrix" should rather become c("matrix", "array"). >> >> I've made up my mind (and not been contradicted by my fellow R >> corers) to try go there for R 4.0.0 next April. >> >> >>> I can't seem to find the previous thread, so would you mind being a >> >>> bit more explicit here? Do you mean adding "array" to the implicit >> >>> class? >> >> >> It's late in Europe ;-) >> >> >> That's my understanding. I think the plan is to have class(matrix()) >> >> return c("matrix", "array"). No class attributes added to matrix or >> >> array objects. >> >> >> It's all what is needed to have inherits(matrix(), "array") return TRUE >> >> (instead of FALSE at the moment) and S3 dispatch pick up the foo.array >> >> method when foo(matrix()) is called and there is no foo.matrix method. >> >> > Thank you, Hervé! That's exactly the plan. >> >> BUT it's wrong what I (and Peter and Hervé and ) had assumed: >> >> If I just change the class >> (as I already did a few days ago, but you must activate the change >> via environment variable, see below), >> >> S3 dispatch does *NOT* at all pick it up: >> "matrix" (and "array") are even more special here (see below), >> and from Hadley's questions, in hindsight I now see that he's been aware >> of that and I hereby apologize to Hadley for not having thought >> and looked more, when he asked .. >> >> Half an hour ago, I've done another source code commit (svn r77446), >> to "R-devel" only, of course, and the R-devel NEWS now starts as >> >> >> >> CHANGES IN R-devel: >> >> USER-VISIBLE CHANGES: >> >> • intention that the next non-patch release should be 4.0.0. >> >> • R now builds by default against a PCRE2 library >> ... >> ... >> >> • For now only active when environment variable >> _R_CLASS_MATRIX_ARRAY_ is set to non-empty, but planned to be the >> new unconditional behavior when R 4.0.0 is released: >> >> Newly, matrix objects also inherit from class "array", namely, >> e.g., class(diag(1)) is c("matrix", "array") which invalidates >> code (wrongly) assuming that length(class(obj)) == 1, a wrong >> assumption that is less frequently fulfilled now. (Currently >> only after setting _R_CLASS_MATRIX_ARRAY_ to non-empty.) >> >> S3 methods for "array", i.e., .array(), are now also >> dispatched for matrix objects. >> >> >> (where only the very last 1.5 lines paragraph is new.) >> >> Note the following >> (if you use a version of R-devel, with svn rev >= 77446; which >> you may get as a binary for Windows in about one day; everyone >> else needs to compile for the sources .. or wait a bit, maybe >> also not much longer than one day, for a docker image) : >> >> >>> Sys.unsetenv("_R_CLASS_MATRIX_ARRAY_") # ==> current R behavior >>> class(m <- diag(1)) >> [1] "matrix" >>> Sys.setenv("_R_CLASS_MATRIX_ARRAY_" = "BOOH !") # ==> future R behavior >>> class(m) >> [1] "matrix" "array" >>> >>> foo <- function(x) UseMethod("foo") >>> foo.array <- function(x) "made in foo.array()" >>> foo(m) >> [1] "made in foo.array()" >>> Sys.unsetenv("_R_CLASS_MATRIX_ARRAY_")# ==> current R behavior >>> foo(m) >> Error in UseMethod("foo") : >> no applicable
Re: [Rd] class() |--> c("matrix", "arrary") -- and S3 dispatch
Dear Martin, What's the ETA for _R_CLASS_MATRIX_ARRAY_=TRUE to become the new unconditional behavior in R devel? Thanks! H. On 11/21/19 08:57, Martin Maechler wrote: > > TLDR: This is quite technical, still somewhat important: > 1) R 4.0.0 will become a bit more coherent: a matrix is an array > 2) Your package (or one you use) may be affected. > > >> Martin Maechler >> on Fri, 15 Nov 2019 17:31:15 +0100 writes: > >> Pages, Herve >> on Thu, 14 Nov 2019 19:13:47 + writes: > > >> On 11/14/19 05:47, Hadley Wickham wrote: > >>> On Sun, Nov 10, 2019 at 2:37 AM Martin Maechler ... wrote: > > [] > > > Note again that both "matrix" and "array" are special [see ?class] > as > > being of __implicit class__ and I am considering that this > > implicit class behavior for these two should be slightly > > changed > > > > And indeed I think you are right on spot and this would mean > > that indeed the implicit class > > "matrix" should rather become c("matrix", "array"). > > I've made up my mind (and not been contradicted by my fellow R > corers) to try go there for R 4.0.0 next April. > > >>> I can't seem to find the previous thread, so would you mind being a > >>> bit more explicit here? Do you mean adding "array" to the implicit > >>> class? > > >> It's late in Europe ;-) > > >> That's my understanding. I think the plan is to have class(matrix()) > >> return c("matrix", "array"). No class attributes added to matrix or > >> array objects. > > >> It's all what is needed to have inherits(matrix(), "array") return > TRUE > >> (instead of FALSE at the moment) and S3 dispatch pick up the foo.array > >> method when foo(matrix()) is called and there is no foo.matrix method. > > > Thank you, Hervé! That's exactly the plan. > > BUT it's wrong what I (and Peter and Hervé and ) had assumed: > > If I just change the class > (as I already did a few days ago, but you must activate the change >via environment variable, see below), > > S3 dispatch does *NOT* at all pick it up: > "matrix" (and "array") are even more special here (see below), > and from Hadley's questions, in hindsight I now see that he's been aware > of that and I hereby apologize to Hadley for not having thought > and looked more, when he asked .. > > Half an hour ago, I've done another source code commit (svn r77446), > to "R-devel" only, of course, and the R-devel NEWS now starts as > > > > CHANGES IN R-devel: > >USER-VISIBLE CHANGES: > > • intention that the next non-patch release should be 4.0.0. > > • R now builds by default against a PCRE2 library >... >... > > • For now only active when environment variable >_R_CLASS_MATRIX_ARRAY_ is set to non-empty, but planned to be the >new unconditional behavior when R 4.0.0 is released: > >Newly, matrix objects also inherit from class "array", namely, >e.g., class(diag(1)) is c("matrix", "array") which invalidates >code (wrongly) assuming that length(class(obj)) == 1, a wrong >assumption that is less frequently fulfilled now. (Currently >only after setting _R_CLASS_MATRIX_ARRAY_ to non-empty.) > >S3 methods for "array", i.e., .array(), are now also >dispatched for matrix objects. > > > (where only the very last 1.5 lines paragraph is new.) > > Note the following > (if you use a version of R-devel, with svn rev >= 77446; which > you may get as a binary for Windows in about one day; everyone > else needs to compile for the sources .. or wait a bit, maybe > also not much longer than one day, for a docker image) : > > >> Sys.unsetenv("_R_CLASS_MATRIX_ARRAY_") # ==> current R behavior >> class(m <- diag(1)) > [1] "matrix" >> Sys.setenv("_R_CLASS_MATRIX_ARRAY_" = "BOOH !") # ==> future R behavior >> class(m) > [1] "matrix" "array" >> >> foo <- function(x) UseMethod("foo") >> foo.array <- function(x) "made in foo.array()" >> foo(m) > [1] "made in foo.array()" >> Sys.unsetenv("_R_CLASS_MATRIX_ARRAY_")# ==> current R behavior >> foo(m) > Error in UseMethod("foo") : >no applicable method for 'foo' applied to an object of class "c('matrix', > 'double', 'numeric')" > >> Sys.setenv("_R_CLASS_MATRIX_ARRAY_" = TRUE) # ==> future R behavior >> foo(m) > [1] "made in foo.array()" >> foo.A <- foo.array ; rm(foo.array) >> foo(m) > Error in UseMethod("foo") : >no applicable method for 'foo' applied to an object of class "c('matrix', > 'array', 'double', 'numeric')" >> > > So, with my commit 77446, the _R_CLASS_MATRIX_ARRAY_ > environment variable also changes
Re: [Rd] class() |--> c("matrix", "arrary") -- and S3 dispatch
In case if anyone needs daily R-devel there is my build scheduled on GitLab. As of now based on Ubuntu 16.04, R built using: --with-recommended-packages --enable-strict-barrier --disable-long-double Predefined Makevars for building pkgs using: -g -O2 -Wall -pedantic -fstack-protector-strong -D_FORTIFY_SOURCE=2 $ docker run --rm -ti registry.gitlab.com/jangorecki/dockerfiles/r-devel:latest R Under development (unstable) (2019-11-23 r77455) -- "Unsuffered Consequences" Copyright (C) 2019 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > Sys.setenv("_R_CLASS_MATRIX_ARRAY_" = "BOOH !") > class(m <- diag(1)) [1] "matrix" "array" On Mon, Nov 25, 2019 at 10:31 PM Dirk Eddelbuettel wrote: > > > On 21 November 2019 at 17:57, Martin Maechler wrote: > | (if you use a version of R-devel, with svn rev >= 77446; which > | you may get as a binary for Windows in about one day; everyone > | else needs to compile for the sources .. or wait a bit, maybe > | also not much longer than one day, for a docker image) : > > FYI: rocker/drd [1] and rocker/r-devel both have rev 77455 now (as they are > both on weekend auto-rebuild schedule). The former is smaller, both should > work to test this. Quick demo below [2]. > > Dirk > > [1] This comes from 'drd == daily r-devel' but we do not build it daily. > [2] Quick demo follows > > edd@rob:~$ docker run --rm -ti rocker/r-devel bash > root@a30e4a5c89ba:/# RD > > R Under development (unstable) (2019-11-23 r77455) -- "Unsuffered > Consequences" > Copyright (C) 2019 The R Foundation for Statistical Computing > Platform: x86_64-pc-linux-gnu (64-bit) > > R is free software and comes with ABSOLUTELY NO WARRANTY. > You are welcome to redistribute it under certain conditions. > Type 'license()' or 'licence()' for distribution details. > > Natural language support but running in an English locale > > R is a collaborative project with many contributors. > Type 'contributors()' for more information and > 'citation()' on how to cite R or R packages in publications. > > Type 'demo()' for some demos, 'help()' for on-line help, or > 'help.start()' for an HTML browser interface to help. > Type 'q()' to quit R. > > > Sys.setenv("_R_CLASS_MATRIX_ARRAY_" = "BOOH !") # ==> future R behavior > > class(m <- diag(1)) > [1] "matrix" "array" > > > > -- > http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org > > __ > 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] class() |--> c("matrix", "arrary") -- and S3 dispatch
On 21 November 2019 at 17:57, Martin Maechler wrote: | (if you use a version of R-devel, with svn rev >= 77446; which | you may get as a binary for Windows in about one day; everyone | else needs to compile for the sources .. or wait a bit, maybe | also not much longer than one day, for a docker image) : FYI: rocker/drd [1] and rocker/r-devel both have rev 77455 now (as they are both on weekend auto-rebuild schedule). The former is smaller, both should work to test this. Quick demo below [2]. Dirk [1] This comes from 'drd == daily r-devel' but we do not build it daily. [2] Quick demo follows edd@rob:~$ docker run --rm -ti rocker/r-devel bash root@a30e4a5c89ba:/# RD R Under development (unstable) (2019-11-23 r77455) -- "Unsuffered Consequences" Copyright (C) 2019 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > Sys.setenv("_R_CLASS_MATRIX_ARRAY_" = "BOOH !") # ==> future R behavior > class(m <- diag(1)) [1] "matrix" "array" > -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] class() |--> c("matrix", "arrary") -- and S3 dispatch
TLDR: This is quite technical, still somewhat important: 1) R 4.0.0 will become a bit more coherent: a matrix is an array 2) Your package (or one you use) may be affected. > Martin Maechler > on Fri, 15 Nov 2019 17:31:15 +0100 writes: > Pages, Herve > on Thu, 14 Nov 2019 19:13:47 + writes: >> On 11/14/19 05:47, Hadley Wickham wrote: >>> On Sun, Nov 10, 2019 at 2:37 AM Martin Maechler ... wrote: [] > Note again that both "matrix" and "array" are special [see ?class] as > being of __implicit class__ and I am considering that this > implicit class behavior for these two should be slightly > changed > > And indeed I think you are right on spot and this would mean > that indeed the implicit class > "matrix" should rather become c("matrix", "array"). I've made up my mind (and not been contradicted by my fellow R corers) to try go there for R 4.0.0 next April. >>> I can't seem to find the previous thread, so would you mind being a >>> bit more explicit here? Do you mean adding "array" to the implicit >>> class? >> It's late in Europe ;-) >> That's my understanding. I think the plan is to have class(matrix()) >> return c("matrix", "array"). No class attributes added to matrix or >> array objects. >> It's all what is needed to have inherits(matrix(), "array") return TRUE >> (instead of FALSE at the moment) and S3 dispatch pick up the foo.array >> method when foo(matrix()) is called and there is no foo.matrix method. > Thank you, Hervé! That's exactly the plan. BUT it's wrong what I (and Peter and Hervé and ) had assumed: If I just change the class (as I already did a few days ago, but you must activate the change via environment variable, see below), S3 dispatch does *NOT* at all pick it up: "matrix" (and "array") are even more special here (see below), and from Hadley's questions, in hindsight I now see that he's been aware of that and I hereby apologize to Hadley for not having thought and looked more, when he asked .. Half an hour ago, I've done another source code commit (svn r77446), to "R-devel" only, of course, and the R-devel NEWS now starts as CHANGES IN R-devel: USER-VISIBLE CHANGES: • intention that the next non-patch release should be 4.0.0. • R now builds by default against a PCRE2 library ... ... • For now only active when environment variable _R_CLASS_MATRIX_ARRAY_ is set to non-empty, but planned to be the new unconditional behavior when R 4.0.0 is released: Newly, matrix objects also inherit from class "array", namely, e.g., class(diag(1)) is c("matrix", "array") which invalidates code (wrongly) assuming that length(class(obj)) == 1, a wrong assumption that is less frequently fulfilled now. (Currently only after setting _R_CLASS_MATRIX_ARRAY_ to non-empty.) S3 methods for "array", i.e., .array(), are now also dispatched for matrix objects. (where only the very last 1.5 lines paragraph is new.) Note the following (if you use a version of R-devel, with svn rev >= 77446; which you may get as a binary for Windows in about one day; everyone else needs to compile for the sources .. or wait a bit, maybe also not much longer than one day, for a docker image) : > Sys.unsetenv("_R_CLASS_MATRIX_ARRAY_") # ==> current R behavior > class(m <- diag(1)) [1] "matrix" > Sys.setenv("_R_CLASS_MATRIX_ARRAY_" = "BOOH !") # ==> future R behavior > class(m) [1] "matrix" "array" > > foo <- function(x) UseMethod("foo") > foo.array <- function(x) "made in foo.array()" > foo(m) [1] "made in foo.array()" > Sys.unsetenv("_R_CLASS_MATRIX_ARRAY_")# ==> current R behavior > foo(m) Error in UseMethod("foo") : no applicable method for 'foo' applied to an object of class "c('matrix', 'double', 'numeric')" > Sys.setenv("_R_CLASS_MATRIX_ARRAY_" = TRUE) # ==> future R behavior > foo(m) [1] "made in foo.array()" > foo.A <- foo.array ; rm(foo.array) > foo(m) Error in UseMethod("foo") : no applicable method for 'foo' applied to an object of class "c('matrix', 'array', 'double', 'numeric')" > So, with my commit 77446, the _R_CLASS_MATRIX_ARRAY_ environment variable also changes the "S3 dispatch determining class" mentioned as 'class' in the error message (of the two cases, old and new) above, which in R <= 3.6.x for a numeric matrix is c('matrix', 'double', 'numeric') and from R 4.0.0 on will be c('matrix', 'array', 'double', 'numeric') Note that this is *not* (in R <= 3.6.x, nor very probably in R 4.0.0) the same as R's class(). Hadley calls this long class vector the 'implicit class' -