Changelog
Source:NEWS.md
S7 (development version)
- Errors thrown by S7 now report the function where they occurred, making it easier to track down the source of a problem (#646).
-
class_POSIXctuses thetzoneattribute (nottz), and allows it to be absent (#401). - Base type wrappers like
class_integernow define their constructor and validator in the S7 namespace. (#553). - Method dispatch on
class_missingnow correctly handles missing arguments forwarded through a wrapper functions (#595). -
convert()no longer automatically converts between sibling classes (classes that merely share a common ancestor); the default downcast now applies only whentois genuinely a descendant offrom’s class (#509). -
convert()now falls back to the correspondingas.*()function (e.g.as.character()) when converting to a base type likeclass_characterand no method or inheritance-based default applies, soconvert(1, class_character)works out of the box (#472). -
convert()no longer errors whenfromis a base or S3 object andtois an S7 class that inherits fromfrom’s class. The base/S3 value is now passed as.datato thetoconstructor (#537). -
method<-now acceptsNULLto unregister an existing method, e.g.method(foo, class_character) <- NULL(#613). -
convert()is now idempotent whenfromis already an instance ofto, returning it unchanged. Whenfrominherits fromtobut is more specific, dispatch is now restricted to classes more specific thanto, so an inherited downcasting method can no longer be selected in place of an upcast (#429). -
method<-now gives a clear error when assigning a primitive function (e.g.log) as a method (#608). -
method<-andmethod()now accept a length-1 list assignaturefor single-dispatch generics, matching the list-of-classes form required for multi-dispatch (#555). -
method<-can now register methods on S3 and S4 generics with base types (e.g.class_character), S3 classes (new_S3_class(),class_factor, etc.), S7 unions (expanded to one registration per class),class_any(registered as thedefaultmethod), andNULL(registered as theNULLmethod) (#455). -
new_class()experimentally allowsclass_environmentas a parent again, so you can build S7 objects that share R’s reference semantics for environments. This support is provisional: because environments are mutated in place, some operations behave differently than for value-typed S7 objects, and the API may change.S7_data()andS7_data<-()error on environment-based objects, since they would otherwise destroy the object’s S7 attributes in place (#590). -
new_object()now gives an informative error when.parentis a class specification rather than an instance of the parent class (#409). -
new_object()no longer materialises ALTREP parent values (e.g.seq_len()), so constructing an S7 object that wraps a large compact integer sequence is now O(1) in memory instead of O(n) (@kschaubroeck, #607). -
new_object()no longer re-runs property validators for properties inherited unchanged from an already-validated parent class, so constructing an instance of a deeply nested class hierarchy validates each property exactly once (#539). -
new_property()now runs the property class’s own validator when checking a value, not just the structural class check, so a property restricted to an S3 class (e.g.class_factor) now enforces constraints that aren’t visible inclass()(#401). -
new_property()now accepts asetterthat takesself,name, andvaluemaking it easy to reuse the same definition for multiple properties (#552). -
new_S3_class()objects now work withinherits()(and other functions that usenameOfClass()) in R 4.3 and later (@lawremi, #521). -
print(<S7_class>)now shows property defaults inline (= "value") and annotates read-only properties ([read-only]) (#439). -
prop()andprop<-()errors from getters and setters (including custom) now report a synthetic<Class>@<prop>call, making it easier to see which property triggered the error (#416, #536, #638). -
prop()no longer leaves an object in a broken state when a custom getter signals an error (#520, #640, #638). -
prop<-()no longer fails when assigning a call or symbol to a property (#511, #633, #638). - New
prop_info()returns a data frame summarising the properties of an S7 object or class, with one row per property and columns for name, default, class, getter, setter, and validator (#551). -
S7_class()now returns a class specification for any R object, not just S7 objects. It returns the matchingclass_*for base types, anew_S3_class()wrapper for S3 objects, and the S4 class for S4 objects, so the result can be passed directly tomethod()or other S7 dispatch helpers (#559). -
S7_class_desc()is a new exported helper that formats a class specification as a short human-readable string (#594). -
S7_data()now preserves the S3 class when the S7 class inherits from an S3 class, so e.g.S7_data()on a data.frame subclass now returns a data.frame (#380). -
S7_data<-()now preserves attributes (likenamesordim) from the replacement data instead of carrying over the originals, so resizing the underlying data works correctly (#478). -
S7_error_method_not_foundnow has a correct class vector without a duplicate"error"entry (@jjjermiah, #604). -
S7_inherits()andcheck_is_S7()now accept any class specification (S7 class, S7 union, S3 class, S4 class, or base type wrapper likeclass_integer), not just S7 classes (#556). -
str()on S7 objects that inherit from data.frame (or other S3 classes whose underlying data has adimattribute incompatible with the bare base type) no longer errors (#494). -
super()now works with S3 and S4 objects, not just S7 objects (#500). -
validate()now signals validation errors with classS7_error_validation_failed, so they can be caught withtryCatch()(#602, #605).
S7 0.2.1
CRAN release: 2025-11-14
props<-()andset_props()gaincheck/.checkarguments, letting you set properties without callingvalidate()(#574, #575).Internal changes to support R-devel (4.6) (#577).
S7 0.2.0
CRAN release: 2024-11-07
New features
The default object constructor returned by
new_class()has been updated. It now accepts lazy (promise) property defaults and includes dynamic properties with asetterin the constructor. Additionally, all custom property setters are now consistently invoked by the default constructor. If you’re using S7 in an R package, you’ll need to re-document to ensure that your documentation matches the updated usage (#438, #445).The call context of a dispatched method (as visible in
sys.calls()andtraceback()) no longer includes the inlined method and generic, resulting in more compact and readable tracebacks. The dispatched method call now contains only the method name, which serves as a hint for retrieving the method. For example:method(my_generic, class_double)(x=10, …). (#486)New
nameOfClass()method exported for S7 base classes, to enable usage likeinherits("foo", S7::class_character)(#432, #458)Added support for more base/S3 classes (#434):
class_POSIXlt,class_POSIXt,class_formula,class_call,class_language, andclass_name.S7 provides a new automatic backward compatibility mechanism to provide a version of
@that works in R before version 4.3 (#326).
Bug fixes and minor improvements
new_class()now automatically infers the package name when called from within an R package (#459).Improved error message when custom validators return invalid values (#454, #457).
Fixed S3 methods registration across packages (#422).
convert()now provides a default method to transform a parent class instance into a subclass, enabling class construction from a prototype (#444).A custom property
getter()no longer infinitely recurses when accessing itself (reported in #403, fixed in #406).method()generates an informative message with classS7_error_method_not_foundwhen dispatch fails (#387).method<-()can create multimethods that dispatch onNULL.In
new_class(), properties can either be named by naming the element of the list or by supplying thenameargument tonew_property()(#371).The
Opsgeneric now falls back to base Ops behaviour when one of the arguments is not an S7 object (#320). This means that you get the somewhat inconsistent base behaviour, but means that S7 doesn’t introduce a new axis of inconsistency.prop()(#395) andprop<-/@<-(#396) have been optimized and rewritten in C.validate()is now always called after a custom property setter was invoked (reported in #393, fixed in #396).
S7 0.1.1
CRAN release: 2023-09-17
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_missingandclass_anycan now be unioned with|(#337).new_object()no longer acceptsNULLas.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 avalidatorargument that allows you to specify a per-property validator (#275).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.S7_inherits()now acceptsclass = NULLto test if an object is any sort of S7 object (#347).
S7 0.1.0
CRAN release: 2023-08-24
May-July 2023
new_external_generic()is only needed when you want a soft dependency on another package.methods_register()now also registers S3 and S4 methods (#306).
Jan-May 2023
Subclasses of abstract class can have readonly properties (#269).
During construction, validation is now only performed once for each element of the class hierarchy (#248).
Implemented a better filtering strategy for the S4 class hierarchy so you can now correctly dispatch on virtual classes (#252).
New
set_props()to make a modified copy of an object (#229).R CMD checknow passes on R 3.5 and greater (for tidyverse compatibility).Dispatching on an evaluated argument no longer causes a crash (#254).
Improve method dispatch failure message (#231).
Can use
|to create unions from S7 classes (#224).Can no longer subclass an environment via
class_environmentbecause we need to think the consequences of this behaviour through more fully (#253).
Rest of 2022
Add
[.S7_object,[<-.S7_object,[[.S7_object, and[[<-.S7_objectmethods to avoid “object of type ‘S4’ is not subsettable” error (@jamieRowen, #236).Base classes now show as
class_xinstead of"x"in method print (#232)
Mar 2022
Exported
class_factor,class_Date,class_POSIXct, andclass_data.frame.New
S7_inherits()andcheck_is_S7()(#193)new_class()can create abstract classes (#199).method_call()is nowS7_dispatch()(#200).Can now register methods for double-dispatch base Ops (currently only works if both classes are S7, or the first argument is S7 and the second doesn’t have a method for the Ops generic) (#128).
All built-in wrappers around base types use
class_. You can no longer refer to a base type with a string or a constructor function (#170).convert()allows you to convert an object into another class (#136).
Feb 2022
class_anyandclass_missingmake it possible to dispatch on absent arguments and arguments of any class (#67).New
method_explain()to explain dispatch (#194).Minor property improvements: use same syntax for naming short-hand and full property specifications; input type automatically validated for custom setters. A property with a getter but no setter is read-only (#168).
When creating an object, unspecified properties are initialized with their default value (#67). DISCUSS: to achieve this, the constructor arguments default to
class_missing.Add
$.S7_objectand$<-.S7_objectmethods to avoid “object of type ‘S4’ is not subsettable” error (#204).Dispatch now disambiguates between S4 and S3/S7, and, optionally, between S7 classes in different packages (#48, #163).
new_generic()now requiresdispatch_args(#180). This means thatnew_generic()will typically be called without names. Eithernew_generic("foo", "x")for a “standard” generic, ornew_generic("foo", "x", function(x, y) call_method())for a non-standard method.new_external_generic()now requiresdispatch_argsso we can eagerly check the signature.Revamp website. README now shows brief example and more info in
vignette("S7"). Initial design docs and minutes are now articles so they appear on the website.
Jan 2022
- New
props<-for setting multiple properties simultaneously and validating afterwards (#149). - Validation now happens recursively, and validates types before validating the object (#149)
- Classes (base types, S3, S4, and S7) are handled consistently wherever they are used. Strings now only refer to base types. New explicit
new_S3_class()for referring to S3 classes (#134). S4 unions are converted to S7 unions (#150). - Base numeric, atomic, and vector “types” are now represented as class unions (#147).
- Different evaluation mechanism for method dispatch, and greater restrictions on dispatch args (#141)
-
x@.data->S7_data(); probably to be replaced by casting. - In generic,
signature->dispatch_args. - Polished
str()andprint()methods -
new_class()has properties as 3rd argument (instead of constructor).