Skip to content

Commit

Permalink
fix contrasts
Browse files Browse the repository at this point in the history
  • Loading branch information
stemangiola committed Dec 14, 2023
1 parent f2026be commit ea3a147
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 36 deletions.
4 changes: 2 additions & 2 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -2106,13 +2106,13 @@ mutate_from_expr_list = function(x, formula_expr, ignore_errors = TRUE){


# Check is backquoted are not used
require_back_quotes = contrasts_elements |> str_remove_all("`") |> contains_only_valid_chars_for_column()
require_back_quotes = !contrasts_elements |> str_remove_all("`") |> contains_only_valid_chars_for_column()
has_left_back_quotes = contrasts_elements |> str_detect("^`")
has_right_back_quotes = contrasts_elements |> str_detect("`$")
if_true_not_good = require_back_quotes & !(has_left_back_quotes & has_right_back_quotes)

if(any(if_true_not_good))
warning(sprintf("sccomp says: for columns which have special characters e.g. %s, you need to use surrounding backquotes ``.", paste(contrasts_elements[!if_false_not_good], sep=", ")))
warning(sprintf("sccomp says: for columns which have special characters e.g. %s, you need to use surrounding backquotes ``.", paste(contrasts_elements[!if_true_not_good], sep=", ")))

# Check if columns exist
contrasts_not_in_the_model =
Expand Down
29 changes: 0 additions & 29 deletions man/mutate_from_expr_list.Rd

This file was deleted.

16 changes: 11 additions & 5 deletions tests/testthat/test-sccomp_.R
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@ test_that("test constrasts",{

my_estimate |>
sccomp_test(contrasts = "(Intercept)") |>
expect_error("sccomp says: for columns which have special characters")
expect_error()

my_estimate |>
sccomp_test(contrasts = "typehealthy_") |>
expect_error("sccomp says: These components of your contrasts are not present in the model as parameters")
expect_error()

res = my_estimate_random |>
sccomp_test(contrasts = c("1/2*typecancer - 1/2*typehealthy", "1/2*typehealthy - 1/2*typecancer") )
Expand All @@ -417,9 +417,15 @@ test_that("test constrasts",{
-res[2,"c_effect"] |> as.numeric()
)

res =
my_estimate |>
sccomp_test(contrasts = c("(1/2*`continuous_covariate:typehealthy` + 1/2*`continuous_covariate:typehealthy`) - `continuous_covariate:typehealthy`") )
# Interaction
my_estimate |>
sccomp_test(contrasts = c("(1/2*`continuous_covariate:typehealthy` + 1/2*`continuous_covariate:typehealthy`) - `continuous_covariate:typehealthy`") ) |>
expect_s3_class("tbl")

# Wrong interaction
my_estimate |>
sccomp_test(contrasts = c("(1/2*continuous_covariate:typehealthy + 1/2*`continuous_covariate:typehealthy`) - `continuous_covariate:typehealthy`") ) |>
expect_warning("sccomp says: for columns which have special characters")


})
Expand Down

0 comments on commit ea3a147

Please sign in to comment.