Kurt Hornik
2020-Aug-20 07:58 UTC
[Rd] utils::isS3stdGeneric chokes on primitives and identity
>>>>> Gabriel Becker writes:> I added that so I can look at the proposed fix and put it or something > similar in bugzilla for review final review.> Apologies for the oversight.Fixed now with - while(as.character(bdexpr[[1L]]) == "{") + while(is.call(bdexpr) && (as.character(bdexpr[[1L]]) == "{")) (the suggested fix does not work on things like foo <- function(x) {{ x }} ...) Best -k> ~G> On Wed, Aug 19, 2020 at 3:40 PM Antoine Fabri <antoine.fabri at gmail.com> > wrote:>> Dear R-devel, >> >> utils::isS3stdGeneric tries to subset the body of the function it's fed, >> primitives don't like that because they don't have a body, identity doesn't >> like it either because it's body is a symbol. >> >> According to the doc, any function is a legal input. >> >> See below: >> >> identity >> #> function (x) >> #> x >> #> <bytecode: 0x0000000013d6da28> >> #> <environment: namespace:base> >> >> max >> #> function (..., na.rm = FALSE) .Primitive("max") >> >> isS3stdGeneric(identity) >> #> Error in bdexpr[[1L]]: objet de type 'symbol' non indi?able >> >> isS3stdGeneric(max) >> #> Error in while (as.character(bdexpr[[1L]]) == "{") bdexpr <- >> bdexpr[[2L]]: l'argument est de longueur nulle >> >> Here is a simple fix : >> >> isS3stdGeneric <- function(f) { >> { >> bdexpr <- body(f) >> if(is.null(bdexpr) || !is.call(bdexpr)) return(FALSE) >> while (as.character(bdexpr[[1L]]) == "{") bdexpr <- bdexpr[[2L]] >> ret <- is.call(bdexpr) && identical(bdexpr[[1L]], as.name >> ("UseMethod")) >> if (ret) >> names(ret) <- bdexpr[[2L]] >> ret >> } >> } >> >> isS3stdGeneric(identity) >> #> [1] FALSE >> isS3stdGeneric(max) >> #> [1] FALSE >> >> Best, >> >> Antoine >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >>> [[alternative HTML version deleted]]> ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Antoine Fabri
2020-Aug-27 18:22 UTC
[Rd] utils::isS3stdGeneric chokes on primitives and identity
Should it work on traced functions ? As it is now it doesn't. Best, Antoine Le jeu. 20 ao?t 2020 ? 09:58, Kurt Hornik <Kurt.Hornik at wu.ac.at> a ?crit :> >>>>> Gabriel Becker writes: > > > I added that so I can look at the proposed fix and put it or something > > similar in bugzilla for review final review. > > > Apologies for the oversight. > > Fixed now with > > - while(as.character(bdexpr[[1L]]) == "{") > + while(is.call(bdexpr) && (as.character(bdexpr[[1L]]) == "{")) > > (the suggested fix does not work on things like > foo <- function(x) {{ x }} > ...) > > Best > -k > > > ~G > > > On Wed, Aug 19, 2020 at 3:40 PM Antoine Fabri <antoine.fabri at gmail.com> > > wrote: > > >> Dear R-devel, > >> > >> utils::isS3stdGeneric tries to subset the body of the function it's fed, > >> primitives don't like that because they don't have a body, identity > doesn't > >> like it either because it's body is a symbol. > >> > >> According to the doc, any function is a legal input. > >> > >> See below: > >> > >> identity > >> #> function (x) > >> #> x > >> #> <bytecode: 0x0000000013d6da28> > >> #> <environment: namespace:base> > >> > >> max > >> #> function (..., na.rm = FALSE) .Primitive("max") > >> > >> isS3stdGeneric(identity) > >> #> Error in bdexpr[[1L]]: objet de type 'symbol' non indi?able > >> > >> isS3stdGeneric(max) > >> #> Error in while (as.character(bdexpr[[1L]]) == "{") bdexpr <- > >> bdexpr[[2L]]: l'argument est de longueur nulle > >> > >> Here is a simple fix : > >> > >> isS3stdGeneric <- function(f) { > >> { > >> bdexpr <- body(f) > >> if(is.null(bdexpr) || !is.call(bdexpr)) return(FALSE) > >> while (as.character(bdexpr[[1L]]) == "{") bdexpr <- bdexpr[[2L]] > >> ret <- is.call(bdexpr) && identical(bdexpr[[1L]], as.name > >> ("UseMethod")) > >> if (ret) > >> names(ret) <- bdexpr[[2L]] > >> ret > >> } > >> } > >> > >> isS3stdGeneric(identity) > >> #> [1] FALSE > >> isS3stdGeneric(max) > >> #> [1] FALSE > >> > >> Best, > >> > >> Antoine > >> > >> [[alternative HTML version deleted]] > >> > >> ______________________________________________ > >> R-devel at r-project.org mailing list > >> https://stat.ethz.ch/mailman/listinfo/r-devel > >> > > > [[alternative HTML version deleted]] > > > ______________________________________________ > > R-devel at r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel >[[alternative HTML version deleted]]
Gabriel Becker
2020-Aug-28 00:28 UTC
[Rd] utils::isS3stdGeneric chokes on primitives and identity
Trace adds something to the body of the function, so it does make sense that it doesn't. Whether traced functions still technically meet the definition of standard s3 generic or not is, I suppose, up for debate, but I would say that they should, I think. As before, if desired I can work on a patch for this if desired, or someone on R-core can just take care of it if that is easier. Best, ~G On Thu, Aug 27, 2020 at 11:22 AM Antoine Fabri <antoine.fabri at gmail.com> wrote:> Should it work on traced functions ? > > As it is now it doesn't. > > Best, > > Antoine > > Le jeu. 20 ao?t 2020 ? 09:58, Kurt Hornik <Kurt.Hornik at wu.ac.at> a ?crit : > >> >>>>> Gabriel Becker writes: >> >> > I added that so I can look at the proposed fix and put it or something >> > similar in bugzilla for review final review. >> >> > Apologies for the oversight. >> >> Fixed now with >> >> - while(as.character(bdexpr[[1L]]) == "{") >> + while(is.call(bdexpr) && (as.character(bdexpr[[1L]]) == "{")) >> >> (the suggested fix does not work on things like >> foo <- function(x) {{ x }} >> ...) >> >> Best >> -k >> >> > ~G >> >> > On Wed, Aug 19, 2020 at 3:40 PM Antoine Fabri <antoine.fabri at gmail.com> >> > wrote: >> >> >> Dear R-devel, >> >> >> >> utils::isS3stdGeneric tries to subset the body of the function it's >> fed, >> >> primitives don't like that because they don't have a body, identity >> doesn't >> >> like it either because it's body is a symbol. >> >> >> >> According to the doc, any function is a legal input. >> >> >> >> See below: >> >> >> >> identity >> >> #> function (x) >> >> #> x >> >> #> <bytecode: 0x0000000013d6da28> >> >> #> <environment: namespace:base> >> >> >> >> max >> >> #> function (..., na.rm = FALSE) .Primitive("max") >> >> >> >> isS3stdGeneric(identity) >> >> #> Error in bdexpr[[1L]]: objet de type 'symbol' non indi?able >> >> >> >> isS3stdGeneric(max) >> >> #> Error in while (as.character(bdexpr[[1L]]) == "{") bdexpr <- >> >> bdexpr[[2L]]: l'argument est de longueur nulle >> >> >> >> Here is a simple fix : >> >> >> >> isS3stdGeneric <- function(f) { >> >> { >> >> bdexpr <- body(f) >> >> if(is.null(bdexpr) || !is.call(bdexpr)) return(FALSE) >> >> while (as.character(bdexpr[[1L]]) == "{") bdexpr <- bdexpr[[2L]] >> >> ret <- is.call(bdexpr) && identical(bdexpr[[1L]], as.name >> >> ("UseMethod")) >> >> if (ret) >> >> names(ret) <- bdexpr[[2L]] >> >> ret >> >> } >> >> } >> >> >> >> isS3stdGeneric(identity) >> >> #> [1] FALSE >> >> isS3stdGeneric(max) >> >> #> [1] FALSE >> >> >> >> Best, >> >> >> >> Antoine >> >> >> >> [[alternative HTML version deleted]] >> >> >> >> ______________________________________________ >> >> R-devel at r-project.org mailing list >> >> https://stat.ethz.ch/mailman/listinfo/r-devel >> >> >> >> > [[alternative HTML version deleted]] >> >> > ______________________________________________ >> > R-devel at r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-devel >> >[[alternative HTML version deleted]]
Seemingly Similar Threads
- utils::isS3stdGeneric chokes on primitives and identity
- utils::isS3stdGeneric chokes on primitives and identity
- utils::isS3stdGeneric chokes on primitives and identity
- utils::isS3stdGeneric chokes on primitives and identity
- utils::isS3stdGeneric chokes on primitives and identity