I have a reference class, one of the fields for which is a 'units' object from the R units package. My initial class definition looked like this:
MyClass =
setRefClass(
"MyClass",
fields = list(units_value = "numeric")
)
uv = units::as_units(10, 'cm')
mc = MyClass(units_value = uv)
Which threw the following error:
Error: invalid assignment for reference class field ‘units_value’, should be from class “numeric” or a subclass (was class “units”)
So I tried to set the field class to units
like so:
MyClass =
setRefClass(
"MyClass",
fields = list(units_value = "units")
)
uv = units::as_units(10, 'cm')
mc = MyClass(units_value = uv)
But this throws a whole new error:
Error in refClassInformation(Class, contains, fields, methods, where) :
class “units” for field ‘units_value’ is not defined
For the moment I've settled for using a non-typed class constructor, but this seems like such a simple problem that it's hard for me to believe there's no way to construct a Reference Class with a units object as a field. Does anyone know how to accomplish this?