# ---- Basic usage --------------------------------------------
Range <- new_bids_class(
"Range",
properties = list(
start = bids_property_numeric("start", "required"),
end = bids_property_numeric("end", "optional")
),
validator = function(self) {
if(length(self@end) && self@end < self@start) {
"@end must be great than or equal to @start"
}
}
)
r <- Range(start = 10)
r
# get and set properties with @ or $
r$start
r$end <- 40
r$end
try(Range(start = c(10, 15), end = 20))
try(Range(start = 15, end = 10))
# ---- hide properties and attributes -------------------------
MyClass <- new_bids_class(
name = "MyClass",
properties = list(
str = bids_property_character(
name = "str", type = "required"),
hidden_prop = bids_property_character("hidden_prop")
),
methods = list(
# read-only methods
format = function(self, ...) {
sprintf("MyClass@str -> %s", self$str)
},
hidden_method = function(self) {
"Nonononono"
}
),
hidden_names = c("hidden_method", "hidden_prop")
)
x <- MyClass(str = "a")
x
# hidden names will not be displayed
names(x)
as.list(x)
# however, then can still be queried
x$hidden_prop
x$hidden_method()
Run the code above in your browser using DataLab