From d3c4fc37e5525782a39baf839acca9222ac3704a Mon Sep 17 00:00:00 2001 From: "Mattan S. Ben-Shachar" Date: Tue, 8 Aug 2023 14:53:33 +0300 Subject: [PATCH] styler --- R/contrs.R | 13 ++++++++----- tests/testthat/test-contr.deviation.R | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/R/contrs.R b/R/contrs.R index 6a48842df..179d545bb 100644 --- a/R/contrs.R +++ b/R/contrs.R @@ -54,8 +54,10 @@ #' mtcars <- data_arrange(mtcars, select = c("cyl", "am")) #' #' mm <- unique(model.matrix(~ cyl * am, data = mtcars)) -#' rownames(mm) <- c("cyl4.am0", "cyl4.am1", "cyl6.am0", -#' "cyl6.am1", "cyl8.am0", "cyl8.am1") +#' rownames(mm) <- c( +#' "cyl4.am0", "cyl4.am1", "cyl6.am0", +#' "cyl6.am1", "cyl8.am0", "cyl8.am1" +#' ) #' #' solve(mm) #' #> cyl4.am0 cyl4.am1 cyl6.am0 cyl6.am1 cyl8.am0 cyl8.am1 @@ -72,9 +74,10 @@ contr.deviation <- function(n, base = 1, contrasts = TRUE, sparse = FALSE) { cont <- stats::contr.treatment(n, - base = base, - contrasts = contrasts, - sparse = sparse) + base = base, + contrasts = contrasts, + sparse = sparse + ) if (contrasts) { n <- nrow(cont) cont <- cont - 1 / n diff --git a/tests/testthat/test-contr.deviation.R b/tests/testthat/test-contr.deviation.R index 55e447277..40a61af40 100644 --- a/tests/testthat/test-contr.deviation.R +++ b/tests/testthat/test-contr.deviation.R @@ -3,6 +3,6 @@ test_that("contr.deviation", { c.sum <- solve(cbind(Intercept = 1, contr.sum(3))) c.deviation <- solve(cbind(Intercept = 1, contr.deviation(3))) - expect_equal(c.deviation[1,], c.sum[1,]) - expect_equal(c.deviation[-1,], c.treatment[-1,]) + expect_equal(c.deviation[1, ], c.sum[1, ]) + expect_equal(c.deviation[-1, ], c.treatment[-1, ]) })