R Under development (unstable) (2024-01-23 r85822 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > message("TESTING: Class...") TESTING: Class... > > library("R.oo") Loading required package: R.methodsS3 R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help. R.oo v1.26.0 successfully loaded. See ?R.oo for help. Attaching package: 'R.oo' The following object is masked from 'package:R.methodsS3': throw The following objects are masked from 'package:methods': getClasses, getMethods The following objects are masked from 'package:base': attach, detach, load, save > > clazz <- Object > print(clazz) Object public attach(private=FALSE, pos=2, ...) public attachLocally(private=FALSE, fields=NULL, excludeFields=NULL, overwrite=TRUE, envir=parent.frame(), ...) public clearCache(recursive=TRUE, gc=FALSE, ...) public detach(...) public equals(other, ...) public finalize(...) public getFields(private=FALSE, ...) public getInstantiationTime(...) public hasField(field, ...) public hashCode(...) public static load(file, path=NULL, ...) public save(file=NULL, path=NULL, compress=TRUE, ..., safe=TRUE) } > print(as.character(clazz)) [1] "Class Object has 0 fields and 28 methods." > > > message(" - instantiation ...") - instantiation ... > obj <- Object() > print(obj) [1] "Object: 0x0000023f1ccc7060" > obj <- newInstance(clazz) > print(obj) [1] "Object: 0x0000023f1cbc3b90" > stopifnot(inherits(obj, "Object")) > obj <- clazz[["newInstance"]]() > print(obj) [1] "Object: 0x0000023f1c88c3b0" > stopifnot(inherits(obj, "Object")) > message(" - instantiation ... DONE") - instantiation ... DONE > > > message(" - reflection ...") - reflection ... > clazz <- Class$forName("Object") > print(clazz) Object public attach(private=FALSE, pos=2, ...) public attachLocally(private=FALSE, fields=NULL, excludeFields=NULL, overwrite=TRUE, envir=parent.frame(), ...) public clearCache(recursive=TRUE, gc=FALSE, ...) public detach(...) public equals(other, ...) public finalize(...) public getFields(private=FALSE, ...) public getInstantiationTime(...) public hasField(field, ...) public hashCode(...) public static load(file, path=NULL, ...) public save(file=NULL, path=NULL, compress=TRUE, ..., safe=TRUE) } > print(getKnownSubclasses(clazz)) [1] "Class" "Exception" "InternalErrorException" [4] "Package" "RccViolationException" "Rdoc" [7] "RdocException" > static <- getStaticInstance(clazz) > print(static) [1] "Object: 0x0000023f1f0795a8" > pkg <- getPackage(clazz) > print(pkg) [1] "R.oo" > stopifnot(pkg == "R.oo") > > ## Odds and ends > print(isBeingCreated(clazz)) [1] FALSE > > ## FIXME: Case should never occur but code allows for it > print(isBeingCreated.Class(obj)) [1] FALSE > message(" - reflection ... DONE") - reflection ... DONE > > > message(" - modifiers ...") - modifiers ... > print(isAbstract(clazz)) [1] FALSE > print(isPrivate(clazz)) [1] FALSE > print(isProtected(clazz)) [1] FALSE > print(isPublic(clazz)) [1] TRUE > print(isDeprecated(clazz)) [1] FALSE > print(isStatic(clazz)) ## TRUE because of Object$load() [1] TRUE > message(" - modifiers ... DONE") - modifiers ... DONE > > > message(" - inheritance ...") - inheritance ... > setConstructorS3("MyClass", function(...) { + extend(Object(), "MyClass", ...) + }) > > obj <- MyClass(a=1, b=2, c=3) > print(obj) [1] "MyClass: 0x0000023f23576610" > stopifnot(all(c("a", "b", "c") %in% names(obj))) > > obj <- newInstance(MyClass, a=1, b=2, c=3) > print(obj) [1] "MyClass: 0x0000023f23ca88b8" > stopifnot(all(c("a", "b", "c") %in% names(obj))) > > message(" - inheritance ... DONE") - inheritance ... DONE > > > > message("TESTING: Class...DONE") TESTING: Class...DONE > > proc.time() user system elapsed 0.75 0.17 0.90