Skip to content

Commit c88c241

Browse files
committed
update for rename of @S7_class to @_S7_class
1 parent abf31be commit c88c241

7 files changed

Lines changed: 26 additions & 20 deletions

File tree

R/S4.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#' `S4_register()` registers an S7 class, S3 class, or S7 union with S4 and
1010
#' invisibly returns the registered S4 class name.
1111
#' For S7 classes, this creates a virtual S4 old class that exposes stored S7
12-
#' properties as S4 slots and carries the `S7_class` slot needed for S7 dispatch
12+
#' properties as S4 slots and carries the `_S7_class` slot needed for S7 dispatch
1313
#' and validation.
1414
#'
1515
#' After registration, `S4_contains()` returns the virtual S4 class name to use
@@ -270,7 +270,7 @@ S4_properties_prototype <- function(
270270
}
271271
}
272272
if (include_S7_class) {
273-
args$S7_class <- class
273+
args$`_S7_class` <- class
274274
}
275275
do.call(methods::prototype, args)
276276
}
@@ -320,9 +320,9 @@ S4_register_class <- function(class, env = parent.frame()) {
320320
properties <- class@properties
321321
properties <- properties[setdiff(names(properties), parent_slot_names)]
322322
slots <- lapply(properties, S4_property_class, S4_env = where)
323-
needs_S7_class_slot <- !"S7_class" %in% parent_slot_names
323+
needs_S7_class_slot <- !"_S7_class" %in% parent_slot_names
324324
if (needs_S7_class_slot) {
325-
slots$S7_class <- "S7_class"
325+
slots$`_S7_class` <- "S7_class"
326326
}
327327

328328
methods::setClass(

R/convert.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ convert_up <- function(from, to, call = sys.call(-1L)) {
187187
stop2(msg, call = call)
188188
}
189189

190-
from <- zap_attr(from, c(setdiff(from_props, to_props), "S7_class"))
190+
from <- zap_attr(
191+
from,
192+
c(setdiff(from_props, to_props), "_S7_class", "S7_class")
193+
)
191194
attr(from, "_S7_class") <- to
192195
class(from) <- class_dispatch(to)
193196
} else if (is_S4_coerce(from, to)) {

R/inherits.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ S7_inherits <- function(x, class = NULL) {
4949
has_S7_class <- function(x) {
5050
identical(class(x), "S7_object") ||
5151
inherits(x, "S7_class") ||
52-
!is.null(attr(x, "S7_class", exact = TRUE))
52+
!is.null(.Call(S7_class_, x))
5353
}
5454

5555
#' @export

R/property.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ prop_call <- function(object, name) {
365365

366366
#' @rawNamespace S3method("@<-",S7_object)
367367
`@<-.S7_object` <- function(object, name, value) {
368-
if (isS4(object) && !name %in% names(slot(object, "S7_class")@properties)) {
368+
if (isS4(object) && !name %in% names(S7_class(object)@properties)) {
369369
methods::slot(object, name) <- value
370370
return(object)
371371
}

man/S4_register.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-S4.R

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test_that("S4_register registers S4 old classes as virtual S7_object descendants
4343
"trying to generate an object from a virtual class"
4444
)
4545
expect_true(methods::extends("S4regS7New", "S7_object"))
46-
expect_true("S7_class" %in% methods::slotNames("S4regS7New"))
46+
expect_true("_S7_class" %in% methods::slotNames("S4regS7New"))
4747
})
4848

4949
test_that("S4_register registers an S3 class so it can be used with S4 methods", {
@@ -116,7 +116,7 @@ test_that("S4_register can reify S7 properties as slots for S4 subclasses", {
116116
expect_equal(S4regContainsChild_S4, "S7::S4regContainsChild")
117117
expect_equal(
118118
methods::slotNames(S4regContainsChild_S4),
119-
c("y", "x", "S7_class", ".S3Class")
119+
c("y", "x", "_S7_class", ".S3Class")
120120
)
121121
expect_contains(
122122
methods::extends(S4regContainsChild_S4),
@@ -138,7 +138,7 @@ test_that("S4_register can reify S7 properties as slots for S4 subclasses", {
138138
expect_equal(methods::slot(object, "x"), 1)
139139
expect_equal(methods::slot(object, "y"), "a")
140140
expect_equal(methods::slot(object, "z"), TRUE)
141-
expect_equal(methods::slot(object, "S7_class"), S4regContainsChild)
141+
expect_equal(methods::slot(object, "_S7_class"), S4regContainsChild)
142142
expect_equal(prop_names(object), c("x", "y"))
143143
expect_equal(prop(object, "x"), 1)
144144
expect_equal(prop(object, "y"), "a")
@@ -224,11 +224,11 @@ test_that("S4_register constructs S4 subclasses of S7 classes that extend S4 cla
224224
S4regNewChild_S4 <- S4_contains(S4regNewChild)
225225
expect_equal(
226226
methods::slotNames("S4regNewChild"),
227-
c("status", "metadata", "S7_class", "assays", "rowData", ".S3Class")
227+
c("status", "metadata", "_S7_class", "assays", "rowData", ".S3Class")
228228
)
229229
expect_contains(
230230
methods::slotNames(S4regNewChild_S4),
231-
c("assays", "rowData", "metadata", "status", "S7_class")
231+
c("assays", "rowData", "metadata", "status", "_S7_class")
232232
)
233233
setClass(
234234
"S4regNewGrandChild",
@@ -242,7 +242,7 @@ test_that("S4_register constructs S4 subclasses of S7 classes that extend S4 cla
242242
expect_true(methods::is(object, "S4regNewParent"))
243243
expect_true(methods::is(object, S4regNewChild_S4))
244244
expect_true(S7_inherits(object, S4regNewChild))
245-
expect_equal(methods::slot(object, "S7_class"), S4regNewChild)
245+
expect_equal(methods::slot(object, "_S7_class"), S4regNewChild)
246246
expect_equal(methods::slot(object, "assays"), list())
247247
expect_equal(methods::slot(object, "rowData"), character())
248248
expect_equal(methods::slot(object, "metadata"), character())
@@ -364,12 +364,12 @@ test_that("S4_register registers abstract S7 classes as virtual S4 classes", {
364364
concrete_prototype <- methods::getClass("S4regAbstractConcrete")@prototype
365365

366366
expect_true(methods::isVirtualClass("S4regAbstract"))
367-
expect_true("S7_class" %in% methods::slotNames("S4regAbstract"))
368-
expect_equal(methods::slot(abstract_prototype, "S7_class"), S4regAbstract)
367+
expect_true("_S7_class" %in% methods::slotNames("S4regAbstract"))
368+
expect_equal(methods::slot(abstract_prototype, "_S7_class"), S4regAbstract)
369369
expect_false(methods::extends("S4regAbstract", "oldClass"))
370370
expect_false(methods::extends("S4regAbstract", "S7_object"))
371371
expect_equal(
372-
methods::slot(concrete_prototype, "S7_class"),
372+
methods::slot(concrete_prototype, "_S7_class"),
373373
S4regAbstractConcrete
374374
)
375375
expect_false("S4regAbstract" %in% attr(concrete_prototype, ".S3Class"))
@@ -672,7 +672,10 @@ test_that("S7 classes can extend S4 classes", {
672672
expect_true(methods::is(child, "Parent"))
673673
expect_true(methods::validObject(child))
674674
expect_equal(as.character(methods::getClass("Child")@className), "Child")
675-
expect_equal(methods::slotNames("Child"), c("y", "S7_class", "x", ".S3Class"))
675+
expect_equal(
676+
methods::slotNames("Child"),
677+
c("y", "_S7_class", "x", ".S3Class")
678+
)
676679
expect_equal(methods::slot(child, "x"), 2)
677680
expect_equal(methods::slot(child, "y"), "b")
678681

vignettes/compatibility.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ library(S7)
2626
S7 objects *are* S3 objects, because S7 is implemented on top of S3.
2727
There are two main differences between an S7 object and an S3 object:
2828

29-
- As well as the `class` attribute possessed by S3 objects, S7 objects have an additional `S7_class` attribute that contains the object that defines the class.
29+
- As well as the `class` attribute possessed by S3 objects, S7 objects have an additional `_S7_class` attribute that contains the object that defines the class.
3030

3131
- S7 objects have properties; S3 objects have attributes.
3232
Properties are implemented on top of attributes, so you can access them directly with `attr` and friends.
@@ -219,7 +219,7 @@ There are a few important caveats:
219219
After calling `S4_register()`, use `S4_contains()` when an S4 class should
220220
extend an S7 class. It returns the virtual S4 class name for
221221
`methods::setClass(contains = )`. This class exposes stored S7 properties as
222-
formal S4 slots and carries the `S7_class` slot that S7 uses for dispatch and
222+
formal S4 slots and carries the `_S7_class` slot that S7 uses for dispatch and
223223
validation.
224224

225225
```{r}

0 commit comments

Comments
 (0)