Skip to content

Commit

Permalink
Merge commit '0b7300e397558f76567e903effb83176a5cba872'
Browse files Browse the repository at this point in the history
#Conflicts:
#	NEWS.md
  • Loading branch information
hadley committed Nov 23, 2023
2 parents d416e73 + 0b7300e commit 5678b41
Show file tree
Hide file tree
Showing 42 changed files with 567 additions and 363 deletions.
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: S7
Title:
An Object Oriented System Meant to Become a Successor to S3 and S4
Version: 0.1.0.9000
Version: 0.1.1.9000
Authors@R: c(
person("Object-Oriented Programming Working Group", role = "cph"),
person("Davis", "Vaughan", role = "aut"),
Expand All @@ -25,7 +25,7 @@ Description: A new object oriented programming system designed to be a successor
License: MIT + file LICENSE
URL: https://github.com/rconsortium/S7/,
https://rconsortium.github.io/S7/
BugReports: https://github.com/rconsortium/OOP-WG/issues
BugReports: https://github.com/rconsortium/S7/issues
Depends:
R (>= 3.5.0)
Imports:
Expand All @@ -36,12 +36,14 @@ Suggests:
knitr,
methods,
rmarkdown,
testthat (>= 3.0.0),
testthat (>= 3.2.0),
tibble
VignetteBuilder:
knitr
Config/Needs/website: sloop
Config/testthat/edition: 3
Config/testthat/parallel: TRUE
Config/testthat/start-first: external-generic
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ export(super)
export(valid_eventually)
export(valid_implicitly)
export(validate)
if (getRversion() < "4.3.0") export(`@`)
if (getRversion() >= "4.3.0" && !is.null(asNamespace("utils")$.AtNames)) S3method(utils::.AtNames,S7_object)
if (getRversion() >= "4.3.0") S3method(base::`@`, S7_object) else export("@")
if (getRversion() >= "4.3.0") S3method(base::`@`, S7_object)
if (getRversion() >= "4.3.0") S3method(chooseOpsMethod, S7_object)
if (getRversion() >= "4.3.0") S3method(matrixOps, S7_object)
if (getRversion() >= "4.3.0") S3method(nameOfClass, S7_class, S7_class_name)
importFrom(stats,setNames)
importFrom(utils,getFromNamespace)
importFrom(utils,globalVariables)
importFrom(utils,hasName)
importFrom(utils,head)
importFrom(utils,packageName)
Expand Down
26 changes: 18 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,44 @@
* `S7_inherits()` now accepts `class = NULL` to test if an object is any
sort of S7 object (#347).

* S7 provides a new automatic backward compatibility mechanism to provide
a version of `@` that works in R before version 4.3 (#326).

* Can create multimethods that dispatch on `NULL`.

# S7 0.1.1

* Classes get a more informative print method (#346).

* Correctly register S3 methods for S7 objects with a package (#333).

* External methods are now registered using an attribute of the S3 methods
table rather than an element of that environment. This prevents a warning
being generated during the "code/documentation mismatches" check in
`R CMD check` (#342).

* `class_missing` and `class_any` can now be unioned with `|` (#337).

* `new_object()` no longer accepts `NULL` as `.parent`.

* `new_object()` now correctly runs the validator from abstract parent classes
(#329).

* `new_object()` works better when custom property setters modify other
properties.

* `new_property()` gains a `validator` argument that allows you to specify
a per-property validator (#275).

* `class_missing` and `class_any` can now be unioned with `|` (#337).

* `new_object()` works better when custom property setters modify other
properties.
* `new_property()` clarifies that it's the user's responsibility to return
the correct class; it is _not_ automatically validated.

* Properties with a custom setter are now validated _after_ the setter has
run and are validated when the object is constructed or when you call
`validate()`, not just when you modify them after construction.

* In `new_property()` clarify that it's the user's responsibility to return
the correct class; it is _not_ automatically validated.

* Correctly register S3 methods for S7 objects with a package (#333).
* `S7_inherits()` now accepts `class = NULL` to test if an object is any
sort of S7 object (#347).

# S7 0.1.0

Expand Down
3 changes: 2 additions & 1 deletion R/S7-package.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## usethis namespace: start
#' @useDynLib S7, .registration = TRUE
#' @importFrom utils globalVariables
#' @importFrom utils head str hasName
#' @useDynLib S7, .registration = TRUE
## usethis namespace: end
NULL
22 changes: 22 additions & 0 deletions R/compatibility.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Where needed, attach an environment containing @ that works with S7
activate_backward_compatiblility <- function() {
if (getRversion() < "4.3.0" && !"S7_at" %in% search()) {
args <- list(list("@" = `@`), name = "S7_at", warn.conflicts = FALSE)
do.call("attach", args)
}
invisible()
}

#' @aliases @
#' @usage NULL
#' @rawNamespace if (getRversion() < "4.3.0") export(`@`)
#' @name prop
`@` <- function(object, name) {
if (inherits(object, "S7_object")) {
name <- as.character(substitute(name))
prop(object, name)
} else {
name <- substitute(name)
do.call(base::`@`, list(object, name))
}
}
14 changes: 2 additions & 12 deletions R/method-ops.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ Ops.S7_super <- Ops.S7_object
chooseOpsMethod.S7_object <- function(x, y, mx, my, cl, reverse) TRUE

#' @rawNamespace if (getRversion() >= "4.3.0") S3method(matrixOps, S7_object)
matrixOps.S7_object <- NULL

on_load_define_matrixOps <- function() {
if (getRversion() >= "4.4.0") {
matrixOps.S7_object <<- function(x, y) {
base_matrix_ops[[.Generic]](x, y)
}
} else {
matrixOps.S7_object <<- function(e1, e2) {
base_matrix_ops[[.Generic]](e1, e2)
}
}
matrixOps.S7_object <- function(x, y) {
base_matrix_ops[[.Generic]](x, y)
}
2 changes: 1 addition & 1 deletion R/method-register.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ as_signature <- function(signature, generic) {
} else {
check_signature_list(signature, n)
for (i in seq_along(signature)) {
signature[[i]] <- as_class(signature[[i]], arg = sprintf("signature[[%i]]", i))
signature[i] <- list(as_class(signature[[i]], arg = sprintf("signature[[%i]]", i)))
}
new_signature(signature)
}
Expand Down
22 changes: 5 additions & 17 deletions R/property.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ prop_obj <- function(object, name) {
if (isTRUE(check)) {
error <- prop_validate(prop, value, object)
if (!is.null(error)) {
stop(error, call. = TRUE)
stop(error, call. = FALSE)
}
}

Expand Down Expand Up @@ -260,28 +260,16 @@ prop_label <- function(object, name) {
sprintf("%s@%s", if (!is.null(object)) obj_desc(object) else "", name)
}

#' @rdname prop
#' @usage object@name
#' @aliases @
#' @rawNamespace if (getRversion() >= "4.3.0") S3method(base::`@`, S7_object) else export("@")
`@.S7_object` <- prop

# Note: we need to explicitly refer to base with "base::`@`" in the
# namespace directive to ensure the method is registered in the correct place.
# Otherwise, loadNamespace()/registerS3method() gets confused by the
# presence of a closure w/ the name of the generic (`@`) in the R7 namespace,
# and incorrectly assumes that R7::`@` is the generic and registers the
# method in the package namespace instead of base::.__S3MethodsTable__.

`@` <- function(object, name) {
if (inherits(object, "S7_object")) {
name <- as.character(substitute(name))
prop(object, name)
} else {
name <- substitute(name)
do.call(base::`@`, list(object, name))
}
}
#' @usage object@name
#' @rawNamespace if (getRversion() >= "4.3.0") S3method(base::`@`, S7_object)
#' @name prop
`@.S7_object` <- prop

#' @rawNamespace S3method("@<-",S7_object)
`@<-.S7_object` <- function(object, name, value) {
Expand Down
3 changes: 2 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ methods::setOldClass(c("S7_method", "function", "S7_object"))
}

.onLoad <- function(...) {
activate_backward_compatiblility()

on_load_make_convert_generic()
on_load_define_matrixOps()
on_load_define_ops()
on_load_define_or_methods()
on_load_define_S7_type()
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ knitr::opts_chunk$set(

<!-- badges: start -->

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![R-CMD-check](https://github.com/RConsortium/OOP-WG/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/RConsortium/OOP-WG/actions/workflows/R-CMD-check.yaml) [![Codecov test coverage](https://codecov.io/gh/RConsortium/OOP-WG/branch/main/graph/badge.svg)](https://app.codecov.io/gh/RConsortium/OOP-WG?branch=main)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![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) [![Codecov test coverage](https://codecov.io/gh/RConsortium/S7/branch/main/graph/badge.svg)](https://app.codecov.io/gh/RConsortium/S7?branch=main)

<!-- badges: end -->

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/RConsortium/OOP-WG/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/RConsortium/OOP-WG/actions/workflows/R-CMD-check.yaml)
[![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)
[![Codecov test
coverage](https://codecov.io/gh/RConsortium/OOP-WG/branch/main/graph/badge.svg)](https://app.codecov.io/gh/RConsortium/OOP-WG?branch=main)
coverage](https://codecov.io/gh/RConsortium/S7/branch/main/graph/badge.svg)](https://app.codecov.io/gh/RConsortium/S7?branch=main)

<!-- badges: end -->

Expand Down
12 changes: 1 addition & 11 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
This is a resubmission.

* There are no references to add to the description.
* I have added the missing `\value{}` documentation.
* I no longer create S4 classes in the global environment in tests.

---

## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
0 errors | 0 warnings | 0 notes
4 changes: 2 additions & 2 deletions man/prop.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions tests/testthat/_snaps/S3.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,39 @@

Code
foo2("a")
Error <simpleError>
<foo2> object is invalid:
Condition
Error:
! <foo2> object is invalid:
- Underlying data must be a double

# new_S3_class() checks its inputs

Code
new_S3_class(1)
Error <simpleError>
`class` must be a character vector
Condition
Error:
! `class` must be a character vector

---

Code
new_S3_class("foo", function(x) { })
Error <simpleError>
First argument to `constructor` must be .data
Condition
Error:
! First argument to `constructor` must be .data
Code
new_S3_class("foo", function(.data, ...) { })
Error <simpleError>
`constructor` can not use `...`
Condition
Error:
! `constructor` can not use `...`

# default new_S3_class constructor errors

Code
class_construct(new_S3_class("foo"), 1)
Error <simpleError>
S3 class <foo> doesn't have a constructor
Condition
Error:
! S3 class <foo> doesn't have a constructor

# catches invalid factors

Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/_snaps/S4.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Code
S4_to_S7_class(1)
Error <simpleError>
Unsupported S4 object: must be a class generator or a class definition, not a <double>.
Condition
Error:
! Unsupported S4 object: must be a class generator or a class definition, not a <double>.

10 changes: 6 additions & 4 deletions tests/testthat/_snaps/class-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

Code
as_class("foo")
Error <simpleError>
Can't convert `"foo"` to a valid class. Class specification must be an S7 class object, the result of `new_S3_class()`, an S4 class object, or a base class, not a <character>.
Condition
Error:
! Can't convert `"foo"` to a valid class. Class specification must be an S7 class object, the result of `new_S3_class()`, an S4 class object, or a base class, not a <character>.
Code
as_class(TRUE)
Error <simpleError>
Can't convert `TRUE` to a valid class. Class specification must be an S7 class object, the result of `new_S3_class()`, an S4 class object, or a base class, not a <logical>.
Condition
Error:
! Can't convert `TRUE` to a valid class. Class specification must be an S7 class object, the result of `new_S3_class()`, an S4 class object, or a base class, not a <logical>.

Loading

0 comments on commit 5678b41

Please sign in to comment.