GithubHelp home page GithubHelp logo

Comments (1)

Zedseayou avatar Zedseayou commented on June 10, 2024

I think you're calling it wrong; s3_get_method takes a function name as string or symbol, specifically the full method name. This is different from s3_dispatch, which may cause the confusion. Here's an example:

library(sloop)
s3_methods_generic("all.equal")
#> # A tibble: 11 x 4
#>    generic   class       visible source
#>    <chr>     <chr>       <lgl>   <chr> 
#>  1 all.equal character   TRUE    base  
#>  2 all.equal default     TRUE    base  
#>  3 all.equal environment TRUE    base  
#>  4 all.equal envRefClass TRUE    base  
#>  5 all.equal factor      TRUE    base  
#>  6 all.equal formula     TRUE    base  
#>  7 all.equal language    TRUE    base  
#>  8 all.equal list        TRUE    base  
#>  9 all.equal numeric     TRUE    base  
#> 10 all.equal POSIXt      TRUE    base  
#> 11 all.equal raw         TRUE    base
s3_get_method(all.equal.numeric)
#> function (target, current, tolerance = sqrt(.Machine$double.eps), 
#>     scale = NULL, countEQ = FALSE, formatFUN = function(err, 
#>         what) format(err), ..., check.attributes = TRUE) 
#> {
#>     if (!is.numeric(tolerance)) 
#>         stop("'tolerance' should be numeric")
#>     if (!is.numeric(scale) && !is.null(scale)) 
#>         stop("'scale' should be numeric or NULL")
#>     if (!is.logical(check.attributes)) 
#>         stop(gettextf("'%s' must be logical", "check.attributes"), 
#>             domain = NA)
#>     msg <- if (check.attributes) 
#>         attr.all.equal(target, current, tolerance = tolerance, 
#>             scale = scale, ...)
#>     if (data.class(target) != data.class(current)) {
#>         msg <- c(msg, paste0("target is ", data.class(target), 
#>             ", current is ", data.class(current)))
#>         return(msg)
#>     }
#>     lt <- length(target)
#>     lc <- length(current)
#>     cplx <- is.complex(target)
#>     if (lt != lc) {
#>         if (!is.null(msg)) 
#>             msg <- msg[-grep("\\bLengths\\b", msg)]
#>         msg <- c(msg, paste0(if (cplx) "Complex" else "Numeric", 
#>             ": lengths (", lt, ", ", lc, ") differ"))
#>         return(msg)
#>     }
#>     target <- as.vector(target)
#>     current <- as.vector(current)
#>     out <- is.na(target)
#>     if (any(out != is.na(current))) {
#>         msg <- c(msg, paste("'is.NA' value mismatch:", sum(is.na(current)), 
#>             "in current", sum(out), "in target"))
#>         return(msg)
#>     }
#>     out <- out | target == current
#>     if (all(out)) 
#>         return(if (is.null(msg)) TRUE else msg)
#>     if (countEQ) {
#>         N <- length(out)
#>         sabst0 <- sum(abs(target[out]))
#>     }
#>     else sabst0 <- 0
#>     target <- target[!out]
#>     current <- current[!out]
#>     if (!countEQ) 
#>         N <- length(target)
#>     if (is.integer(target) && is.integer(current)) 
#>         target <- as.double(target)
#>     xy <- sum(abs(target - current))/N
#>     what <- if (is.null(scale)) {
#>         xn <- (sabst0 + sum(abs(target)))/N
#>         if (is.finite(xn) && xn > tolerance) {
#>             xy <- xy/xn
#>             "relative"
#>         }
#>         else "absolute"
#>     }
#>     else {
#>         stopifnot(all(scale > 0))
#>         xy <- xy/scale
#>         if (all(abs(scale - 1) < 1e-07)) 
#>             "absolute"
#>         else "scaled"
#>     }
#>     if (cplx) 
#>         what <- paste(what, "Mod")
#>     if (is.na(xy) || xy > tolerance) 
#>         msg <- c(msg, paste("Mean", what, "difference:", formatFUN(xy, 
#>             what)))
#>     if (is.null(msg)) 
#>         TRUE
#>     else msg
#> }
#> <bytecode: 0x7fc213926558>
#> <environment: namespace:base>

Created on 2019-11-27 by the reprex package (v0.3.0)

from sloop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.