Skip to content

Clarify how to extend tibbles #275

@hadley

Description

@hadley

By following the principles defined at http://adv-r.hadley.nz/s3.html#inheritance

  • Provide a constructor that can also be used to create subclassed objects

    new_tibble <- function(data, ..., subclass = NULL) {
      stopifnot(is.data.frame(data))
      
      structure(
        data,
        ...,
        class = c(subclass, "tibble", "tbl_df", "data.frame")
      )
    }
  • Provide a reconstruct method

     reconstruct.tibble <- function(new, old) {
       new_tibble(new)
     }
  • Call S3::reconstruct() in all methods that return a tibble

This supersedes #155, #211, #218.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions