├── .github ├── .gitignore ├── workflows │ ├── pkgdown.yaml │ ├── test-coverage.yaml │ ├── R-CMD-check.yaml │ └── pr-commands.yaml └── CODE_OF_CONDUCT.md ├── revdep ├── README.md ├── failures.md ├── problems.md ├── .gitignore ├── data.sqlite ├── email.yml └── cran.md ├── LICENSE ├── tests ├── testthat.R └── testthat │ ├── testSameRd │ ├── NAMESPACE │ ├── DESCRIPTION │ ├── man │ │ ├── same_rd_name.Rd │ │ └── same_rd_name-2.Rd │ └── R │ │ └── a.R │ ├── testMultiPackage │ ├── NAMESPACE │ ├── R │ │ └── a.R │ ├── DESCRIPTION │ └── man │ │ └── multi-method-4.Rd │ ├── testS4Docs │ ├── NAMESPACE │ ├── DESCRIPTION │ ├── R │ │ └── a.R │ └── man │ │ └── multi_method.Rd │ ├── testSingleMethod │ ├── NAMESPACE │ ├── DESCRIPTION │ ├── man │ │ ├── single-method.Rd │ │ └── single-method-2.Rd │ └── R │ │ └── a.R │ ├── testGenericsExtension │ ├── NAMESPACE │ ├── R │ │ └── a.R │ ├── DESCRIPTION │ └── man │ │ ├── tidy-special.Rd │ │ └── reexports.Rd │ ├── testMultiMethod │ ├── NAMESPACE │ ├── DESCRIPTION │ ├── man │ │ ├── multi-method-2.Rd │ │ ├── multi-method.Rd │ │ └── multi-method-3.Rd │ └── R │ │ └── a.R │ ├── test-docs.R │ └── _snaps │ └── docs.md ├── cran-comments.md ├── R ├── utils.R ├── varying_args.R ├── calculate.R ├── prune.R ├── refit.R ├── fit.R ├── generate.R ├── hypothesize.R ├── specify.R ├── estfun.R ├── evaluate.R ├── visualize.R ├── explain.R ├── compile.R ├── fit_xy.R ├── required_pkgs.R ├── learn.R ├── train.R ├── var_imp.R ├── accuracy.R ├── tidy.R ├── forecast.R ├── equation.R ├── augment.R ├── rank_results.R ├── glance.R ├── explore.R ├── interpolate.R ├── components.R ├── min_grid.R ├── generics-package.R ├── tune_args.R ├── tunable.R ├── sets.R ├── coercion.R └── docs.R ├── .Rbuildignore ├── codecov.yml ├── _pkgdown.yml ├── generics.Rproj ├── man ├── refit.Rd ├── calculate.Rd ├── prune.Rd ├── hypothesize.Rd ├── generate.Rd ├── specify.Rd ├── evaluate.Rd ├── visualize.Rd ├── explain.Rd ├── compile.Rd ├── fit.Rd ├── estfun.Rd ├── learn.Rd ├── train.Rd ├── var_imp.Rd ├── accuracy.Rd ├── forecast.Rd ├── equation.Rd ├── varying_args.Rd ├── required_pkgs.Rd ├── fit_xy.Rd ├── rank_results.Rd ├── tidy.Rd ├── augment.Rd ├── glance.Rd ├── explore.Rd ├── interpolate.Rd ├── min_grid.Rd ├── components.Rd ├── coercion-factor.Rd ├── tune_args.Rd ├── coercion-time-difference.Rd ├── tunable.Rd ├── generics-package.Rd └── setops.Rd ├── NEWS.md ├── .gitignore ├── LICENSE.md ├── NAMESPACE ├── DESCRIPTION ├── README.Rmd └── README.md /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /revdep/README.md: -------------------------------------------------------------------------------- 1 | # Revdeps 2 | 3 | -------------------------------------------------------------------------------- /revdep/failures.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /revdep/problems.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2023 2 | COPYRIGHT HOLDER: generics authors 3 | -------------------------------------------------------------------------------- /revdep/.gitignore: -------------------------------------------------------------------------------- 1 | checks 2 | library 3 | data.sqlite 4 | *.html 5 | *.noindex 6 | -------------------------------------------------------------------------------- /revdep/data.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r-lib/generics/HEAD/revdep/data.sqlite -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(generics) 3 | 4 | test_check("generics") 5 | -------------------------------------------------------------------------------- /tests/testthat/testSameRd/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | -------------------------------------------------------------------------------- /tests/testthat/testMultiPackage/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## revdepcheck results 2 | 3 | I did not check revdeps since this was just a resubmission with modern R. 4 | -------------------------------------------------------------------------------- /revdep/email.yml: -------------------------------------------------------------------------------- 1 | release_date: ??? 2 | rel_release_date: ??? 3 | my_news_url: ??? 4 | release_version: ??? 5 | release_details: ??? 6 | -------------------------------------------------------------------------------- /tests/testthat/testS4Docs/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(multi_method) 4 | exportMethods(multi_method) 5 | -------------------------------------------------------------------------------- /tests/testthat/testSingleMethod/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(single_method,default) 4 | export(single_method) 5 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | local_load_all <- function(path, env = parent.frame()) { 2 | pkgload::load_all(path, quiet = TRUE) 3 | withr::defer(pkgload::unload(path), envir = env) 4 | } 5 | -------------------------------------------------------------------------------- /tests/testthat/testGenericsExtension/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(tidy,special_method) 4 | export(tidy) 5 | importFrom(generics,tidy) 6 | -------------------------------------------------------------------------------- /tests/testthat/testMultiMethod/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(multi_method,data.frame) 4 | S3method(multi_method,default) 5 | export(multi_method) 6 | -------------------------------------------------------------------------------- /tests/testthat/testMultiPackage/R/a.R: -------------------------------------------------------------------------------- 1 | #' Test data frame 2 | #' 3 | #' @param x,y A parameter 4 | #' 5 | #' @rdname multi-method-4 6 | multi_method.matrix <- function(x, y) { 7 | x 8 | } 9 | -------------------------------------------------------------------------------- /revdep/cran.md: -------------------------------------------------------------------------------- 1 | ## revdepcheck results 2 | 3 | We checked 101 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. 4 | 5 | * We saw 0 new problems 6 | * We failed to check 0 packages 7 | 8 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^revdep$ 2 | ^docs$ 3 | ^_pkgdown\.yml$ 4 | ^codecov\.yml$ 5 | ^README\.Rmd$ 6 | generics.Rproj 7 | ^.*\.Rproj$ 8 | ^\.Rproj\.user$ 9 | ^\.travis\.yml$ 10 | ^LICENSE\.md$ 11 | ^\.github$ 12 | ^pkgdown$ 13 | ^cran-comments\.md$ 14 | ^CRAN-RELEASE$ 15 | ^CRAN-SUBMISSION$ 16 | -------------------------------------------------------------------------------- /tests/testthat/testGenericsExtension/R/a.R: -------------------------------------------------------------------------------- 1 | #' @importFrom generics tidy 2 | #' @export 3 | generics::tidy 4 | 5 | #' Test default 6 | #' 7 | #' @param x A parameter 8 | #' 9 | #' @rdname tidy-special 10 | #' 11 | #' @export 12 | tidy.special_method <- function(x, ...) { 13 | x 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat/testS4Docs/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: testS4Docs 2 | Title: Tools to make developing R code easier 3 | License: GPL-2 4 | Description: 5 | Author: Hadley 6 | Maintainer: Hadley 7 | Version: 0.1 8 | Collate: a.r 9 | RoxygenNote: 6.1.0 10 | -------------------------------------------------------------------------------- /tests/testthat/testSameRd/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: testSameRd 2 | Title: Tools to make developing R code easier 3 | License: GPL-2 4 | Description: 5 | Author: Hadley 6 | Maintainer: Hadley 7 | Version: 0.1 8 | Collate: 9 | a.r 10 | RoxygenNote: 6.1.0 11 | -------------------------------------------------------------------------------- /tests/testthat/testMultiMethod/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: testMultiMethod 2 | Title: Tools to make developing R code easier 3 | License: GPL-2 4 | Description: 5 | Author: Hadley 6 | Maintainer: Hadley 7 | Version: 0.1 8 | Collate: a.r 9 | RoxygenNote: 6.1.0 10 | -------------------------------------------------------------------------------- /tests/testthat/testSingleMethod/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: testSingleMethod 2 | Title: Tools to make developing R code easier 3 | License: GPL-2 4 | Description: 5 | Author: Hadley 6 | Maintainer: Hadley 7 | Version: 0.1 8 | Collate: a.r 9 | RoxygenNote: 6.1.0 10 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /tests/testthat/testMultiPackage/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: testMultiPackage 2 | Title: Tools to make developing R code easier 3 | License: GPL-2 4 | Description: 5 | Author: Hadley 6 | Maintainer: Hadley 7 | Version: 0.1 8 | Collate: 9 | a.r 10 | RoxygenNote: 6.1.0 11 | -------------------------------------------------------------------------------- /R/varying_args.R: -------------------------------------------------------------------------------- 1 | #' Find any arguments that are not fully specified. 2 | #' 3 | #' @section Methods: 4 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("varying_args")} 5 | #' 6 | #' @inheritParams compile 7 | #' @export 8 | varying_args <- function(object, ...) { 9 | UseMethod("varying_args") 10 | } 11 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://generics.r-lib.org 2 | 3 | template: 4 | package: tidytemplate 5 | bootstrap: 5 6 | 7 | includes: 8 | in_header: | 9 | 10 | 11 | development: 12 | mode: auto 13 | -------------------------------------------------------------------------------- /R/calculate.R: -------------------------------------------------------------------------------- 1 | #' Calculate statistics. 2 | #' @param x An object. 3 | #' @param ... Other arguments passed to methods 4 | #' 5 | #' @section Methods: 6 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("calculate")} 7 | #' 8 | #' @export 9 | calculate <- function(x, ...) { 10 | UseMethod("calculate") 11 | } 12 | 13 | -------------------------------------------------------------------------------- /R/prune.R: -------------------------------------------------------------------------------- 1 | #' Prune or reduce an object 2 | #' 3 | #' @section Methods: 4 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("prune")} 5 | #' 6 | #' @param tree A fitted model object. 7 | #' @param ... Other arguments passed to methods 8 | #' @export 9 | prune <- function(tree, ...) { 10 | UseMethod("prune") 11 | } 12 | -------------------------------------------------------------------------------- /R/refit.R: -------------------------------------------------------------------------------- 1 | #' Refitting models 2 | #' 3 | #' @param object A fitted model object. 4 | #' @param ... Other arguments passed to methods 5 | #' 6 | #' @section Methods: 7 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("refit")} 8 | #' 9 | #' @export 10 | refit <- function(object, ...) { 11 | UseMethod("refit") 12 | } 13 | -------------------------------------------------------------------------------- /R/fit.R: -------------------------------------------------------------------------------- 1 | #' Estimate model parameters. 2 | #' 3 | #' Estimates parameters for a given model from a set of data. 4 | #' 5 | #' @section Methods: 6 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("fit")} 7 | #' 8 | #' @inheritParams compile 9 | #' @export 10 | fit <- function(object, ...) { 11 | UseMethod("fit") 12 | } 13 | -------------------------------------------------------------------------------- /R/generate.R: -------------------------------------------------------------------------------- 1 | #' Generate values based on inputs 2 | #' @param x An object. 3 | #' @param ... Other arguments passed to methods 4 | #' 5 | #' @section Methods: 6 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("generate")} 7 | #' 8 | #' @export 9 | generate <- function(x, ...) { 10 | UseMethod("generate") 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/testthat/testGenericsExtension/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: testGenericsExtension 2 | Title: Tools to make developing R code easier 3 | License: GPL-2 4 | Description: 5 | Author: Hadley 6 | Maintainer: Hadley 7 | Version: 0.1 8 | Collate: a.r 9 | RoxygenNote: 6.1.0 10 | Imports: 11 | generics 12 | -------------------------------------------------------------------------------- /R/hypothesize.R: -------------------------------------------------------------------------------- 1 | #' Construct hypotheses. 2 | #' 3 | #' @param x An object. 4 | #' @param ... Other arguments passed to methods 5 | #' 6 | #' @section Methods: 7 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("hypothesize")} 8 | #' 9 | #' @export 10 | hypothesize <- function(x, ...) { 11 | UseMethod("hypothesize") 12 | } 13 | 14 | -------------------------------------------------------------------------------- /R/specify.R: -------------------------------------------------------------------------------- 1 | #' Specify variables or other quantities. 2 | #' 3 | #' @param x An object. 4 | #' @param ... Other arguments passed to methods 5 | #' 6 | #' @section Methods: 7 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("specify")} 8 | #' 9 | #' @export 10 | specify <- function(x, ...) { 11 | UseMethod("specify") 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/testthat/testSingleMethod/man/single-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/a.r 3 | \name{single_method} 4 | \alias{single_method} 5 | \title{Generic test} 6 | \usage{ 7 | single_method(x) 8 | } 9 | \arguments{ 10 | \item{x}{A parameter} 11 | } 12 | \description{ 13 | Generic test 14 | } 15 | -------------------------------------------------------------------------------- /R/estfun.R: -------------------------------------------------------------------------------- 1 | #' Extracting the estimating functions of a fitted model. 2 | #' 3 | #' @section Methods: 4 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("estfun")} 5 | #' 6 | #' @param x A fitted model object. 7 | #' @param ... Other arguments passed to methods 8 | #' @export 9 | estfun <- function(x, ...) { 10 | UseMethod("estfun") 11 | } 12 | -------------------------------------------------------------------------------- /R/evaluate.R: -------------------------------------------------------------------------------- 1 | #' Evaluate an object. 2 | #' 3 | #' @param x An object. See the individual method for specifics. 4 | #' @param ... other arguments passed to methods 5 | #' 6 | #' @section Methods: 7 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("evaluate")} 8 | #' 9 | #' @export 10 | evaluate <- function(x, ...) { 11 | UseMethod("evaluate") 12 | } 13 | -------------------------------------------------------------------------------- /R/visualize.R: -------------------------------------------------------------------------------- 1 | #' Visualize a data set or object. 2 | #' 3 | #' @param x A data frame or other object. 4 | #' @param ... Other arguments passed to methods 5 | #' 6 | #' @section Methods: 7 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("visualize")} 8 | #' 9 | #' @export 10 | visualize <- function(x, ...) { 11 | UseMethod("visualize") 12 | } 13 | 14 | -------------------------------------------------------------------------------- /R/explain.R: -------------------------------------------------------------------------------- 1 | #' Explain details of an object 2 | #' 3 | #' @param x An object. See the individual method for specifics. 4 | #' @param ... other arguments passed to methods 5 | #' 6 | #' @section Methods: 7 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("explain")} 8 | #' 9 | #' @export 10 | explain <- function(x, ...) { 11 | UseMethod("explain") 12 | } 13 | -------------------------------------------------------------------------------- /tests/testthat/testMultiPackage/man/multi-method-4.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/a.r 3 | \name{multi_method.matrix} 4 | \alias{multi_method.matrix} 5 | \title{Test data frame} 6 | \usage{ 7 | multi_method.matrix(x, y) 8 | } 9 | \arguments{ 10 | \item{x, y}{A parameter} 11 | } 12 | \description{ 13 | Test data frame 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat/testGenericsExtension/man/tidy-special.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/a.r 3 | \name{tidy.special_method} 4 | \alias{tidy.special_method} 5 | \title{Test default} 6 | \usage{ 7 | \method{tidy}{special_method}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A parameter} 11 | } 12 | \description{ 13 | Test default 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat/testMultiMethod/man/multi-method-2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/a.r 3 | \name{multi_method.default} 4 | \alias{multi_method.default} 5 | \title{Test default} 6 | \usage{ 7 | \method{multi_method}{default}(x, y) 8 | } 9 | \arguments{ 10 | \item{x, y}{A parameter} 11 | } 12 | \description{ 13 | Test default 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat/testSingleMethod/man/single-method-2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/a.r 3 | \name{single_method.default} 4 | \alias{single_method.default} 5 | \title{Test default} 6 | \usage{ 7 | \method{single_method}{default}(x) 8 | } 9 | \arguments{ 10 | \item{x}{A parameter} 11 | } 12 | \description{ 13 | Test default 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat/testMultiMethod/man/multi-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/a.r 3 | \name{multi_method} 4 | \alias{multi_method} 5 | \title{Generic test for multiple methods} 6 | \usage{ 7 | multi_method(x, y) 8 | } 9 | \arguments{ 10 | \item{x, y}{A parameter} 11 | } 12 | \description{ 13 | Generic test for multiple methods 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat/testSameRd/man/same_rd_name.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/a.r 3 | \name{same_rd_name} 4 | \alias{same_rd_name} 5 | \title{Generic test for multiple methods on the same rd file} 6 | \usage{ 7 | same_rd_name(x) 8 | } 9 | \arguments{ 10 | \item{x}{A parameter} 11 | } 12 | \description{ 13 | Should be comma separated 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat/testMultiMethod/man/multi-method-3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/a.r 3 | \name{multi_method.data.frame} 4 | \alias{multi_method.data.frame} 5 | \title{Test data frame} 6 | \usage{ 7 | \method{multi_method}{data.frame}(x, y) 8 | } 9 | \arguments{ 10 | \item{x, y}{A parameter} 11 | } 12 | \description{ 13 | Test data frame 14 | } 15 | -------------------------------------------------------------------------------- /R/compile.R: -------------------------------------------------------------------------------- 1 | #' Configure an object 2 | #' 3 | #' Finalizes or completes an object. 4 | #' 5 | #' @section Methods: 6 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("compile")} 7 | #' 8 | #' @param object An object. See the individual method for specifics. 9 | #' @param ... Other arguments passed to methods 10 | #' @export 11 | compile <- function(object, ...) { 12 | UseMethod("compile") 13 | } 14 | -------------------------------------------------------------------------------- /R/fit_xy.R: -------------------------------------------------------------------------------- 1 | #' Estimate model parameters. 2 | #' 3 | #' Estimates parameters for a given model from a set of data in the form of 4 | #' a set of predictors (`x`) and outcome(s) (`y`). 5 | #' 6 | #' @section Methods: 7 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("fit_xy")} 8 | #' 9 | #' @inheritParams compile 10 | #' @export 11 | fit_xy <- function(object, ...) { 12 | UseMethod("fit_xy") 13 | } 14 | -------------------------------------------------------------------------------- /R/required_pkgs.R: -------------------------------------------------------------------------------- 1 | #' Determine packages required by objects 2 | #' 3 | #' @param x An object. 4 | #' @param ... Other arguments passed to methods 5 | #' @return A character string of packages that are required. 6 | #' @section Methods: 7 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("required_pkgs")} 8 | #' @export 9 | required_pkgs <- function(x, ...) { 10 | UseMethod("required_pkgs") 11 | } 12 | -------------------------------------------------------------------------------- /tests/testthat/testSingleMethod/R/a.R: -------------------------------------------------------------------------------- 1 | #' Generic test 2 | #' 3 | #' 4 | #' @param x A parameter 5 | #' 6 | #' @rdname single-method 7 | #' 8 | #' @export 9 | single_method <- function(x) { 10 | UseMethod("single_method") 11 | } 12 | 13 | #' Test default 14 | #' 15 | #' @param x A parameter 16 | #' 17 | #' @rdname single-method-2 18 | #' 19 | #' @export 20 | single_method.default <- function(x) { 21 | x 22 | } 23 | -------------------------------------------------------------------------------- /R/learn.R: -------------------------------------------------------------------------------- 1 | #' Estimate model parameters. 2 | #' 3 | #' Estimates parameters for a given model from a set of data. 4 | #' 5 | #' @param x An object. See the individual method for specifics. 6 | #' @param ... other arguments passed to methods 7 | #' 8 | #' @section Methods: 9 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("learn")} 10 | #' 11 | #' @export 12 | learn <- function(x, ...) { 13 | UseMethod("learn") 14 | } 15 | -------------------------------------------------------------------------------- /R/train.R: -------------------------------------------------------------------------------- 1 | #' Estimate model parameters. 2 | #' 3 | #' Estimates parameters for a given model from a set of data. 4 | #' 5 | #' @param x An object. See the individual method for specifics. 6 | #' @param ... other arguments passed to methods 7 | #' 8 | #' @section Methods: 9 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("train")} 10 | #' 11 | #' @export 12 | train <- function(x, ...) { 13 | UseMethod("train") 14 | } 15 | -------------------------------------------------------------------------------- /R/var_imp.R: -------------------------------------------------------------------------------- 1 | #' Calculation of variable importance 2 | #' 3 | #' A generic method for calculating variable importance for model objects. 4 | #' 5 | #' @param object A fitted model object. 6 | #' @param ... Other arguments passed to methods 7 | #' 8 | #' @section Methods: 9 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("var_imp")} 10 | #' 11 | #' @export 12 | var_imp <- function(object, ...) { 13 | UseMethod("var_imp") 14 | } 15 | -------------------------------------------------------------------------------- /R/accuracy.R: -------------------------------------------------------------------------------- 1 | #' Accuracy measures for a model 2 | #' 3 | #' Returns range of summary measures of the forecast accuracy. 4 | #' 5 | #' @param object A model for which forecasts are required. 6 | #' @param ... Other arguments passed to methods 7 | #' 8 | #' @section Methods: 9 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("accuracy")} 10 | #' 11 | #' @export 12 | accuracy <- function(object, ...) { 13 | UseMethod("accuracy") 14 | } 15 | -------------------------------------------------------------------------------- /R/tidy.R: -------------------------------------------------------------------------------- 1 | #' Turn an object into a tidy tibble 2 | #' 3 | #' @param x An object to be converted into a tidy [tibble::tibble()]. 4 | #' @param ... Additional arguments to tidying method. 5 | #' @return A [tibble::tibble()] with information about model components. 6 | #' 7 | #' @section Methods: 8 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("tidy")} 9 | #' 10 | #' @export 11 | tidy <- function(x, ...) { 12 | UseMethod("tidy") 13 | } 14 | -------------------------------------------------------------------------------- /R/forecast.R: -------------------------------------------------------------------------------- 1 | #' Forecasting from an object 2 | #' 3 | #' The functions allow producing forecasts based on the provided object. 4 | #' 5 | #' @param object A model for which forecasts are required. 6 | #' @param ... Other arguments passed to methods 7 | #' 8 | #' @section Methods: 9 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("forecast")} 10 | #' 11 | #' @export 12 | forecast <- function(object, ...) { 13 | UseMethod("forecast") 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat/testS4Docs/R/a.R: -------------------------------------------------------------------------------- 1 | #' An s4 generic 2 | #' 3 | #' @export 4 | #' @aliases multi_method,ANY,ANY-method 5 | setGeneric("multi_method", function(x, y) { 6 | x 7 | }) 8 | 9 | #' @rdname multi_method 10 | #' @export 11 | setMethod("multi_method", signature(x = "numeric"), function(x, y) { 12 | x 13 | }) 14 | 15 | #' @rdname multi_method 16 | #' @export 17 | setMethod("multi_method", signature(x = "numeric", y = "integer"), function(x, y) { 18 | x 19 | }) 20 | 21 | -------------------------------------------------------------------------------- /R/equation.R: -------------------------------------------------------------------------------- 1 | #' Model equations 2 | #' 3 | #' Display the mathematical representation of a fitted model. 4 | #' 5 | #' @param object A fitted model object. 6 | #' @param ... Other arguments passed to methods 7 | #' 8 | #' @return Markup output suitable for rendering the equation. 9 | #' 10 | #' @section Methods: 11 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("equation")} 12 | #' 13 | #' @export 14 | equation <- function(object, ...) { 15 | UseMethod("equation") 16 | } 17 | -------------------------------------------------------------------------------- /generics.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /man/refit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/refit.R 3 | \name{refit} 4 | \alias{refit} 5 | \title{Refitting models} 6 | \usage{ 7 | refit(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{A fitted model object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Refitting models 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("refit")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /R/augment.R: -------------------------------------------------------------------------------- 1 | #' Augment data with information from an object 2 | #' 3 | #' @param x Model object or other R object with information to append to 4 | #' observations. 5 | #' @param ... Addition arguments to `augment` method. 6 | #' @return A [tibble::tibble()] with information about data points. 7 | #' @section Methods: 8 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("augment")} 9 | #' 10 | #' @export 11 | #' 12 | augment <- function(x, ...) { 13 | UseMethod("augment") 14 | } 15 | -------------------------------------------------------------------------------- /man/calculate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/calculate.R 3 | \name{calculate} 4 | \alias{calculate} 5 | \title{Calculate statistics.} 6 | \usage{ 7 | calculate(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Calculate statistics. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("calculate")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/prune.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prune.R 3 | \name{prune} 4 | \alias{prune} 5 | \title{Prune or reduce an object} 6 | \usage{ 7 | prune(tree, ...) 8 | } 9 | \arguments{ 10 | \item{tree}{A fitted model object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Prune or reduce an object 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("prune")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/testthat/testGenericsExtension/man/reexports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/a.r 3 | \docType{import} 4 | \name{reexports} 5 | \alias{reexports} 6 | \alias{tidy} 7 | \title{Objects exported from other packages} 8 | \keyword{internal} 9 | \description{ 10 | These objects are imported from other packages. Follow the links 11 | below to see their documentation. 12 | 13 | \describe{ 14 | \item{generics}{\code{\link[generics]{tidy}}} 15 | }} 16 | 17 | -------------------------------------------------------------------------------- /R/rank_results.R: -------------------------------------------------------------------------------- 1 | #' Compute relative rankings of a collection of objects 2 | #' 3 | #' `rank_results()` computes relative ranks of a collection of objects and 4 | #' returns a summary of the results. 5 | #' 6 | #' @param x A collection of objects 7 | #' @param ... Other arguments passed to methods 8 | #' 9 | #' @section Methods: 10 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("rank_results")} 11 | #' 12 | #' @export 13 | rank_results <- function(x, ...) { 14 | UseMethod("rank_results") 15 | } 16 | -------------------------------------------------------------------------------- /man/hypothesize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hypothesize.R 3 | \name{hypothesize} 4 | \alias{hypothesize} 5 | \title{Construct hypotheses.} 6 | \usage{ 7 | hypothesize(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Construct hypotheses. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("hypothesize")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/generate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generate.R 3 | \name{generate} 4 | \alias{generate} 5 | \title{Generate values based on inputs} 6 | \usage{ 7 | generate(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Generate values based on inputs 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("generate")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/testthat/testSameRd/man/same_rd_name-2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/a.r 3 | \name{same_rd_name.default} 4 | \alias{same_rd_name.default} 5 | \alias{same_rd_name.data.frame} 6 | \title{Test default} 7 | \usage{ 8 | \method{same_rd_name}{default}(x) 9 | 10 | \method{same_rd_name}{data.frame}(x) 11 | } 12 | \arguments{ 13 | \item{x}{A parameter} 14 | 15 | \item{x}{A parameter} 16 | } 17 | \description{ 18 | Test default 19 | 20 | Test data frame 21 | } 22 | -------------------------------------------------------------------------------- /man/specify.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/specify.R 3 | \name{specify} 4 | \alias{specify} 5 | \title{Specify variables or other quantities.} 6 | \usage{ 7 | specify(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Specify variables or other quantities. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("specify")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/evaluate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/evaluate.R 3 | \name{evaluate} 4 | \alias{evaluate} 5 | \title{Evaluate an object.} 6 | \usage{ 7 | evaluate(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An object. See the individual method for specifics.} 11 | 12 | \item{...}{other arguments passed to methods} 13 | } 14 | \description{ 15 | Evaluate an object. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("evaluate")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/visualize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/visualize.R 3 | \name{visualize} 4 | \alias{visualize} 5 | \title{Visualize a data set or object.} 6 | \usage{ 7 | visualize(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A data frame or other object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Visualize a data set or object. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("visualize")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/explain.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/explain.R 3 | \name{explain} 4 | \alias{explain} 5 | \title{Explain details of an object} 6 | \usage{ 7 | explain(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An object. See the individual method for specifics.} 11 | 12 | \item{...}{other arguments passed to methods} 13 | } 14 | \description{ 15 | Explain details of an object 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("explain")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/compile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compile.R 3 | \name{compile} 4 | \alias{compile} 5 | \title{Configure an object} 6 | \usage{ 7 | compile(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{An object. See the individual method for specifics.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Finalizes or completes an object. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("compile")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit.R 3 | \name{fit} 4 | \alias{fit} 5 | \title{Estimate model parameters.} 6 | \usage{ 7 | fit(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{An object. See the individual method for specifics.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Estimates parameters for a given model from a set of data. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("fit")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/estfun.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/estfun.R 3 | \name{estfun} 4 | \alias{estfun} 5 | \title{Extracting the estimating functions of a fitted model.} 6 | \usage{ 7 | estfun(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A fitted model object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Extracting the estimating functions of a fitted model. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("estfun")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/learn.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/learn.R 3 | \name{learn} 4 | \alias{learn} 5 | \title{Estimate model parameters.} 6 | \usage{ 7 | learn(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An object. See the individual method for specifics.} 11 | 12 | \item{...}{other arguments passed to methods} 13 | } 14 | \description{ 15 | Estimates parameters for a given model from a set of data. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("learn")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/train.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/train.R 3 | \name{train} 4 | \alias{train} 5 | \title{Estimate model parameters.} 6 | \usage{ 7 | train(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An object. See the individual method for specifics.} 11 | 12 | \item{...}{other arguments passed to methods} 13 | } 14 | \description{ 15 | Estimates parameters for a given model from a set of data. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("train")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/testthat/testS4Docs/man/multi_method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/a.r 3 | \docType{methods} 4 | \name{multi_method} 5 | \alias{multi_method} 6 | \alias{multi_method,ANY,ANY-method} 7 | \alias{multi_method,numeric,ANY-method} 8 | \alias{multi_method,numeric,integer-method} 9 | \title{An s4 generic} 10 | \usage{ 11 | multi_method(x, y) 12 | 13 | \S4method{multi_method}{numeric,ANY}(x, y) 14 | 15 | \S4method{multi_method}{numeric,integer}(x, y) 16 | } 17 | \description{ 18 | An s4 generic 19 | } 20 | -------------------------------------------------------------------------------- /man/var_imp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/var_imp.R 3 | \name{var_imp} 4 | \alias{var_imp} 5 | \title{Calculation of variable importance} 6 | \usage{ 7 | var_imp(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{A fitted model object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | A generic method for calculating variable importance for model objects. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("var_imp")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/accuracy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/accuracy.R 3 | \name{accuracy} 4 | \alias{accuracy} 5 | \title{Accuracy measures for a model} 6 | \usage{ 7 | accuracy(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{A model for which forecasts are required.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Returns range of summary measures of the forecast accuracy. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("accuracy")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/forecast.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/forecast.R 3 | \name{forecast} 4 | \alias{forecast} 5 | \title{Forecasting from an object} 6 | \usage{ 7 | forecast(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{A model for which forecasts are required.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | The functions allow producing forecasts based on the provided object. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("forecast")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /R/glance.R: -------------------------------------------------------------------------------- 1 | #' Glance at an object 2 | #' 3 | #' Construct a single row summary "glance" of a model, fit, or other 4 | #' object 5 | #' 6 | #' glance methods always return either a one-row data frame (except on 7 | #' `NULL`, which returns an empty data frame) 8 | #' 9 | #' @param x model or other R object to convert to single-row data frame 10 | #' @param ... other arguments passed to methods 11 | #' 12 | #' @section Methods: 13 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("glance")} 14 | #' 15 | #' @export 16 | glance <- function(x, ...) { 17 | UseMethod("glance") 18 | } 19 | -------------------------------------------------------------------------------- /tests/testthat/testSameRd/R/a.R: -------------------------------------------------------------------------------- 1 | #' Generic test for multiple methods on the same rd file 2 | #' 3 | #' Should be comma separated 4 | #' 5 | #' @param x A parameter 6 | #' 7 | #' @rdname same_rd_name 8 | #' 9 | same_rd_name <- function(x) { 10 | UseMethod("same_rd_name") 11 | } 12 | 13 | #' Test default 14 | #' 15 | #' @param x A parameter 16 | #' 17 | #' @rdname same_rd_name-2 18 | same_rd_name.default <- function(x) { 19 | x 20 | } 21 | 22 | #' Test data frame 23 | #' 24 | #' @param x A parameter 25 | #' 26 | #' @rdname same_rd_name-2 27 | same_rd_name.data.frame <- function(x) { 28 | x 29 | } 30 | -------------------------------------------------------------------------------- /man/equation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/equation.R 3 | \name{equation} 4 | \alias{equation} 5 | \title{Model equations} 6 | \usage{ 7 | equation(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{A fitted model object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \value{ 15 | Markup output suitable for rendering the equation. 16 | } 17 | \description{ 18 | Display the mathematical representation of a fitted model. 19 | } 20 | \section{Methods}{ 21 | 22 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("equation")} 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/varying_args.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varying_args.R 3 | \name{varying_args} 4 | \alias{varying_args} 5 | \title{Find any arguments that are not fully specified.} 6 | \usage{ 7 | varying_args(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{An object. See the individual method for specifics.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Find any arguments that are not fully specified. 16 | } 17 | \section{Methods}{ 18 | 19 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("varying_args")} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/required_pkgs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/required_pkgs.R 3 | \name{required_pkgs} 4 | \alias{required_pkgs} 5 | \title{Determine packages required by objects} 6 | \usage{ 7 | required_pkgs(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \value{ 15 | A character string of packages that are required. 16 | } 17 | \description{ 18 | Determine packages required by objects 19 | } 20 | \section{Methods}{ 21 | 22 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("required_pkgs")} 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tests/testthat/testMultiMethod/R/a.R: -------------------------------------------------------------------------------- 1 | #' Generic test for multiple methods 2 | #' 3 | #' 4 | #' @param x,y A parameter 5 | #' 6 | #' @rdname multi-method 7 | #' 8 | #' @export 9 | multi_method <- function(x, y) { 10 | UseMethod("multi_method") 11 | } 12 | 13 | #' Test default 14 | #' 15 | #' @param x,y A parameter 16 | #' 17 | #' @rdname multi-method-2 18 | #' 19 | #' @export 20 | multi_method.default <- function(x, y) { 21 | x 22 | } 23 | 24 | #' Test data frame 25 | #' 26 | #' @param x,y A parameter 27 | #' 28 | #' @rdname multi-method-3 29 | #' 30 | #' @export 31 | multi_method.data.frame <- function(x, y) { 32 | x 33 | } 34 | -------------------------------------------------------------------------------- /man/fit_xy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit_xy.R 3 | \name{fit_xy} 4 | \alias{fit_xy} 5 | \title{Estimate model parameters.} 6 | \usage{ 7 | fit_xy(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{An object. See the individual method for specifics.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | Estimates parameters for a given model from a set of data in the form of 16 | a set of predictors (\code{x}) and outcome(s) (\code{y}). 17 | } 18 | \section{Methods}{ 19 | 20 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("fit_xy")} 21 | } 22 | 23 | -------------------------------------------------------------------------------- /man/rank_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rank_results.R 3 | \name{rank_results} 4 | \alias{rank_results} 5 | \title{Compute relative rankings of a collection of objects} 6 | \usage{ 7 | rank_results(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A collection of objects} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \description{ 15 | \code{rank_results()} computes relative ranks of a collection of objects and 16 | returns a summary of the results. 17 | } 18 | \section{Methods}{ 19 | 20 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("rank_results")} 21 | } 22 | 23 | -------------------------------------------------------------------------------- /R/explore.R: -------------------------------------------------------------------------------- 1 | #' Create an interactive visualization appropriate to a particular object type 2 | #' 3 | #' `explore()` invokes a function that starts an interactive, pre-defined widget 4 | #' (e.g. `plotly` visualization, `shiny` app, etc.) to investigate the results. 5 | #' 6 | #' @param x A object 7 | #' @param ... Other arguments passed to methods 8 | #' 9 | #' @return `NULL` (invisibly) or some other data type (e.g. tibble) depending on 10 | #' the application. 11 | #' 12 | #' @section Methods: 13 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("explore")} 14 | #' 15 | #' @export 16 | explore <- function(x, ...) { 17 | UseMethod("explore") 18 | } 19 | -------------------------------------------------------------------------------- /R/interpolate.R: -------------------------------------------------------------------------------- 1 | #' Interpolate missing values 2 | #' 3 | #' Interpolates missing values provided in the training dataset using the 4 | #' fitted model. 5 | #' 6 | #' @param object A fitted model object 7 | #' @param ... Other arguments passed to methods 8 | #' 9 | #' @return A dataset ([tibble::tibble()] or similar) of the same structure as 10 | #' the input dataset with missing values from the response variable replaced 11 | #' with interpolated values. 12 | #' 13 | #' @section Methods: 14 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("interpolate")} 15 | #' 16 | #' @export 17 | interpolate <- function(object, ...) { 18 | UseMethod("interpolate") 19 | } 20 | -------------------------------------------------------------------------------- /man/tidy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tidy.R 3 | \name{tidy} 4 | \alias{tidy} 5 | \title{Turn an object into a tidy tibble} 6 | \usage{ 7 | tidy(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An object to be converted into a tidy \code{\link[tibble:tibble]{tibble::tibble()}}.} 11 | 12 | \item{...}{Additional arguments to tidying method.} 13 | } 14 | \value{ 15 | A \code{\link[tibble:tibble]{tibble::tibble()}} with information about model components. 16 | } 17 | \description{ 18 | Turn an object into a tidy tibble 19 | } 20 | \section{Methods}{ 21 | 22 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("tidy")} 23 | } 24 | 25 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # generics (development version) 2 | 3 | # generics 0.1.4 4 | 5 | * Patch release for CRAN 6 | 7 | # generics 0.1.3 8 | 9 | * New `rank_results()` generic. 10 | 11 | # generics 0.1.2 12 | 13 | * New `forecast()` and `accuracy()` generics. 14 | 15 | # generics 0.1.1 16 | 17 | * New `tune_args()` generic. 18 | 19 | # generics 0.1.0 20 | 21 | * Maintainer changed to Hadley Wickham. 22 | 23 | * Re-licensed with MIT license. 24 | 25 | * New `min_grid()`, `required_pkgs()`, and `tunable()` generics. 26 | 27 | # `generics` 0.0.2 28 | 29 | * Removed the `data` argument to `augment` to resolve issues with `broom`. 30 | 31 | # `generics` 0.0.1 32 | 33 | First CRAN version 34 | -------------------------------------------------------------------------------- /man/augment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/augment.R 3 | \name{augment} 4 | \alias{augment} 5 | \title{Augment data with information from an object} 6 | \usage{ 7 | augment(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{Model object or other R object with information to append to 11 | observations.} 12 | 13 | \item{...}{Addition arguments to \code{augment} method.} 14 | } 15 | \value{ 16 | A \code{\link[tibble:tibble]{tibble::tibble()}} with information about data points. 17 | } 18 | \description{ 19 | Augment data with information from an object 20 | } 21 | \section{Methods}{ 22 | 23 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("augment")} 24 | } 25 | 26 | -------------------------------------------------------------------------------- /man/glance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/glance.R 3 | \name{glance} 4 | \alias{glance} 5 | \title{Glance at an object} 6 | \usage{ 7 | glance(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{model or other R object to convert to single-row data frame} 11 | 12 | \item{...}{other arguments passed to methods} 13 | } 14 | \description{ 15 | Construct a single row summary "glance" of a model, fit, or other 16 | object 17 | } 18 | \details{ 19 | glance methods always return either a one-row data frame (except on 20 | \code{NULL}, which returns an empty data frame) 21 | } 22 | \section{Methods}{ 23 | 24 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("glance")} 25 | } 26 | 27 | -------------------------------------------------------------------------------- /R/components.R: -------------------------------------------------------------------------------- 1 | #' Extract components 2 | #' 3 | #' `components` can be used to extract elements from an object. 4 | #' 5 | #' For example, decomposition methods and some modelling techniques can be used 6 | #' to decompose a dataset into components of interest. This function is used 7 | #' to extract these components in a tidy data format. 8 | #' 9 | #' @param object A data separable object. 10 | #' @param ... Other arguments passed to methods 11 | #' 12 | #' @return A dataset ([tibble::tibble()] or similar) containing components from 13 | #' the object. 14 | #' 15 | #' @section Methods: 16 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("components")} 17 | #' 18 | #' @export 19 | components <- function(object, ...) { 20 | UseMethod("components") 21 | } 22 | -------------------------------------------------------------------------------- /R/min_grid.R: -------------------------------------------------------------------------------- 1 | #' Determine the minimum set of model fits 2 | #' 3 | #' `min_grid()` determines exactly what models should be fit in order to 4 | #' evaluate the entire set of tuning parameter combinations. This is for 5 | #' internal use only and the API may change in the near future. 6 | #' @param x A model specification. 7 | #' @param grid A tibble with tuning parameter combinations. 8 | #' @param ... Not currently used. 9 | #' @return A tibble with the minimum tuning parameters to fit and an additional 10 | #' list column with the parameter combinations used for prediction. 11 | #' @section Methods: 12 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("min_grid")} 13 | #' @export 14 | min_grid <- function(x, grid, ...) { 15 | UseMethod("min_grid") 16 | } 17 | -------------------------------------------------------------------------------- /man/explore.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/explore.R 3 | \name{explore} 4 | \alias{explore} 5 | \title{Create an interactive visualization appropriate to a particular object type} 6 | \usage{ 7 | explore(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A object} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \value{ 15 | \code{NULL} (invisibly) or some other data type (e.g. tibble) depending on 16 | the application. 17 | } 18 | \description{ 19 | \code{explore()} invokes a function that starts an interactive, pre-defined widget 20 | (e.g. \code{plotly} visualization, \code{shiny} app, etc.) to investigate the results. 21 | } 22 | \section{Methods}{ 23 | 24 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("explore")} 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/interpolate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interpolate.R 3 | \name{interpolate} 4 | \alias{interpolate} 5 | \title{Interpolate missing values} 6 | \usage{ 7 | interpolate(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{A fitted model object} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \value{ 15 | A dataset (\code{\link[tibble:tibble]{tibble::tibble()}} or similar) of the same structure as 16 | the input dataset with missing values from the response variable replaced 17 | with interpolated values. 18 | } 19 | \description{ 20 | Interpolates missing values provided in the training dataset using the 21 | fitted model. 22 | } 23 | \section{Methods}{ 24 | 25 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("interpolate")} 26 | } 27 | 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Session Data files 6 | .RData 7 | 8 | # Example code in package build process 9 | *-Ex.R 10 | 11 | # Output files from R CMD build 12 | /*.tar.gz 13 | 14 | # Output files from R CMD check 15 | /*.Rcheck/ 16 | 17 | # RStudio files 18 | .Rproj.user/ 19 | 20 | # produced vignettes 21 | vignettes/*.html 22 | vignettes/*.pdf 23 | 24 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 25 | .httr-oauth 26 | 27 | # knitr and R markdown default cache directories 28 | /*_cache/ 29 | /cache/ 30 | 31 | # Temporary files created by R markdown 32 | *.utf8.md 33 | *.knit.md 34 | 35 | # Shiny token, see https://shiny.rstudio.com/articles/shinyapps.html 36 | rsconnect/ 37 | 38 | .Rproj.user 39 | 40 | .DS_Store 41 | revdep/checks.noindex/ 42 | revdep/library.noindex/ 43 | docs 44 | -------------------------------------------------------------------------------- /man/min_grid.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/min_grid.R 3 | \name{min_grid} 4 | \alias{min_grid} 5 | \title{Determine the minimum set of model fits} 6 | \usage{ 7 | min_grid(x, grid, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A model specification.} 11 | 12 | \item{grid}{A tibble with tuning parameter combinations.} 13 | 14 | \item{...}{Not currently used.} 15 | } 16 | \value{ 17 | A tibble with the minimum tuning parameters to fit and an additional 18 | list column with the parameter combinations used for prediction. 19 | } 20 | \description{ 21 | \code{min_grid()} determines exactly what models should be fit in order to 22 | evaluate the entire set of tuning parameter combinations. This is for 23 | internal use only and the API may change in the near future. 24 | } 25 | \section{Methods}{ 26 | 27 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("min_grid")} 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/components.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/components.R 3 | \name{components} 4 | \alias{components} 5 | \title{Extract components} 6 | \usage{ 7 | components(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{A data separable object.} 11 | 12 | \item{...}{Other arguments passed to methods} 13 | } 14 | \value{ 15 | A dataset (\code{\link[tibble:tibble]{tibble::tibble()}} or similar) containing components from 16 | the object. 17 | } 18 | \description{ 19 | \code{components} can be used to extract elements from an object. 20 | } 21 | \details{ 22 | For example, decomposition methods and some modelling techniques can be used 23 | to decompose a dataset into components of interest. This function is used 24 | to extract these components in a tidy data format. 25 | } 26 | \section{Methods}{ 27 | 28 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("components")} 29 | } 30 | 31 | -------------------------------------------------------------------------------- /R/generics-package.R: -------------------------------------------------------------------------------- 1 | #' generics: common S3 generics 2 | #' 3 | #' These are generic functions that can be used to minimize 4 | #' package dependencies when multiple packages have the same 5 | #' method. 6 | #' 7 | #' An attempt was made to use generic class signatures that were 8 | #' consistent with existing code. For example, \pkg{dplyr} and 9 | #' \pkg{lime} both have `explain()` methods that do very different 10 | #' things but both take `x` as their main object. Even though `x` 11 | #' would be different in those cases, this package provides access 12 | #' to the S3 generic so that other packages that may want to create 13 | #' `explain()` methods for their objects can do so without loading 14 | #' either of the other packages. 15 | #' 16 | #' For example, if a new `tidy()` method is being developed for a 17 | #' package, this lightweight package can be the required dependency 18 | #' to have access to the generic method (instead of depending on 19 | #' \pkg{broom} and installing its dependencies). 20 | #' 21 | #' @keywords internal 22 | "_PACKAGE" 23 | 24 | ## usethis namespace: start 25 | ## usethis namespace: end 26 | NULL 27 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2023 generics authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(as.character,dev_topic) 4 | S3method(as.difftime,default) 5 | S3method(as.factor,default) 6 | S3method(as.ordered,default) 7 | S3method(intersect,default) 8 | S3method(is.element,default) 9 | S3method(setdiff,default) 10 | S3method(setequal,default) 11 | S3method(union,default) 12 | export(accuracy) 13 | export(as.difftime) 14 | export(as.factor) 15 | export(as.ordered) 16 | export(augment) 17 | export(calculate) 18 | export(compile) 19 | export(components) 20 | export(equation) 21 | export(estfun) 22 | export(evaluate) 23 | export(explain) 24 | export(explore) 25 | export(fit) 26 | export(fit_xy) 27 | export(forecast) 28 | export(generate) 29 | export(glance) 30 | export(hypothesize) 31 | export(interpolate) 32 | export(intersect) 33 | export(is.element) 34 | export(learn) 35 | export(min_grid) 36 | export(prune) 37 | export(rank_results) 38 | export(refit) 39 | export(required_pkgs) 40 | export(setdiff) 41 | export(setequal) 42 | export(specify) 43 | export(tidy) 44 | export(train) 45 | export(tunable) 46 | export(tune_args) 47 | export(union) 48 | export(var_imp) 49 | export(varying_args) 50 | export(visualize) 51 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: generics 2 | Title: Common S3 Generics not Provided by Base R Methods Related to Model 3 | Fitting 4 | Version: 0.1.4.9000 5 | Authors@R: c( 6 | person("Hadley", "Wickham", , "hadley@posit.co", role = c("aut", "cre"), 7 | comment = c(ORCID = "0000-0003-4757-117X")), 8 | person("Max", "Kuhn", , "max@posit.co", role = "aut"), 9 | person("Davis", "Vaughan", , "davis@posit.co", role = "aut"), 10 | person("Posit Software, PBC", role = c("cph", "fnd"), 11 | comment = c(ROR = "https://ror.org/03wc8by49")) 12 | ) 13 | Description: In order to reduce potential package dependencies and 14 | conflicts, generics provides a number of commonly used S3 generics. 15 | License: MIT + file LICENSE 16 | URL: https://generics.r-lib.org, https://github.com/r-lib/generics 17 | BugReports: https://github.com/r-lib/generics/issues 18 | Depends: 19 | R (>= 3.6) 20 | Imports: 21 | methods 22 | Suggests: 23 | covr, 24 | pkgload, 25 | testthat (>= 3.0.0), 26 | tibble, 27 | withr 28 | Config/Needs/website: tidyverse/tidytemplate 29 | Config/testthat/edition: 3 30 | Encoding: UTF-8 31 | Roxygen: list(markdown = TRUE) 32 | RoxygenNote: 7.3.2 33 | -------------------------------------------------------------------------------- /man/coercion-factor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coercion.R 3 | \name{coercion-factor} 4 | \alias{coercion-factor} 5 | \alias{as.factor} 6 | \alias{as.ordered} 7 | \title{Factor coercion} 8 | \usage{ 9 | as.factor(x, ...) 10 | 11 | as.ordered(x, ...) 12 | } 13 | \arguments{ 14 | \item{x}{A vector of data.} 15 | 16 | \item{...}{Other arguments passed on to methods.} 17 | } 18 | \value{ 19 | For \code{as.factor()}, a factor. For \code{as.ordered()}, 20 | an ordered factor. 21 | } 22 | \description{ 23 | Coercion functions for creating factors from other existing objects. 24 | } 25 | \details{ 26 | These functions override non-generic factor coercion functions provided 27 | in base so that packages can provide methods for different data types. The 28 | default methods call the base versions. 29 | } 30 | \section{Methods}{ 31 | 32 | 33 | \subsection{\code{as.factor()}}{ 34 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("as.factor")} 35 | } 36 | 37 | \subsection{\code{as.ordered()}}{ 38 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("as.ordered")} 39 | } 40 | } 41 | 42 | \examples{ 43 | as.factor(letters[1:5]) 44 | as.ordered(letters[1:5]) 45 | 46 | } 47 | -------------------------------------------------------------------------------- /R/tune_args.R: -------------------------------------------------------------------------------- 1 | #' Determine arguments tagged for tuning 2 | #' 3 | #' `tune_args()` takes an object such as a model specification or a recipe and 4 | #' returns a tibble of information on all possible tunable arguments and 5 | #' whether or not they are actually tunable. 6 | #' 7 | #' @param object A `model_spec`, `recipe`, `workflow`, or other object. 8 | #' @param ... Other arguments passed to methods. 9 | #' 10 | #' @details 11 | #' The `source` column is determined differently for a 12 | #' `model_spec` or a `recipe` (with additional detail on the type). 13 | #' 14 | #' The `id` field has any identifier that was passed from `tune::tune()` (e.g. 15 | #' `tune("some note")`). If no additional detail was used in that function, 16 | #' the `id` field reverts to the name of the parameters. 17 | #' 18 | #' @return A tibble with columns for the parameter name (`name`), whether it 19 | #' contains _any_ tunable value (`tune`), the `id` for the parameter (`id`), 20 | #' and the information on where the parameter was located (`source`). 21 | #' 22 | #' @section Methods: 23 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("tune_args")} 24 | #' 25 | #' @export 26 | tune_args <- function(object, ...) { 27 | UseMethod("tune_args") 28 | } 29 | -------------------------------------------------------------------------------- /man/tune_args.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tune_args.R 3 | \name{tune_args} 4 | \alias{tune_args} 5 | \title{Determine arguments tagged for tuning} 6 | \usage{ 7 | tune_args(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{A \code{model_spec}, \code{recipe}, \code{workflow}, or other object.} 11 | 12 | \item{...}{Other arguments passed to methods.} 13 | } 14 | \value{ 15 | A tibble with columns for the parameter name (\code{name}), whether it 16 | contains \emph{any} tunable value (\code{tune}), the \code{id} for the parameter (\code{id}), 17 | and the information on where the parameter was located (\code{source}). 18 | } 19 | \description{ 20 | \code{tune_args()} takes an object such as a model specification or a recipe and 21 | returns a tibble of information on all possible tunable arguments and 22 | whether or not they are actually tunable. 23 | } 24 | \details{ 25 | The \code{source} column is determined differently for a 26 | \code{model_spec} or a \code{recipe} (with additional detail on the type). 27 | 28 | The \code{id} field has any identifier that was passed from \code{tune::tune()} (e.g. 29 | \code{tune("some note")}). If no additional detail was used in that function, 30 | the \code{id} field reverts to the name of the parameters. 31 | } 32 | \section{Methods}{ 33 | 34 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("tune_args")} 35 | } 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/test-docs.R: -------------------------------------------------------------------------------- 1 | test_that("generics methods can be reexported and extended", { 2 | local_load_all("testGenericsExtension") 3 | expect_snapshot(methods_rd("tidy")) 4 | }) 5 | 6 | test_that("multiple packages have multiple headers", { 7 | local_load_all("testMultiMethod") 8 | local_load_all("testMultiPackage") 9 | expect_snapshot(methods_rd("multi_method")) 10 | }) 11 | 12 | test_that("S4 bullets print with no issues", { 13 | local_load_all("testS4Docs") 14 | 15 | expect_snapshot(methods_rd("multi_method")) 16 | }) 17 | 18 | test_that("S4 and S3 packages can intermingle", { 19 | local_load_all("testS4Docs") 20 | local_load_all("testMultiMethod") 21 | 22 | expect_snapshot(methods_rd("multi_method")) 23 | }) 24 | 25 | test_that("multiple methods but same rdname are comma separated", { 26 | local_load_all("testSameRd") 27 | expect_snapshot(methods_rd("same_rd_name")) 28 | }) 29 | 30 | test_that("single method is correctly itemized", { 31 | local_load_all("testSingleMethod") 32 | expect_snapshot(methods_rd("single_method")) 33 | }) 34 | 35 | test_that("multiple methods are correctly itemized", { 36 | local_load_all("testMultiMethod") 37 | expect_snapshot(methods_rd("multi_method")) 38 | }) 39 | 40 | test_that("no methods case returns default output", { 41 | expect_equal( 42 | methods_rd("methods_rd"), 43 | "No methods found in currently loaded packages." 44 | ) 45 | }) 46 | 47 | test_that("nonexistant generic is an error", { 48 | expect_error(methods_rd("xyz")) 49 | }) 50 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | release: 9 | types: [published] 10 | workflow_dispatch: 11 | 12 | name: pkgdown 13 | 14 | jobs: 15 | pkgdown: 16 | runs-on: ubuntu-latest 17 | # Only restrict concurrency for non-PR jobs 18 | concurrency: 19 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 20 | env: 21 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 22 | permissions: 23 | contents: write 24 | steps: 25 | - uses: actions/checkout@v3 26 | 27 | - uses: r-lib/actions/setup-pandoc@v2 28 | 29 | - uses: r-lib/actions/setup-r@v2 30 | with: 31 | use-public-rspm: true 32 | 33 | - uses: r-lib/actions/setup-r-dependencies@v2 34 | with: 35 | extra-packages: any::pkgdown, local::. 36 | needs: website 37 | 38 | - name: Build site 39 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 40 | shell: Rscript {0} 41 | 42 | - name: Deploy to GitHub pages 🚀 43 | if: github.event_name != 'pull_request' 44 | uses: JamesIves/github-pages-deploy-action@v4.4.1 45 | with: 46 | clean: false 47 | branch: gh-pages 48 | folder: docs 49 | -------------------------------------------------------------------------------- /man/coercion-time-difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coercion.R 3 | \name{coercion-time-difference} 4 | \alias{coercion-time-difference} 5 | \alias{as.difftime} 6 | \alias{as.difftime.default} 7 | \title{Time difference coercion} 8 | \usage{ 9 | as.difftime(tim, ...) 10 | 11 | \method{as.difftime}{default}(tim, format = "\%X", units = "auto", ...) 12 | } 13 | \arguments{ 14 | \item{tim}{A vector specifying a time interval.} 15 | 16 | \item{...}{Other arguments passed on to methods.} 17 | 18 | \item{format}{A single character specifying the format of \code{tim} when it is 19 | a character. The default is a locale-specific time format.} 20 | 21 | \item{units}{A single character specifying units in which the results are 22 | desired. Required if \code{tim} is a numeric.} 23 | } 24 | \value{ 25 | A \code{difftime} object with an attribute indicating the units. 26 | } 27 | \description{ 28 | Coercion functions for creating \code{difftime} objects from other 29 | existing objects. 30 | } 31 | \details{ 32 | This function overrides the non-generic \code{as.difftime()} function 33 | provided in base so that packages can provide methods for different data 34 | types. The default method call the base version. 35 | } 36 | \section{Methods}{ 37 | 38 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("as.difftime")} 39 | } 40 | 41 | \examples{ 42 | as.difftime(1:5, units = "secs") 43 | 44 | as.difftime(c("01:55:22", "01:55:25")) 45 | 46 | as.difftime("01", format = "\%H") 47 | as.difftime("01", format = "\%H", units = "secs") 48 | 49 | } 50 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: test-coverage 10 | 11 | jobs: 12 | test-coverage: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - uses: r-lib/actions/setup-r@v2 21 | with: 22 | use-public-rspm: true 23 | 24 | - uses: r-lib/actions/setup-r-dependencies@v2 25 | with: 26 | extra-packages: any::covr 27 | needs: coverage 28 | 29 | - name: Test coverage 30 | run: | 31 | covr::codecov( 32 | quiet = FALSE, 33 | clean = FALSE, 34 | install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") 35 | ) 36 | shell: Rscript {0} 37 | 38 | - name: Show testthat output 39 | if: always() 40 | run: | 41 | ## -------------------------------------------------------------------- 42 | find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true 43 | shell: bash 44 | 45 | - name: Upload test results 46 | if: failure() 47 | uses: actions/upload-artifact@v3 48 | with: 49 | name: coverage-test-failures 50 | path: ${{ runner.temp }}/package 51 | -------------------------------------------------------------------------------- /R/tunable.R: -------------------------------------------------------------------------------- 1 | #' Declare tunable parameters 2 | #' 3 | #' Returns information on potential hyper-parameters that can be optimized. 4 | #' 5 | #' @param x An object, such as a recipe, recipe step, workflow, or model 6 | #' specification. 7 | #' @param ... Other arguments passed to methods 8 | #' 9 | #'@return A tibble with a column for the parameter `name`, information on the 10 | #' _default_ method for generating a corresponding parameter object, the 11 | #' `source` of the parameter (e.g. "recipe", etc.), and the `component` within 12 | #' the source. For the `component` column, a little more specificity is given 13 | #' about the location of the parameter (e.g. "step_normalize" for recipes or 14 | #' "boost_tree" for models). The `component_id` column contains the unique step 15 | #' `id` field or, for models, a logical for whether the model specification 16 | #' argument was a main parameter or one associated with the engine. 17 | #' @details 18 | #' For a model specification, an engine must be chosen. 19 | #' 20 | #' If the object has no tunable parameters, a tibble with no rows is returned. 21 | #' 22 | #' The information about the default parameter object takes the form of a 23 | #' named list with an element for the function call and an optional element for 24 | #' the source of the function (e.g. the `dials` package). For model 25 | #' specifications, If the parameter is unknown to the underlying `tunable` 26 | #' method, a `NULL` is returned. 27 | #' 28 | #' @section Methods: 29 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("tunable")} 30 | #' 31 | #' @export 32 | tunable <- function(x, ...) { 33 | UseMethod("tunable") 34 | } 35 | -------------------------------------------------------------------------------- /man/tunable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tunable.R 3 | \name{tunable} 4 | \alias{tunable} 5 | \title{Declare tunable parameters} 6 | \usage{ 7 | tunable(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An object, such as a recipe, recipe step, workflow, or model 11 | specification.} 12 | 13 | \item{...}{Other arguments passed to methods} 14 | } 15 | \value{ 16 | A tibble with a column for the parameter \code{name}, information on the 17 | \emph{default} method for generating a corresponding parameter object, the 18 | \code{source} of the parameter (e.g. "recipe", etc.), and the \code{component} within 19 | the source. For the \code{component} column, a little more specificity is given 20 | about the location of the parameter (e.g. "step_normalize" for recipes or 21 | "boost_tree" for models). The \code{component_id} column contains the unique step 22 | \code{id} field or, for models, a logical for whether the model specification 23 | argument was a main parameter or one associated with the engine. 24 | } 25 | \description{ 26 | Returns information on potential hyper-parameters that can be optimized. 27 | } 28 | \details{ 29 | For a model specification, an engine must be chosen. 30 | 31 | If the object has no tunable parameters, a tibble with no rows is returned. 32 | 33 | The information about the default parameter object takes the form of a 34 | named list with an element for the function call and an optional element for 35 | the source of the function (e.g. the \code{dials} package). For model 36 | specifications, If the parameter is unknown to the underlying \code{tunable} 37 | method, a \code{NULL} is returned. 38 | } 39 | \section{Methods}{ 40 | 41 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("tunable")} 42 | } 43 | 44 | -------------------------------------------------------------------------------- /man/generics-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics-package.R 3 | \docType{package} 4 | \name{generics-package} 5 | \alias{generics} 6 | \alias{generics-package} 7 | \title{generics: common S3 generics} 8 | \description{ 9 | These are generic functions that can be used to minimize 10 | package dependencies when multiple packages have the same 11 | method. 12 | } 13 | \details{ 14 | An attempt was made to use generic class signatures that were 15 | consistent with existing code. For example, \pkg{dplyr} and 16 | \pkg{lime} both have \code{explain()} methods that do very different 17 | things but both take \code{x} as their main object. Even though \code{x} 18 | would be different in those cases, this package provides access 19 | to the S3 generic so that other packages that may want to create 20 | \code{explain()} methods for their objects can do so without loading 21 | either of the other packages. 22 | 23 | For example, if a new \code{tidy()} method is being developed for a 24 | package, this lightweight package can be the required dependency 25 | to have access to the generic method (instead of depending on 26 | \pkg{broom} and installing its dependencies). 27 | } 28 | \seealso{ 29 | Useful links: 30 | \itemize{ 31 | \item \url{https://generics.r-lib.org} 32 | \item \url{https://github.com/r-lib/generics} 33 | \item Report bugs at \url{https://github.com/r-lib/generics/issues} 34 | } 35 | 36 | } 37 | \author{ 38 | \strong{Maintainer}: Hadley Wickham \email{hadley@posit.co} 39 | 40 | Authors: 41 | \itemize{ 42 | \item Max Kuhn \email{max@posit.co} 43 | \item Davis Vaughan \email{davis@posit.co} 44 | } 45 | 46 | Other contributors: 47 | \itemize{ 48 | \item Posit Software, PBC [copyright holder, funder] 49 | } 50 | 51 | } 52 | \keyword{internal} 53 | -------------------------------------------------------------------------------- /man/setops.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sets.R 3 | \name{setops} 4 | \alias{setops} 5 | \alias{intersect} 6 | \alias{union} 7 | \alias{setdiff} 8 | \alias{setequal} 9 | \alias{is.element} 10 | \title{Set operations} 11 | \usage{ 12 | intersect(x, y, ...) 13 | 14 | union(x, y, ...) 15 | 16 | setdiff(x, y, ...) 17 | 18 | setequal(x, y, ...) 19 | 20 | is.element(el, set, ...) 21 | } 22 | \arguments{ 23 | \item{x, y}{Vectors to combine.} 24 | 25 | \item{...}{Other arguments passed on to methods.} 26 | 27 | \item{el, set}{Element and set to compare.} 28 | } 29 | \value{ 30 | For \code{union()}, \code{intersect()}, and \code{setdiff()}, a vector with all 31 | duplicate removed. 32 | 33 | For \code{setequal()} and \code{is.element()}, a logical \code{TRUE} or \code{FALSE}.` 34 | } 35 | \description{ 36 | Union (\code{union()}), intersect (\code{intersect()}), difference (\code{setdiff()}), 37 | and equality (\code{setequal()}) for two vectors representing sets. Determine 38 | membership with \code{is.element()}. 39 | } 40 | \details{ 41 | These functions override the set functions provided in base to make them 42 | generic so that packages can provide methods for different data types. The 43 | default methods call the base versions. 44 | } 45 | \section{Methods}{ 46 | 47 | 48 | \subsection{\code{intersect()}}{ 49 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("intersect")} 50 | } 51 | 52 | \subsection{\code{union()}}{ 53 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("union")} 54 | } 55 | 56 | \subsection{\code{setdiff()}}{ 57 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("setdiff")} 58 | } 59 | 60 | \subsection{\code{setequal()}}{ 61 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("setequal")} 62 | } 63 | 64 | \subsection{\code{is.element()}}{ 65 | \Sexpr[stage=render,results=rd]{generics:::methods_rd("is.element")} 66 | } 67 | } 68 | 69 | \examples{ 70 | intersect(1:5, 4:8) 71 | union(1:5, 4:8) 72 | 73 | setdiff(1:5, 4:8) 74 | setdiff(4:8, 1:5) 75 | } 76 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | # 4 | # NOTE: This workflow is overkill for most R packages and 5 | # check-standard.yaml is likely a better choice. 6 | # usethis::use_github_action("check-standard") will install it. 7 | on: 8 | push: 9 | branches: [main, master] 10 | pull_request: 11 | branches: [main, master] 12 | 13 | name: R-CMD-check 14 | 15 | jobs: 16 | R-CMD-check: 17 | runs-on: ${{ matrix.config.os }} 18 | 19 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 20 | 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | config: 25 | - {os: macos-latest, r: 'release'} 26 | 27 | - {os: windows-latest, r: 'release'} 28 | # Use 3.6 to trigger usage of RTools35 29 | - {os: windows-latest, r: '3.6'} 30 | # use 4.1 to check with rtools40's older compiler 31 | - {os: windows-latest, r: '4.1'} 32 | 33 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 34 | - {os: ubuntu-latest, r: 'release'} 35 | - {os: ubuntu-latest, r: 'oldrel-1'} 36 | - {os: ubuntu-latest, r: 'oldrel-2'} 37 | - {os: ubuntu-latest, r: 'oldrel-3'} 38 | - {os: ubuntu-latest, r: 'oldrel-4'} 39 | 40 | env: 41 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 42 | R_KEEP_PKG_SOURCE: yes 43 | 44 | steps: 45 | - uses: actions/checkout@v3 46 | 47 | - uses: r-lib/actions/setup-pandoc@v2 48 | 49 | - uses: r-lib/actions/setup-r@v2 50 | with: 51 | r-version: ${{ matrix.config.r }} 52 | http-user-agent: ${{ matrix.config.http-user-agent }} 53 | use-public-rspm: true 54 | 55 | - uses: r-lib/actions/setup-r-dependencies@v2 56 | with: 57 | extra-packages: any::rcmdcheck 58 | needs: check 59 | 60 | - uses: r-lib/actions/check-r-package@v2 61 | with: 62 | upload-snapshots: true 63 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | ```{r setup, include = FALSE} 6 | knitr::opts_chunk$set(collapse = TRUE, comment = "#>") 7 | ``` 8 | 9 | # generics 10 | 11 | 12 | [![R-CMD-check](https://github.com/r-lib/generics/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/generics/actions/workflows/R-CMD-check.yaml) 13 | [![Codecov test coverage](https://codecov.io/gh/r-lib/generics/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/generics?branch=main) 14 | 15 | 16 | `generics` is designed to help package authors reduce dependencies by providing a set of generic methods that can be imported. For example, if a package author wanted to include a `tidy` method for their object, they would have to import the `broom` package to do so. This would work but would potentially increase the number of package dependencies required to install and/or test the package. 17 | 18 | ## Installation 19 | 20 | To install `generics` from CRAN, use: 21 | 22 | ```{r, eval = FALSE} 23 | install.packages("generics") 24 | ``` 25 | 26 | To install the development version, use: 27 | 28 | ```{r, eval = FALSE} 29 | # install.packages("pak") 30 | pak::pak("r-lib/generics") 31 | ``` 32 | 33 | ## Usage 34 | 35 | `generics` is a simple, lightweight package that contains S3 generics to be used by other packages. Some examples are: 36 | 37 | ```{r} 38 | library(generics) 39 | 40 | fit 41 | 42 | tidy 43 | ``` 44 | 45 | To use `generics` with your package, we recommend that you import and re-export the generic(s) of interest. For example, if you want to provide a method for the S3 `explain()` method, you'd using the following `roxygen2` code: 46 | 47 | ``` {r, eval = FALSE} 48 | #' @importFrom generics explain 49 | #' @export 50 | generics::explain 51 | ``` 52 | 53 | As an example, the [recipes](https://github.com/tidymodels/recipes) package defines a number of `tidy()` S3 methods by importing this package (whereas it previously depended on `broom`). 54 | 55 | ## Documentation 56 | 57 | When searching for help on a method that is exported from `generics` by one or more packages, using `?method` will show entries for all exported methods. If the version from `generics` is selected, the Methods section dynamically lists all specific methods exported by any loaded packages. 58 | -------------------------------------------------------------------------------- /R/sets.R: -------------------------------------------------------------------------------- 1 | #' Set operations 2 | #' 3 | #' Union (`union()`), intersect (`intersect()`), difference (`setdiff()`), 4 | #' and equality (`setequal()`) for two vectors representing sets. Determine 5 | #' membership with `is.element()`. 6 | #' 7 | #' These functions override the set functions provided in base to make them 8 | #' generic so that packages can provide methods for different data types. The 9 | #' default methods call the base versions. 10 | #' 11 | #' @section Methods: 12 | #' 13 | #' \subsection{`intersect()`}{ 14 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("intersect")} 15 | #' } 16 | #' 17 | #' \subsection{`union()`}{ 18 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("union")} 19 | #' } 20 | #' 21 | #' \subsection{`setdiff()`}{ 22 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("setdiff")} 23 | #' } 24 | #' 25 | #' \subsection{`setequal()`}{ 26 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("setequal")} 27 | #' } 28 | #' 29 | #' \subsection{`is.element()`}{ 30 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("is.element")} 31 | #' } 32 | #' 33 | #' @param x,y Vectors to combine. 34 | #' @param el,set Element and set to compare. 35 | #' @param ... Other arguments passed on to methods. 36 | #' @return For `union()`, `intersect()`, and `setdiff()`, a vector with all 37 | #' duplicate removed. 38 | #' 39 | #' For `setequal()` and `is.element()`, a logical `TRUE` or `FALSE`.` 40 | #' @name setops 41 | #' @examples 42 | #' intersect(1:5, 4:8) 43 | #' union(1:5, 4:8) 44 | #' 45 | #' setdiff(1:5, 4:8) 46 | #' setdiff(4:8, 1:5) 47 | NULL 48 | 49 | #' @rdname setops 50 | #' @export 51 | intersect <- function(x, y, ...) UseMethod("intersect") 52 | #' @rdname setops 53 | #' @export 54 | union <- function(x, y, ...) UseMethod("union") 55 | #' @rdname setops 56 | #' @export 57 | setdiff <- function(x, y, ...) UseMethod("setdiff") 58 | #' @rdname setops 59 | #' @export 60 | setequal <- function(x, y, ...) UseMethod("setequal") 61 | #' @rdname setops 62 | #' @export 63 | is.element <- function(el, set, ...) UseMethod("is.element") 64 | 65 | #' @export 66 | intersect.default <- function(x, y, ...) base::intersect(x, y, ...) 67 | #' @export 68 | union.default <- function(x, y, ...) base::union(x, y, ...) 69 | #' @export 70 | setdiff.default <- function(x, y, ...) base::setdiff(x, y, ...) 71 | #' @export 72 | setequal.default <- function(x, y, ...) base::setequal(x, y, ...) 73 | #' @export 74 | is.element.default <- function(el, set, ...) base::is.element(el, set, ...) 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # generics 3 | 4 | 5 | 6 | [![R-CMD-check](https://github.com/r-lib/generics/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/generics/actions/workflows/R-CMD-check.yaml) 7 | [![Codecov test 8 | coverage](https://codecov.io/gh/r-lib/generics/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/generics?branch=main) 9 | 10 | 11 | `generics` is designed to help package authors reduce dependencies by 12 | providing a set of generic methods that can be imported. For example, if 13 | a package author wanted to include a `tidy` method for their object, 14 | they would have to import the `broom` package to do so. This would work 15 | but would potentially increase the number of package dependencies 16 | required to install and/or test the package. 17 | 18 | ## Installation 19 | 20 | To install `generics` from CRAN, use: 21 | 22 | ``` r 23 | install.packages("generics") 24 | ``` 25 | 26 | To install the development version, use: 27 | 28 | ``` r 29 | # install.packages("pak") 30 | pak::pak("r-lib/generics") 31 | ``` 32 | 33 | ## Usage 34 | 35 | `generics` is a simple, lightweight package that contains S3 generics to 36 | be used by other packages. Some examples are: 37 | 38 | ``` r 39 | library(generics) 40 | #> 41 | #> Attaching package: 'generics' 42 | #> The following objects are masked from 'package:base': 43 | #> 44 | #> as.difftime, as.factor, as.ordered, intersect, is.element, setdiff, 45 | #> setequal, union 46 | 47 | fit 48 | #> function(object, ...) { 49 | #> UseMethod("fit") 50 | #> } 51 | #> 52 | #> 53 | 54 | tidy 55 | #> function(x, ...) { 56 | #> UseMethod("tidy") 57 | #> } 58 | #> 59 | #> 60 | ``` 61 | 62 | To use `generics` with your package, we recommend that you import and 63 | re-export the generic(s) of interest. For example, if you want to 64 | provide a method for the S3 `explain()` method, you’d using the 65 | following `roxygen2` code: 66 | 67 | ``` r 68 | #' @importFrom generics explain 69 | #' @export 70 | generics::explain 71 | ``` 72 | 73 | As an example, the [recipes](https://github.com/tidymodels/recipes) 74 | package defines a number of `tidy()` S3 methods by importing this 75 | package (whereas it previously depended on `broom`). 76 | 77 | ## Documentation 78 | 79 | When searching for help on a method that is exported from `generics` by 80 | one or more packages, using `?method` will show entries for all exported 81 | methods. If the version from `generics` is selected, the Methods section 82 | dynamically lists all specific methods exported by any loaded packages. 83 | -------------------------------------------------------------------------------- /.github/workflows/pr-commands.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | issue_comment: 5 | types: [created] 6 | 7 | name: Commands 8 | 9 | jobs: 10 | document: 11 | if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }} 12 | name: document 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | steps: 17 | - uses: actions/checkout@v3 18 | 19 | - uses: r-lib/actions/pr-fetch@v2 20 | with: 21 | repo-token: ${{ secrets.GITHUB_TOKEN }} 22 | 23 | - uses: r-lib/actions/setup-r@v2 24 | with: 25 | use-public-rspm: true 26 | 27 | - uses: r-lib/actions/setup-r-dependencies@v2 28 | with: 29 | extra-packages: any::roxygen2 30 | needs: pr-document 31 | 32 | - name: Document 33 | run: roxygen2::roxygenise() 34 | shell: Rscript {0} 35 | 36 | - name: commit 37 | run: | 38 | git config --local user.name "$GITHUB_ACTOR" 39 | git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" 40 | git add man/\* NAMESPACE 41 | git commit -m 'Document' 42 | 43 | - uses: r-lib/actions/pr-push@v2 44 | with: 45 | repo-token: ${{ secrets.GITHUB_TOKEN }} 46 | 47 | style: 48 | if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }} 49 | name: style 50 | runs-on: ubuntu-latest 51 | env: 52 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 53 | steps: 54 | - uses: actions/checkout@v3 55 | 56 | - uses: r-lib/actions/pr-fetch@v2 57 | with: 58 | repo-token: ${{ secrets.GITHUB_TOKEN }} 59 | 60 | - uses: r-lib/actions/setup-r@v2 61 | 62 | - name: Install dependencies 63 | run: install.packages("styler") 64 | shell: Rscript {0} 65 | 66 | - name: Style 67 | run: styler::style_pkg() 68 | shell: Rscript {0} 69 | 70 | - name: commit 71 | run: | 72 | git config --local user.name "$GITHUB_ACTOR" 73 | git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" 74 | git add \*.R 75 | git commit -m 'Style' 76 | 77 | - uses: r-lib/actions/pr-push@v2 78 | with: 79 | repo-token: ${{ secrets.GITHUB_TOKEN }} 80 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/docs.md: -------------------------------------------------------------------------------- 1 | # generics methods can be reexported and extended 2 | 3 | Code 4 | methods_rd("tidy") 5 | Output 6 | [1] "See the following help topics for more details about individual methods:\n\n\\code{testGenericsExtension}\n\\itemize{\n\\item \\code{\\link[testGenericsExtension]{tidy-special}}: \\code{special_method}\n}" 7 | 8 | # multiple packages have multiple headers 9 | 10 | Code 11 | methods_rd("multi_method") 12 | Output 13 | [1] "See the following help topics for more details about individual methods:\n\n\\code{testMultiMethod}\n\\itemize{\n\\item \\code{\\link[testMultiMethod]{multi-method-2}}: \\code{default}\n\\item \\code{\\link[testMultiMethod]{multi-method-3}}: \\code{data.frame}\n}\n\\code{testMultiPackage}\n\\itemize{\n\\item \\code{\\link[testMultiPackage]{multi-method-4}}: \\code{matrix}\n}" 14 | 15 | # S4 bullets print with no issues 16 | 17 | Code 18 | methods_rd("multi_method") 19 | Output 20 | [1] "See the following help topics for more details about individual methods:\n\n\\code{testS4Docs}\n\\itemize{\n\\item \\code{\\link[testS4Docs]{multi_method}}: \\code{ANY,ANY}, \\code{numeric,ANY}, \\code{numeric,integer}\n}" 21 | 22 | # S4 and S3 packages can intermingle 23 | 24 | Code 25 | methods_rd("multi_method") 26 | Output 27 | [1] "See the following help topics for more details about individual methods:\n\n\\code{testMultiMethod}\n\\itemize{\n\\item \\code{\\link[testMultiMethod]{multi-method-2}}: \\code{default}\n\\item \\code{\\link[testMultiMethod]{multi-method-3}}: \\code{data.frame}\n}\n\\code{testS4Docs}\n\\itemize{\n\\item \\code{\\link[testS4Docs]{multi_method}}: \\code{ANY,ANY}, \\code{numeric,ANY}, \\code{numeric,integer}\n}" 28 | 29 | # multiple methods but same rdname are comma separated 30 | 31 | Code 32 | methods_rd("same_rd_name") 33 | Output 34 | [1] "See the following help topics for more details about individual methods:\n\n\\code{testSameRd}\n\\itemize{\n\\item \\code{\\link[testSameRd]{same_rd_name-2}}: \\code{data.frame}, \\code{default}\n}" 35 | 36 | # single method is correctly itemized 37 | 38 | Code 39 | methods_rd("single_method") 40 | Output 41 | [1] "See the following help topics for more details about individual methods:\n\n\\code{testSingleMethod}\n\\itemize{\n\\item \\code{\\link[testSingleMethod]{single-method-2}}: \\code{default}\n}" 42 | 43 | # multiple methods are correctly itemized 44 | 45 | Code 46 | methods_rd("multi_method") 47 | Output 48 | [1] "See the following help topics for more details about individual methods:\n\n\\code{testMultiMethod}\n\\itemize{\n\\item \\code{\\link[testMultiMethod]{multi-method-2}}: \\code{default}\n\\item \\code{\\link[testMultiMethod]{multi-method-3}}: \\code{data.frame}\n}" 49 | 50 | -------------------------------------------------------------------------------- /R/coercion.R: -------------------------------------------------------------------------------- 1 | #' Factor coercion 2 | #' 3 | #' Coercion functions for creating factors from other existing objects. 4 | #' 5 | #' These functions override non-generic factor coercion functions provided 6 | #' in base so that packages can provide methods for different data types. The 7 | #' default methods call the base versions. 8 | #' 9 | #' @section Methods: 10 | #' 11 | #' \subsection{`as.factor()`}{ 12 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("as.factor")} 13 | #' } 14 | #' 15 | #' \subsection{`as.ordered()`}{ 16 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("as.ordered")} 17 | #' } 18 | #' 19 | #' 20 | #' @param x A vector of data. 21 | #' @param ... Other arguments passed on to methods. 22 | #' @return For `as.factor()`, a factor. For `as.ordered()`, 23 | #' an ordered factor. 24 | #' 25 | #' @name coercion-factor 26 | #' 27 | #' @examples 28 | #' as.factor(letters[1:5]) 29 | #' as.ordered(letters[1:5]) 30 | #' 31 | NULL 32 | 33 | #' @rdname coercion-factor 34 | #' @export 35 | as.factor <- function(x, ...) UseMethod("as.factor") 36 | 37 | #' @rdname coercion-factor 38 | #' @export 39 | as.ordered <- function(x, ...) UseMethod("as.ordered") 40 | 41 | 42 | #' @export 43 | as.factor.default <- function(x, ...) base::as.factor(x) 44 | 45 | #' @export 46 | as.ordered.default <- function(x, ...) base::as.ordered(x) 47 | 48 | 49 | #' Time difference coercion 50 | #' 51 | #' Coercion functions for creating `difftime` objects from other 52 | #' existing objects. 53 | #' 54 | #' This function overrides the non-generic `as.difftime()` function 55 | #' provided in base so that packages can provide methods for different data 56 | #' types. The default method call the base version. 57 | #' 58 | #' @section Methods: 59 | #' \Sexpr[stage=render,results=rd]{generics:::methods_rd("as.difftime")} 60 | #' 61 | #' @param tim A vector specifying a time interval. 62 | #' @param format A single character specifying the format of `tim` when it is 63 | #' a character. The default is a locale-specific time format. 64 | #' @param units A single character specifying units in which the results are 65 | #' desired. Required if `tim` is a numeric. 66 | #' @param ... Other arguments passed on to methods. 67 | #' @return A `difftime` object with an attribute indicating the units. 68 | #' 69 | #' @name coercion-time-difference 70 | #' 71 | #' @examples 72 | #' as.difftime(1:5, units = "secs") 73 | #' 74 | #' as.difftime(c("01:55:22", "01:55:25")) 75 | #' 76 | #' as.difftime("01", format = "%H") 77 | #' as.difftime("01", format = "%H", units = "secs") 78 | #' 79 | NULL 80 | 81 | #' @rdname coercion-time-difference 82 | #' @export 83 | as.difftime <- function(tim, ...) UseMethod("as.difftime") 84 | 85 | 86 | #' @rdname coercion-time-difference 87 | #' @export 88 | as.difftime.default <- function(tim, format = "%X", units = "auto", ...) 89 | base::as.difftime(tim = tim, format = format, units = units, ...) 90 | -------------------------------------------------------------------------------- /R/docs.R: -------------------------------------------------------------------------------- 1 | # Modified from sloop::methods_generic 2 | methods_find <- function(x) { 3 | info <- attr(utils::methods(x), "info") 4 | 5 | if (nrow(info) == 0) { 6 | info$topic <- character() 7 | return(info) 8 | } 9 | 10 | info$method <- rownames(info) 11 | rownames(info) <- NULL 12 | 13 | # Simply class and source 14 | generic_esc <- gsub("\\.", "\\\\.", x) 15 | info$class <- gsub(paste0("^", generic_esc, "[.,]"), "", info$method) 16 | info$class <- gsub("-method$", "", info$class) 17 | info$source <- gsub(paste0(" for ", generic_esc), "", info$from) 18 | 19 | # Find package 20 | info$package <- lookup_package(x, info$class, info$isS4) 21 | 22 | # Find help topic 23 | path <- help_path(info$method, info$package) 24 | pieces <- strsplit(path, "/") 25 | info$topic <- vapply(pieces, last, character(1)) 26 | 27 | info[c("method", "class", "package", "topic", "visible", "source")] 28 | } 29 | 30 | methods_rd <- function(x) { 31 | methods <- methods_find(x) 32 | methods <- methods[!is.na(methods$topic), , drop = FALSE] 33 | 34 | if (nrow(methods) == 0) { 35 | return("No methods found in currently loaded packages.") 36 | } 37 | 38 | methods_by_package <- split(methods, methods$package) 39 | 40 | topics_by_package <- lapply(methods_by_package, function(x) { 41 | split(x, paste(x$topic, x$package, sep = ".")) 42 | }) 43 | 44 | make_bullets <- function(topics) { 45 | bullet_vec <- vapply( 46 | X = topics, 47 | FUN = function(x) { 48 | link <- paste0( 49 | "\\code{", 50 | "\\link[", x$package[[1]], "]", 51 | "{", x$topic[[1]], "}", 52 | "}" 53 | ) 54 | classes <- paste0("\\code{", x$class, "}", collapse = ", ") 55 | paste0("\\item ", link, ": ", classes) 56 | }, 57 | FUN.VALUE = character(1), 58 | USE.NAMES = FALSE 59 | ) 60 | 61 | paste0(bullet_vec, collapse = "\n") 62 | } 63 | 64 | make_header <- function(pkg) { 65 | paste0("\\code{", pkg, "}") 66 | } 67 | 68 | bullets <- lapply(topics_by_package, make_bullets) 69 | headers <- lapply(names(topics_by_package), make_header) 70 | 71 | help_msg <- paste0( 72 | "See the following help topics for more details about individual methods:\n" 73 | ) 74 | 75 | paste0( 76 | c(help_msg, 77 | paste( 78 | headers, 79 | "\\itemize{", 80 | bullets, 81 | "}", 82 | sep = "\n" 83 | ) 84 | ), 85 | collapse = "\n" 86 | ) 87 | 88 | } 89 | 90 | last <- function(x, n = 0) { 91 | if (length(x) <= n) { 92 | x[NA_integer_] 93 | } else { 94 | x[[length(x) - n]] 95 | } 96 | } 97 | 98 | help_path <- function(x, package) { 99 | 100 | help <- mapply(locate_help_doc, x, package, SIMPLIFY = FALSE) 101 | 102 | vapply(help, 103 | function(x) if (length(x) == 0) NA_character_ else as.character(x), 104 | FUN.VALUE = character(1) 105 | ) 106 | } 107 | 108 | locate_help_doc <- function(x, package) { 109 | help <- if (requireNamespace("pkgload", quietly = TRUE)) { 110 | shim_help <- get("shim_help", asNamespace("pkgload")) 111 | function(x, package = NULL) { 112 | tryCatch( 113 | expr = shim_help(x, (package)), 114 | error = function(e) character() 115 | ) 116 | } 117 | } else { 118 | utils::help 119 | } 120 | 121 | if (is.na(package)) { 122 | help(x) 123 | } else { 124 | help(x, (package)) 125 | } 126 | } 127 | 128 | #' @export 129 | as.character.dev_topic <- function(x, ...) { 130 | sub("[.]Rd$", "", x$path) 131 | } 132 | 133 | lookup_package <- function(generic, class, is_s4) { 134 | 135 | lookup_single_package <- function(generic, class, is_s4) { 136 | 137 | if (is_s4) { 138 | 139 | class <- strsplit(class, ",")[[1]] 140 | fn <- methods::getMethod(generic, class, optional = TRUE) 141 | 142 | } else { 143 | 144 | fn <- utils::getS3method(generic, class, optional = TRUE) 145 | 146 | } 147 | 148 | # Not found 149 | if (is.null(fn)) { 150 | return(NA_character_) 151 | } 152 | 153 | pkg <- utils::packageName(environment(fn)) 154 | 155 | # Function method found, but in a non-package environment 156 | if (is.null(pkg)) { 157 | return(NA_character_) 158 | } 159 | 160 | pkg 161 | } 162 | 163 | pkgs <- mapply(lookup_single_package, generic, class, is_s4, SIMPLIFY = FALSE) 164 | as.vector(pkgs, "character") 165 | } 166 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, caste, color, religion, or sexual 10 | identity and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or advances of 31 | any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email address, 35 | without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at codeofconduct@posit.co. 63 | All complaints will be reviewed and investigated promptly and fairly. 64 | 65 | All community leaders are obligated to respect the privacy and security of the 66 | reporter of any incident. 67 | 68 | ## Enforcement Guidelines 69 | 70 | Community leaders will follow these Community Impact Guidelines in determining 71 | the consequences for any action they deem in violation of this Code of Conduct: 72 | 73 | ### 1. Correction 74 | 75 | **Community Impact**: Use of inappropriate language or other behavior deemed 76 | unprofessional or unwelcome in the community. 77 | 78 | **Consequence**: A private, written warning from community leaders, providing 79 | clarity around the nature of the violation and an explanation of why the 80 | behavior was inappropriate. A public apology may be requested. 81 | 82 | ### 2. Warning 83 | 84 | **Community Impact**: A violation through a single incident or series of 85 | actions. 86 | 87 | **Consequence**: A warning with consequences for continued behavior. No 88 | interaction with the people involved, including unsolicited interaction with 89 | those enforcing the Code of Conduct, for a specified period of time. This 90 | includes avoiding interactions in community spaces as well as external channels 91 | like social media. Violating these terms may lead to a temporary or permanent 92 | ban. 93 | 94 | ### 3. Temporary Ban 95 | 96 | **Community Impact**: A serious violation of community standards, including 97 | sustained inappropriate behavior. 98 | 99 | **Consequence**: A temporary ban from any sort of interaction or public 100 | communication with the community for a specified period of time. No public or 101 | private interaction with the people involved, including unsolicited interaction 102 | with those enforcing the Code of Conduct, is allowed during this period. 103 | Violating these terms may lead to a permanent ban. 104 | 105 | ### 4. Permanent Ban 106 | 107 | **Community Impact**: Demonstrating a pattern of violation of community 108 | standards, including sustained inappropriate behavior, harassment of an 109 | individual, or aggression toward or disparagement of classes of individuals. 110 | 111 | **Consequence**: A permanent ban from any sort of public interaction within the 112 | community. 113 | 114 | ## Attribution 115 | 116 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 117 | version 2.1, available at 118 | . 119 | 120 | Community Impact Guidelines were inspired by 121 | [Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion]. 122 | 123 | For answers to common questions about this code of conduct, see the FAQ at 124 | . Translations are available at . 125 | 126 | [homepage]: https://www.contributor-covenant.org 127 | --------------------------------------------------------------------------------