Skip to content

Commit

Permalink
Merge pull request #57 from bluefoxr/aggregate_debug
Browse files Browse the repository at this point in the history
Aggregate debug
  • Loading branch information
bluefoxr committed May 6, 2024
2 parents 191582d + 216fe88 commit 9625e10
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,8 @@ a_copeland <- function(X, w = NULL){
orm <- outrankMatrix(X, w)$OutRankMatrix

orm[orm > 0.5] <- 1
orm[orm == 0.5] <- 0
orm[orm < 0.5] <- -1
orm[orm == 0.5] <- 0
diag(orm) <- 0

# get scores by summing across rows
Expand Down
31 changes: 30 additions & 1 deletion R/treat.R
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ Treat.data.frame <- function(x, global_specs = NULL, indiv_specs = NULL, combine
}
}
# merge with defaults (overwrites any differences)
specs <- utils::modifyList(specs_def, indiv_specs_col)
#specs <- utils::modifyList(specs_def, indiv_specs_col)
specs <- modify_treat_specs(specs_def, indiv_specs_col)
} else {
# otherwise, use defaults
specs <- specs_def
Expand Down Expand Up @@ -1222,3 +1223,31 @@ check_SkewKurt <- function(x, na.rm = FALSE, skew_thresh = 2, kurt_thresh = 3.5)
# output
list(Pass = ans, Skew = sk, Kurt = kt)
}


modify_treat_specs <- function(l_def, l_mod){

if(is.null(l_mod)){
return(l_def)
}

l_out <- l_def

# if any functions have changed we completely delete the function parameters
# to avoid passing unused arguments
if(!identical(l_def$f1, l_mod$f1)){
l_out$f1_para <- NULL
}
if(!identical(l_def$f2, l_mod$f2)){
l_out$f2_para <- NULL
}
if(!identical(l_def$f_pass, l_mod$f_pass)){
l_out$f_pass_para <- NULL
}

# now, merge lists
l_out <- utils::modifyList(l_out, l_mod)

l_out

}
15 changes: 14 additions & 1 deletion tests/testthat/test-aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,25 @@ test_that("copeland", {

orm <- outrankMatrix(X)$OutRankMatrix
orm[orm > 0.5] <- 1
orm[orm == 0.5] <- 0
orm[orm < 0.5] <- -1
orm[orm == 0.5] <- 0
diag(orm) <- 0

expect_equal(y, rowSums(orm))

# test equal units correctly assigned
X <- data.frame(
x1 = c(1,2),
x2 = c(2,1)
)

orm <- outrankMatrix(X)$OutRankMatrix
expect_equal(orm[1,2], 0.5)
expect_equal(orm[2,1], 0.5)

y <- a_copeland(X)
expect_equal(y, c(0,0))

})

test_that("aggregation by level", {
Expand Down

0 comments on commit 9625e10

Please sign in to comment.