| Line 1... |
Line 1... |
| 1 |
|
1 |
|
| 2 |
R Under development (unstable) (2013-07-06 r63201) -- "Unsuffered Consequences"
|
2 |
R Under development (unstable) (2013-07-06 r63204) -- "Unsuffered Consequences"
|
| 3 |
Copyright (C) 2013 The R Foundation for Statistical Computing
|
3 |
Copyright (C) 2013 The R Foundation for Statistical Computing
|
| 4 |
Platform: x86_64-unknown-linux-gnu (64-bit)
|
4 |
Platform: x86_64-apple-darwin12.4.0/x86_64 (64-bit)
|
| 5 |
|
5 |
|
| 6 |
R is free software and comes with ABSOLUTELY NO WARRANTY.
|
6 |
R is free software and comes with ABSOLUTELY NO WARRANTY.
|
| 7 |
You are welcome to redistribute it under certain conditions.
|
7 |
You are welcome to redistribute it under certain conditions.
|
| 8 |
Type 'license()' or 'licence()' for distribution details.
|
8 |
Type 'license()' or 'licence()' for distribution details.
|
| 9 |
|
9 |
|
| Line 16... |
Line 16... |
| 16 |
Type 'q()' to quit R.
|
16 |
Type 'q()' to quit R.
|
| 17 |
|
17 |
|
| 18 |
> ####--- S4 Methods (and Classes) --- see also ../src/library/methods/tests/
|
18 |
> ####--- S4 Methods (and Classes) --- see also ../src/library/methods/tests/
|
| 19 |
> options(useFancyQuotes=FALSE)
|
19 |
> options(useFancyQuotes=FALSE)
|
| 20 |
> require(methods)
|
20 |
> require(methods)
|
| 21 |
> assertCondition <- tools::assertCondition # "import"
|
21 |
> assertError <- tools::assertError # "import"
|
| 22 |
> ##too fragile: showMethods(where = "package:methods")
|
22 |
> ##too fragile: showMethods(where = "package:methods")
|
| 23 |
>
|
23 |
>
|
| 24 |
> ##-- S4 classes with S3 slots [moved from ./reg-tests-1.R]
|
24 |
> ##-- S4 classes with S3 slots [moved from ./reg-tests-1.R]
|
| 25 |
> setClass("test1", representation(date="POSIXct"))
|
25 |
> setClass("test1", representation(date="POSIXct"))
|
| 26 |
> x <- new("test1", date=as.POSIXct("2003-10-09"))
|
26 |
> x <- new("test1", date=as.POSIXct("2003-10-09"))
|
| Line 268... |
Line 268... |
| 268 |
> setMethod("Logic", signature("brob", "ANY"), logic2)
|
268 |
> setMethod("Logic", signature("brob", "ANY"), logic2)
|
| 269 |
[1] "Logic"
|
269 |
[1] "Logic"
|
| 270 |
> setMethod("Logic", signature("ANY", "brob"), logic2)
|
270 |
> setMethod("Logic", signature("ANY", "brob"), logic2)
|
| 271 |
[1] "Logic"
|
271 |
[1] "Logic"
|
| 272 |
> ## Now ensure that using group members gives error:
|
272 |
> ## Now ensure that using group members gives error:
|
| 273 |
> assertCondition(b & b, "error")
|
273 |
> assertError(b & b)
|
| 274 |
Note: method with signature 'brob#ANY' chosen for function '&',
|
274 |
Note: method with signature 'brob#ANY' chosen for function '&',
|
| 275 |
target signature 'brob#brob'.
|
275 |
target signature 'brob#brob'.
|
| 276 |
"ANY#brob" would also be valid
|
276 |
"ANY#brob" would also be valid
|
| 277 |
> assertCondition(b | 1, "error")
|
277 |
> assertError(b | 1)
|
| 278 |
> assertCondition(TRUE & b, "error")
|
278 |
> assertError(TRUE & b)
|
| 279 |
>
|
279 |
>
|
| 280 |
>
|
280 |
>
|
| 281 |
> ## methods' hidden cbind() / rbind:
|
281 |
> ## methods' hidden cbind() / rbind:
|
| 282 |
> cBind <- methods:::cbind
|
282 |
> cBind <- methods:::cbind
|
| 283 |
> setClass("myMat", representation(x = "numeric"))
|
283 |
> setClass("myMat", representation(x = "numeric"))
|
| Line 635... |
Line 635... |
| 635 |
>
|
635 |
>
|
| 636 |
> ## Method with wrong argument order :
|
636 |
> ## Method with wrong argument order :
|
| 637 |
> setGeneric("test1", function(x, printit = TRUE, name = "tmp")
|
637 |
> setGeneric("test1", function(x, printit = TRUE, name = "tmp")
|
| 638 |
+ standardGeneric("test1"))
|
638 |
+ standardGeneric("test1"))
|
| 639 |
[1] "test1"
|
639 |
[1] "test1"
|
| 640 |
> assertCondition(
|
640 |
> tools::assertCondition(
|
| 641 |
+ setMethod("test1", "numeric", function(x, name, printit) match.call()),
|
641 |
+ setMethod("test1", "numeric", function(x, name, printit) match.call()),
|
| 642 |
+ "warning", "error")## did not warn or error in R 2.7.0 and earlier
|
642 |
+ "warning", "error")## did not warn or error in R 2.7.0 and earlier
|
| 643 |
>
|
643 |
>
|
| 644 |
> library(stats4)
|
644 |
> library(stats4)
|
| 645 |
> c1 <- getClass("mle", where = "stats4")
|
645 |
> c1 <- getClass("mle", where = "stats4")
|
| Line 716... |
Line 716... |
| 716 |
> ## the 3rd did not have "methods"
|
716 |
> ## the 3rd did not have "methods"
|
| 717 |
>
|
717 |
>
|
| 718 |
> ## Invalid "factor"s -- now "caught" by validity check :
|
718 |
> ## Invalid "factor"s -- now "caught" by validity check :
|
| 719 |
> ok.f <- gl(3,5, labels = letters[1:3])
|
719 |
> ok.f <- gl(3,5, labels = letters[1:3])
|
| 720 |
> bad.f <- structure(rep(1:3, each=5), levels=c("a","a","b"), class="factor")
|
720 |
> bad.f <- structure(rep(1:3, each=5), levels=c("a","a","b"), class="factor")
|
| 721 |
> validObject(ok.f) ; assertCondition(validObject(bad.f), "error")
|
721 |
> validObject(ok.f) ; assertError(validObject(bad.f))
|
| 722 |
[1] TRUE
|
722 |
[1] TRUE
|
| 723 |
> setClass("myF", contains = "factor")
|
723 |
> setClass("myF", contains = "factor")
|
| 724 |
> validObject(new("myF", ok.f))
|
724 |
> validObject(new("myF", ok.f))
|
| 725 |
[1] TRUE
|
725 |
[1] TRUE
|
| 726 |
> assertCondition(validObject(new("myF", bad.f)), "error")
|
726 |
> assertError(validObject(new("myF", bad.f)))
|
| 727 |
> removeClass("myF")
|
727 |
> removeClass("myF")
|
| 728 |
[1] TRUE
|
728 |
[1] TRUE
|
| 729 |
> ## no validity check in R <= 2.9.0
|
729 |
> ## no validity check in R <= 2.9.0
|
| 730 |
>
|
730 |
>
|
| 731 |
> ## as(x, .) when x is from an "unregistered" S3 class :
|
731 |
> ## as(x, .) when x is from an "unregistered" S3 class :
|