Skip to content

Commit d9a310c

Browse files
committed
feat: Adds functions enable_suppression() and disable_suppression()
1 parent 8069069 commit d9a310c

5 files changed

Lines changed: 61 additions & 3 deletions

File tree

R/acro_init.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Globals -----------------------------------------------------------------
22
acro_venv <- "r-acro"
3-
acro_pkg <- "acro==0.4.11"
3+
acro_pkg <- "acro==0.4.12"
44
ch <- "conda-forge"
55

66

R/output_commands.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,30 @@ acro_finalise <- function(path, ext) {
9898
}
9999
acroEnv$ac$finalise(path, ext)
100100
}
101+
102+
103+
#' Turns suppresssion on during a session
104+
#'
105+
#' @return No return value, called for side effects
106+
#' @export
107+
108+
acro_enable_suppression <- function() {
109+
if (is.null(acroEnv$ac)) {
110+
stop("ACRO has not been initialised. Please first call acro_init().")
111+
}
112+
acroEnv$ac$enable_suppression()
113+
}
114+
115+
#' Turns suppresssion off during a session
116+
#'
117+
#' @return No return value, called for side effects
118+
#' @export
119+
120+
acro_disable_suppression <- function() {
121+
if (is.null(acroEnv$ac)) {
122+
stop("ACRO has not been initialised. Please first call acro_init().")
123+
}
124+
acroEnv$ac$disable_suppression()
125+
}
126+
127+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
test_that("acro_enable_suppression without initialising ACRO object first", {
2+
acroEnv$ac <- NULL
3+
expect_error(acro_disable_suppression(), "ACRO has not been initialised. Please first call acro_init()")
4+
})
5+
6+
test_that("acro_disable_suppression works", {
7+
testthat::skip_on_cran()
8+
acro_init()
9+
foo <- acro_disable_suppression()
10+
table <- acro_crosstab(index = nursery_data[, c("recommend")], columns = nursery_data[, c("parents")])
11+
output <- acro_print_outputs()
12+
status <- "fail"
13+
expect_true(any(grepl(status, output)))
14+
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
test_that("acro_enable_suppression without initialising ACRO object first", {
2+
acroEnv$ac <- NULL
3+
expect_error(acro_enable_suppression()(), "ACRO has not been initialised. Please first call acro_init()")
4+
})
5+
6+
test_that("acro_enable_suppression works", {
7+
testthat::skip_on_cran()
8+
acro_init()
9+
acro_enable_suppression()
10+
table <- acro_crosstab(index = nursery_data[, c("recommend")], columns = nursery_data[, c("parents")])
11+
output <- acro_print_outputs()
12+
status <- "review"
13+
expect_true(any(grepl(status, output)))
14+
})

tests/testthat/test-acro_pivot_table.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ test_that("acro_pivot_table without initialising ACRO object first", {
66
test_that("acro_pivot_table works", {
77
testthat::skip_on_cran()
88
expected_table <- data.frame(
9-
"('mean', 'children')" = c(3.272222, 3.242593, 3.241667),
10-
"('std', 'children')" = c(2.48458394, 2.43848908, 2.42963966),
9+
# "(mean', 'children')" = c(3.272222, 3.242593, 3.241667),
10+
# "('std', 'children')" = c(2.48458394, 2.43848908, 2.42963966),
11+
"mean children" = c(3.272222, 3.242593, 3.241667),
12+
"std children" = c(2.48458394, 2.43848908, 2.42963966),
1113
check.names = FALSE
1214
)
1315

@@ -17,6 +19,7 @@ test_that("acro_pivot_table works", {
1719

1820
acro_init()
1921
table <- acro_pivot_table(data = nursery_data, index = "parents", values = "children", aggfunc = list("mean", "std"))
22+
print( table)
2023
print(expected_table)
2124
expect_equal(table[, -1, drop = FALSE], expected_table[, -1, drop = FALSE])
2225
})

0 commit comments

Comments
 (0)