Skip to content

Commit

Permalink
Merged origin/main into prop-name
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Nov 23, 2023
2 parents 11fa185 + d4be7f8 commit 96fb0f6
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 24 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ 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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ 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
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
20 changes: 10 additions & 10 deletions R/method-ops.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ Ops.S7_object <- function(e1, e2) {
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
matrixOps.S7_object <- function(x, y) {
base_matrix_ops[[.Generic]](x, y)
}


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)
}
}
# if (getRversion() >= "4.3.0") {
# } else {
# matrixOps.S7_object <<- function(e1, e2) {
# base_matrix_ops[[.Generic]](e1, e2)
# }
# }
}
3 changes: 1 addition & 2 deletions tests/testthat/test-base-r.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ test_that("base::`@` accesses S7 properties", {
})

test_that("dput(<S7_object>) works", {
skip_if(getRversion() < "4.3")
skip("dput() not fixed yet; https://github.com/RConsortium/S7/issues/272")
skip_if(getRversion() < "4.4")

expect_no_error(dput(new_class("Foo")()))
expect_no_error(dput(new_class("Foo")))
Expand Down
1 change: 0 additions & 1 deletion vignettes/classes-objects.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,3 @@ The first argument to `new_object()` should be an object of the `parent` class (
That argument should be followed by one named argument for each property.

There's one drawback of custom constructors that you should be aware of: any subclass will also require a custom constructor.

2 changes: 1 addition & 1 deletion vignettes/generics-methods.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Generics and methods"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{S7 generics and method dispatch}
%\VignetteIndexEntry{Generics and methods}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down
10 changes: 2 additions & 8 deletions vignettes/motivation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ library(S7)
This made it possible to make radical changes but it made it harder to switch from S3 to S4, leading to a general lack of adoption in the R community.
S7 is designed to be drop-in compatible with S3, making it possible to convert existing packages to use S7 instead of S3 with only an hour or two of work.

```{=html}
<!-- -->
```
- At least within Bioconductor, slots are generally thought of as implementation detail that should not be directly accessed by the end-user.
This leads to two problems.
Firstly, implementing an S4 Bioconductor class often also requires a plethora of accessor functions that are a thin wrapper around `@` or `@<-`.
Secondly, users know about `@` and use it to access object internals even though they're not supposed to.
S7 avoids these problems by accepting the fact that R is a data language, and that there's no way to stop users from pulling the data they need out of an object.
To make it possible to change the internal implementation details of an object while preserving existing `@` usage, S7 provides dynamic properties.

- At least within Bioconductor, slots are generally thought of as implementation detail that should not be directly accessed by the end-user. This leads to two problems. Firstly, implementing an S4 Bioconductor class often also requires a plethora of accessor functions that are a thin wrapper around `@` or `@<-`. Secondly, users know about `@` and use it to access object internals even though they're not supposed to. S7 avoids these problems by accepting the fact that R is a data language, and that there's no way to stop users from pulling the data they need out of an object. To make it possible to change the internal implementation details of an object while preserving existing `@` usage, S7 provides dynamic properties.
2 changes: 1 addition & 1 deletion vignettes/packages.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Using S7 in a package"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{packages}
%\VignetteIndexEntry{Using S7 in a package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down

0 comments on commit 96fb0f6

Please sign in to comment.