Issues with devtools::load_all() and exported S3 methods

It seems that devtools::load_all() does not load exported S3methods. I noticed that recently. However I'm not sure that's because I moved from R 4.0.3 to R 4.0.4.

A reprex is difficult in that situation, so I post here the content of the package:

R/test.R

#' @export
test <- function(x){
 UseMethod(x)
}

#' @export
test.default <- function(x){
 x^2
}

#' @export
test.character <- function(x){
 cat(x)
}

DESCRIPTION

Package: test
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: Who wrote it
Maintainer: The package maintainer <yourself@somewhere.net>
Description: More about what it does (maybe more than one line)
    Use four spaces when indenting paragraphs within the Description.
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1

NAMESPACE

# Generated by roxygen2: do not edit by hand

S3method(test,character)
S3method(test,default)
export(test)

inst/script.R

devtools::load_all()
test("test.character")
#> Error in UseMethod(x) : no applicable method for 'test.character' applied to an object of class "character"
test.character("test.character")
#> test.character
test(25)
#>  Error in UseMethod(x) : 'generic' argument must be a character string
test.default(25)
#> 625

Session info

─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.0.4 (2021-02-15)
 os       Ubuntu 20.10                
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  fr_FR.UTF-8                 
 ctype    fr_FR.UTF-8                 
 tz       Europe/Paris                
 date     2021-03-02                  

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date       lib source        
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)
 cachem        1.0.4   2021-02-13 [1] CRAN (R 4.0.3)
 callr         3.5.1   2020-10-13 [1] CRAN (R 4.0.3)
 cli           2.3.1   2021-02-23 [1] CRAN (R 4.0.4)
 crayon        1.4.1   2021-02-08 [1] CRAN (R 4.0.3)
 desc          1.2.0   2018-05-01 [1] CRAN (R 4.0.2)
 devtools      2.3.2   2020-09-18 [1] CRAN (R 4.0.4)
 ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.2)
 fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.0.3)
 fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)
 glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
 lifecycle     1.0.0   2021-02-15 [1] CRAN (R 4.0.3)
 magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.3)
 memoise       2.0.0   2021-01-26 [1] CRAN (R 4.0.3)
 pkgbuild      1.2.0   2020-12-15 [1] CRAN (R 4.0.3)
 pkgload       1.2.0   2021-02-23 [1] CRAN (R 4.0.4)
 prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.2)
 processx      3.4.5   2020-11-30 [1] CRAN (R 4.0.3)
 ps            1.6.0   2021-02-28 [1] CRAN (R 4.0.4)
 purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.2)
 R6            2.5.0   2020-10-28 [1] CRAN (R 4.0.3)
 remotes       2.2.0   2020-07-21 [1] CRAN (R 4.0.2)
 rlang         0.4.10  2020-12-30 [1] CRAN (R 4.0.3)
 rprojroot     2.0.2   2020-11-15 [1] CRAN (R 4.0.3)
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)
 testthat      3.0.2   2021-02-14 [1] CRAN (R 4.0.3)
 usethis       2.0.1   2021-02-10 [1] CRAN (R 4.0.4)
 withr         2.4.1   2021-01-26 [1] CRAN (R 4.0.3)

[1] /home/kevin/R/x86_64-pc-linux-gnu-library/4.0
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library

Your call to UseMethod() is incorrect.

You need to give it the name of the generic not pass it the argument value. e.g. UseMethod("test")

That's correct, I created dozens of generics and methods but still making silly mistakes! Thank you

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.