Skip to content

Commit

Permalink
styler
Browse files Browse the repository at this point in the history
  • Loading branch information
mattansb committed Aug 8, 2023
1 parent d4f149d commit d3c4fc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions R/contrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-contr.deviation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ])

Check warning on line 6 in tests/testthat/test-contr.deviation.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-contr.deviation.R,line=6,col=3,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.
expect_equal(c.deviation[-1, ], c.treatment[-1, ])

Check warning on line 7 in tests/testthat/test-contr.deviation.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-contr.deviation.R,line=7,col=3,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.
})

0 comments on commit d3c4fc3

Please sign in to comment.