You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Code
new_class(1)
Condition
Error:
! `name` must be a single string.
Code
new_class("foo", 1)
Condition
Error in `as_class()`:
! Can't convert `parent` to a valid class.
Class specification must be one of the following, not a <double>:
* An S7 class object
* An S3 class object (from `new_S3_class()`)
* An S4 class object
* A base class
Code
new_class("foo", package = 1)
Condition
Error:
! `package` must be a single string.
Code
new_class("foo", constructor = 1)
Condition
Error:
! `constructor` must be a function.
Code
new_class("foo", constructor = function() { })
Condition
Error:
! `constructor` must contain a call to `new_object()`.
Code
new_class("foo", validator = function() { })
Condition
Error:
! `validator` must be function(self), not function().
S7 classes / can't inherit from S4 or class unions
Code
new_class("test", parent = parentS4)
Condition
Error:
! `parent` must be an S7 class, S3 class, or base type, not an S4 class.
Code
new_class("test", parent = new_union("character"))
Condition
Error in `FUN()`:
! Can't convert `X[[i]]` to a valid class.
Class specification must be one of the following, not a <character>:
* An S7 class object
* An S3 class object (from `new_S3_class()`)
* An S4 class object
* A base class
S7 classes / can't inherit from an environment
Code
new_class("test", parent = class_environment)
Condition
Error:
! Can't inherit from an environment.
abstract classes / can't be instantiated
Code
foo := new_class(abstract = TRUE)
foo()
Condition
Error in `S7::new_object()`:
! Can't construct an object from abstract class <foo>.
abstract classes / can't inherit from concrete class
Code
foo1 := new_class()
new_class("foo2", parent = foo1, abstract = TRUE)
Condition
Error in `new_class()`:
! Abstract classes must have abstract parents.
abstract classes / can use inherited validator from abstract class
Code
foo2(x = 2)
Condition
Error:
! <foo2> object is invalid:
- @x has bad value
new_object() / gives useful error if called directly
Code
new_object()
Condition
Error in `new_object()`:
! `new_object()` must be called from within a constructor.
new_object() / errors if .parent doesn't inherit from the parent class (#409)
Code
Foo()
Condition
Error:
! `.parent` must be an instance of <Bar>, not S3<S7_base_class>.
Code
Baz()
Condition
Error:
! `.parent` must be an instance of <integer>, not <character>.
new_object() / errors if .parent is supplied but class has no parent
Code
NoParent()
Condition
Error:
! `.parent` must not be supplied when class has no parent.
new_object() / validates object
Code
foo("x")
Condition
Error:
! <foo> object properties are invalid:
- @x must be <double>, not <character>
Code
foo(-1)
Condition
Error:
! <foo> object is invalid:
- x must be positive
new_object() / runs each parent validator exactly once
Code
. <- A()
Output
A
Code
. <- B()
Output
A B
Code
. <- C()
Output
A B C
Code
text := new_class(class_character, package = NULL)
text("x")
Output
<text> chr "x"
Code
str(list(text("x")))
Output
List of 1
$ : <text> chr "x"
S7 object / displays data.frame subclasses without error (#494)
Code
str(mydf(data.frame(a = 1:2, b = 1:2)))
Output
Classes 'mydf', 'S7_object' and 'data.frame': 2 obs. of 2 variables:
<mydf> 'data.frame': 2 obs. of 2 variables:
$ a: int 1 2
$ b: int 1 2
S7 object / displays list objects nicely
Code
foo1(list(x = 1, y = list(a = 21, b = 22)), x = 3, y = list(a = 41, b = 42))
Output
<foo1> List of 2
$ x: num 1
$ y:List of 2
..$ a: num 21
..$ b: num 22
@ x: num 3
@ y:List of 2
.. $ a: num 41
.. $ b: num 42
c(<S7_class>, ...) gives error
Code
c(foo1, foo1)
Condition
Error in `c.S7_class()`:
! Can not combine S7 class objects.
can't create class with reserved property names
Code
new_class("foo", properties = list(names = class_character))
Condition
Error in `new_class()`:
! Property can't be named: names.
Code
new_class("foo", properties = list(dim = NULL | class_integer))
Condition
Error in `new_class()`:
! Property can't be named: dim.
Code
new_class("foo", properties = list(dim = NULL | class_integer, dimnames = class_list))
Condition
Error in `new_class()`:
! Property can't be named: dim, dimnames.
S7_class() gives informative error if no S7 spec available
Code
S7_class(pairlist(x = 1))
Condition
Error:
! No S7 class for base type <pairlist>.