1- dat <- data.frame (rel = c(1 : 6 , NA , 7 , 8 ),
2- period = c(1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 ),
3- ea = c(" 11" , " 11" , " 12" , " 12" , " 13" , " 11" , " 12" , " 11" , " 14" ))
1+ dat <- data.frame (
2+ rel = c(1 : 6 , NA , 7 , 8 ),
3+ period = c(1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 ),
4+ ea = c(" 11" , " 11" , " 12" , " 12" , " 13" , " 11" , " 12" , " 11" , " 14" )
5+ )
46
57pias <- as_aggregation_structure(
68 data.frame (level1 = 1 , level2 = c(11 , 12 , 13 , 14 ), weight = 1 )
@@ -24,9 +26,10 @@ test_that("as_index works with matrices", {
2426 expect_equal(as_index(as.matrix(epr )), epr2 )
2527 expect_equal(
2628 contrib(as_index(as.matrix(epr ), contrib = TRUE )),
27- as.matrix(epr )[1 , , drop = FALSE ] - 1
29+ as.matrix(epr )[1 , , drop = FALSE ] - 1 ,
30+ ignore_attr = TRUE
2831 )
29-
32+
3033 # A character vector used to get pass through without coercion.
3134 mat <- as.matrix(epr )
3235 mat [] <- as.character(mat )
@@ -38,7 +41,8 @@ test_that("as_index works for data frames", {
3841 expect_equal(as_index(as.data.frame(epr )), epr2 )
3942 expect_equal(
4043 contrib(as_index(as.data.frame(epr ), contrib = TRUE )),
41- as.matrix(epr )[1 , , drop = FALSE ] - 1
44+ as.matrix(epr )[1 , , drop = FALSE ] - 1 ,
45+ ignore_attr = TRUE
4246 )
4347 df <- as.data.frame(epr )
4448 df [[1 ]] <- factor (df [[1 ]], levels = 2 : 1 )
@@ -49,12 +53,12 @@ test_that("as_index works for data frames", {
4953 elemental_index(rel , period = factor (period , levels = 2 : 1 ), ea = ea )
5054 )
5155 )
52-
56+
5357 expect_equal(
5458 as_index(data.frame (1 : 5 , 1 : 5 , 1 : 5 )),
5559 as_index(matrix (replace(NA , c(1 , 7 , 13 , 19 , 25 ), 1 : 5 ), 5 ))
5660 )
57-
61+
5862 expect_error(as_index(df [1 : 2 ]))
5963})
6064
@@ -74,17 +78,17 @@ test_that("as_index works with contribs", {
7478 as_index(as.data.frame(epr2 , contrib = TRUE ), contrib = TRUE ),
7579 epr2
7680 )
77-
81+
7882 index2 <- aggregate(epr , pias , contrib = FALSE )
7983 index2df <- as.data.frame(index2 , contrib = TRUE )
8084 expect_equal(
8185 as_index(index2df [- 1 , ], contrib = TRUE ),
8286 index2
8387 )
84-
88+
8589 index2df [1 , 4 ] <- list (a = 0 )
8690 expect_error(as_index(index2df , contrib = TRUE ))
87-
91+
8892 index2df [1 , 4 ][[1 ]] <- list (c(a = 2 , a = 1 , b = NA ))
8993 expect_warning(index2 <- as_index(index2df , contrib = TRUE ))
9094 expect_identical(rownames(contrib(index2 )), c(" a" , " a.1" , " b" ))
0 commit comments