{"id":32207741,"url":"https://github.com/rconsortium/s7","last_synced_at":"2025-10-22T05:59:01.865Z","repository":{"id":37868725,"uuid":"261290944","full_name":"RConsortium/S7","owner":"RConsortium","description":"S7: a new OO system for R","archived":false,"fork":false,"pushed_at":"2025-08-27T14:10:26.000Z","size":8581,"stargazers_count":469,"open_issues_count":121,"forks_count":40,"subscribers_count":25,"default_branch":"main","last_synced_at":"2025-10-22T05:59:01.084Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://rconsortium.github.io/S7","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RConsortium.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-05-04T20:40:58.000Z","updated_at":"2025-10-14T12:23:01.000Z","dependencies_parsed_at":"2023-10-14T21:19:06.542Z","dependency_job_id":"835696ce-46dd-4617-a970-b879fadf338a","html_url":"https://github.com/RConsortium/S7","commit_stats":null,"previous_names":["rconsortium/s7","rconsortium/oop-wg"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/RConsortium/S7","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RConsortium%2FS7","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RConsortium%2FS7/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RConsortium%2FS7/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RConsortium%2FS7/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RConsortium","download_url":"https://codeload.github.com/RConsortium/S7/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RConsortium%2FS7/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280389299,"owners_count":26322507,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-22T05:58:57.345Z","updated_at":"2025-10-22T05:59:01.860Z","avatar_url":"https://github.com/RConsortium.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# S7\n\n\u003c!-- badges: start --\u003e\n\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\n[![R-CMD-check](https://github.com/RConsortium/S7/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/RConsortium/S7/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/RConsortium/S7/branch/main/graph/badge.svg)](https://app.codecov.io/gh/RConsortium/S7?branch=main)\n\u003c!-- badges: end --\u003e\n\nThe S7 package is a new OOP system designed to be a successor to S3 and S4.\nIt has been designed and implemented collaboratively by the R Consortium Object-Oriented Programming Working Group, which includes representatives from R-Core, Bioconductor, the tidyverse/Posit, and the wider R community.\n\nS7 is somewhat experimental; we are confident in the design but it has relatively little usage in the wild currently.\nWe hope to avoid any major breaking changes, but reserve the right if we discover major problems.\n\n## Installation\n\nThe long-term goal of this project is to merge S7 in to base R.\nFor now, you can experiment by installing it from CRAN:\n\n```{r, eval = FALSE}\ninstall.packages(\"S7\")\n```\n\n## Usage\n\nThis section gives a very brief overview of the entirety of S7.\nLearn more of the basics in `vignette(\"S7\")`, generics and methods in `vignette(\"generics-methods\")`, classes and objects in `vignette(\"classes-objects\")`, and compatibility with S3 and S4 in `vignette(\"compatibility\")`.\n\n```{r}\nlibrary(S7)\n```\n\n### Classes and objects\n\nS7 classes have a formal definition, which includes a list of properties and an optional validator.\nUse `new_class()` to define a class:\n\n```{r}\nrange \u003c- new_class(\"range\",\n  properties = list(\n    start = class_double,\n    end = class_double\n  ),\n  validator = function(self) {\n    if (length(self@start) != 1) {\n      \"@start must be length 1\"\n    } else if (length(self@end) != 1) {\n      \"@end must be length 1\"\n    } else if (self@end \u003c self@start) {\n      \"@end must be greater than or equal to @start\"\n    }\n  }\n)\n```\n\n`new_class()` returns the class object, which is also the constructor you use to create instances of the class:\n\n```{r}\nx \u003c- range(start = 1, end = 10)\nx\n```\n\n### Properties\n\nThe data possessed by an object is called its **properties**.\nUse `@` to get and set properties:\n\n```{r}\nx@start\nx@end \u003c- 20\nx\n```\n\nProperties are automatically validated against the type declared in `new_class()` (`double` in this case), and with the class **validator**:\n\n```{r, error = TRUE}\nx@end \u003c- \"x\"\nx@end \u003c- -1\n```\n\n### Generics and methods\n\nLike S3 and S4, S7 uses **functional OOP** where methods belong to **generic** functions, and method calls look like all other function calls: `generic(object, arg2, arg3)`.\nThis style is called functional because from the outside it looks like a regular function call, and internally the components are also functions.\n\nUse `new_generic()` to create a new generic: the first argument is the generic name (used in error messages) and the second gives the arguments used for dispatch.\nThe third, and optional argument, supplies the body of the generic.\nThis is only needed if your generic has additional arguments that aren't used for method dispatch.\n\n```{r}\ninside \u003c- new_generic(\"inside\", \"x\")\n```\n\nOnce you have a generic, you can define a method for a specific class with `method\u003c-`:\n\n```{r}\n# Add a method for our class\nmethod(inside, range) \u003c- function(x, y) {\n  y \u003e= x@start \u0026 y \u003c= x@end\n}\n\ninside(x, c(0, 5, 10, 15))\n```\n\nYou can use `method\u003c-` to register methods for base types on S7 generics, and S7 classes on S3 or S4 generics.\nSee `vignette(\"compatibility\")` for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frconsortium%2Fs7","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frconsortium%2Fs7","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frconsortium%2Fs7/lists"}