@@ -15,13 +15,22 @@ S7_object <- new_class(
15
15
.Call(S7_object_ )
16
16
},
17
17
validator = function (self ) {
18
- if (typeof (self ) != .S7_type ) {
18
+ if (! is_S7_type (self )) {
19
19
" Underlying data is corrupt"
20
20
}
21
21
}
22
22
)
23
23
methods :: setOldClass(" S7_object" )
24
24
25
+ .S7_type <- NULL
26
+ # Defined onLoad because it depends on R version
27
+ on_load_define_S7_type <- function () {
28
+ .S7_type <<- typeof(.Call(S7_object_ ))
29
+ }
30
+ is_S7_type <- function (x ) {
31
+ typeof(x ) == .S7_type
32
+ }
33
+
25
34
# ' @export
26
35
`$.S7_object` <- function (x , name ) {
27
36
if (typeof(x ) %in% c(" list" , " environment" )) {
@@ -100,6 +109,8 @@ S7_method <- new_class("S7_method",
100
109
)
101
110
methods :: setOldClass(c(" S7_method" , " function" , " S7_object" ))
102
111
112
+ # hooks -------------------------------------------------------------------
113
+
103
114
.onAttach <- function (libname , pkgname ) {
104
115
env <- as.environment(paste0(" package:" , pkgname ))
105
116
if (getRversion() < " 4.3.0" ) {
@@ -108,26 +119,10 @@ methods::setOldClass(c("S7_method", "function", "S7_object"))
108
119
}
109
120
110
121
.onLoad <- function (... ) {
111
- on_load_define_ops ()
122
+ on_load_make_convert_generic ()
112
123
on_load_define_matrixOps()
113
-
114
- # # "S4" or [in R-devel 2023-07-x] "object"
115
- assign(" .S7_type" , typeof(.Call(S7_object_ )), topenv())
116
-
117
- convert <<- S7_generic(convert , name = " convert" , dispatch_args = c(" from" , " to" ))
118
-
119
- class_numeric <<- new_union(class_integer , class_double )
120
- class_atomic <<- new_union(class_logical , class_numeric , class_complex , class_character , class_raw )
121
- class_vector <<- new_union(class_atomic , class_expression , class_list )
122
-
123
- # Dynamic register so that function pointers are the same, avoiding R 4.0
124
- # and earlier bug related to incompatible S3 methods during Ops dispatch
125
- registerS3method(" |" , " S7_union" , `|.S7_class` )
126
- registerS3method(" |" , " S7_base_class" , `|.S7_class` )
127
- registerS3method(" |" , " S7_S3_class" , `|.S7_class` )
128
- registerS3method(" |" , " S7_any" , `|.S7_class` )
129
- registerS3method(" |" , " S7_missing" , `|.S7_class` )
130
- registerS3method(" |" , " classGeneratorFunction" , `|.S7_class` )
131
- registerS3method(" |" , " ClassUnionRepresentation" , `|.S7_class` )
132
- registerS3method(" |" , " classRepresentation" , `|.S7_class` )
124
+ on_load_define_ops()
125
+ on_load_define_or_methods()
126
+ on_load_define_S7_type()
127
+ on_load_define_union_classes()
133
128
}
0 commit comments