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: Object...") TESTING: Object... > > 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 > > obj <- Object() > print(obj) [1] "Object: 0x00000289dc866d80" > > obj <- Object(42L) > print(obj) [1] "Object: 0x00000289dc89f140" > stopifnot(obj == 42L) > > obj$a <- 1:99 > print(obj) [1] "Object: 0x00000289dc89f140" > > fields <- getFields(obj) > print(fields) [1] "a" > > hasA <- hasField(obj, "a") > print(hasA) [1] TRUE > stopifnot(hasA) > > value <- obj$a > str(value) int [1:99] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(value, 1:99)) > > obj$a <- 1:100 > print(obj) [1] "Object: 0x00000289dc89f140" > > value <- obj[["a"]] > str(value) int [1:100] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(value, 1:100)) > > obj[["a"]] <- 1:101 > print(obj) [1] "Object: 0x00000289dc89f140" > > value <- obj[["a"]] > str(value) int [1:101] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(value, 1:101)) > > size <- objectSize(obj) > print(size) 760 bytes > > ref <- isReferable(obj) > print(ref) [1] TRUE > stopifnot(isTRUE(ref)) > > time <- getInstantiationTime(obj) > print(time) NULL > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Attach and detach > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - > res <- attach(obj) > print(res) [1] TRUE > stopifnot(exists("a", mode="integer")) > str(a) int [1:101] 1 2 3 4 5 6 7 8 9 10 ... > > ## Object already attached > res <- tryCatch(attach(obj), warning=function(w) w) > stopifnot(inherits(res, "warning")) > > res <- detach(obj) > print(res) [1] TRUE > > ## Object already detached > res <- tryCatch(detach(obj), warning=function(w) w) > stopifnot(inherits(res, "warning")) > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Save and load > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - > obj <- Object() > obj$a <- 1 > obj$b <- 2 > pathnameT <- tempfile() > save(obj, file=pathnameT) > > obj2 <- Object$load(pathnameT) > stopifnot(all.equal(getFields(obj2), getFields(obj))) > for (key in getFields(obj)) { + stopifnot(identical(obj2[[key]], obj[[key]])) + } > > file.remove(pathnameT) [1] TRUE > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Class > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - > obj2 <- newInstance(obj, 43L) > print(obj2) [1] "Object: 0x00000289db72f450" > stopifnot(obj2 == 43L) > > > hash <- hashCode(obj) > print(hash) [1] 2.791095e+12 > stopifnot(length(hash) == 1L) > > neq <- equals(obj, 1) > print(neq) [1] FALSE > stopifnot(!neq) > > eq <- equals(obj, obj) > print(eq) [1] TRUE > stopifnot(eq) > > obj3 <- clone(obj) > print(obj3) [1] "Object: 0x00000289db7a9370" > stopifnot(!identical(obj3, obj)) > stopifnot(all.equal(obj3, obj)) > > > message("TESTING: Object...DONE") TESTING: Object...DONE > > proc.time() user system elapsed 0.25 0.18 0.36