Git Product home page Git Product logo

generics's Introduction

generics

R-CMD-check Codecov test coverage

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.

Installation

To install generics from CRAN, use:

install.packages("generics")

To install the development version, use:

install.packages("devtools")
devtools::install_github("r-lib/generics")

Usage

generics is a simple, lightweight package that contains S3 generics to be used by other packages. Some examples are:

library(generics)
#> 
#> Attaching package: 'generics'
#> The following objects are masked from 'package:base':
#> 
#>     as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
#>     setequal, union

fit
#> function(object, ...) {
#>   UseMethod("fit")
#> }
#> <bytecode: 0x7fca8cc62a30>
#> <environment: namespace:generics>

tidy
#> function(x, ...) {
#>   UseMethod("tidy")
#> }
#> <bytecode: 0x7fca6c986cf8>
#> <environment: namespace:generics>

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:

#' @importFrom generics explain
#' @export
generics::explain

As an example, the recipes package defines a number of tidy() S3 methods by importing this package (whereas it previously depended on broom).

Documentation

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.

generics's People

Contributors

alexpghayes avatar batpigandme avatar davisvaughan avatar dpprdan avatar hadley avatar jimhester avatar mitchelloharawild avatar topepo avatar

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

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

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.