Skip to content

Commit

Permalink
Improve "cat" context
Browse files Browse the repository at this point in the history
  • Loading branch information
gdemin committed Aug 27, 2023
1 parent 50835e5 commit ef8f81a
Show file tree
Hide file tree
Showing 63 changed files with 197 additions and 394 deletions.
6 changes: 2 additions & 4 deletions inst/tinytest/test_add_columns.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("add_columns", "
")
cat("\nCONTEXT:", "add_columns", "\n")

sh1 = sheet(a = 1:5, b = 5:1)
sh2 = sheet(a = 4:2, d = 4:2)
Expand Down Expand Up @@ -89,8 +88,7 @@ expect_identical(add_columns(sh1, sh2, by = c("b" = "a", "a" = "b")), res)


############################
cat("add_columns data.table", "
")
cat("\nCONTEXT:", "add_columns data.table", "\n")
# data.table is modified by reference
sh1 = data.table(a = 1:5, b = 5:1)
sh2 = data.table(a = 4:2, d = 4:2)
Expand Down
15 changes: 5 additions & 10 deletions inst/tinytest/test_add_rows.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("add_rows", "
")
cat("\nCONTEXT:", "add_rows", "\n")

a = data.frame(x = 1:5, y = 6:10)
b = data.frame(y = 6:10, z = 11:15)
Expand All @@ -18,8 +17,7 @@ expect_equal_to_reference(add_rows(a, NA), "rds/add_rows6a.rds")
expect_equal_to_reference(add_rows(a, 1:2), "rds/add_rows6b.rds")


cat("add_rows.etable", "
")
cat("\nCONTEXT:", "add_rows.etable", "\n")

a = data.frame(x = 1:5, y = 6:10)
b = data.frame(y = 6:10, z = 11:15)
Expand All @@ -41,8 +39,7 @@ expect_equal_to_reference(add_rows(a, 1:2), "rds/add_rows11e.rds")



cat("labels preserving", "
")
cat("\nCONTEXT:", "labels preserving", "\n")

a = sheet(x = 1:5, y = 11:15)
b = sheet(x = 6:10, z = 16:20)
Expand All @@ -66,8 +63,7 @@ val_lab(res$y) = c("yyy" = 1)

expect_identical(add_rows(a, b), res)

cat("etable", "
")
cat("\nCONTEXT:", "etable", "\n")
data(mtcars)
mtcars = apply_labels(mtcars,
mpg = "Miles/(US) gallon",
Expand Down Expand Up @@ -107,8 +103,7 @@ a = matrix(1:9, 3)
expect_identical(add_rows(a, NA), rbind(a, NA))


cat("add_rows duplicated column names", "
")
cat("\nCONTEXT:", "add_rows duplicated column names", "\n")


data(iris)
Expand Down
6 changes: 2 additions & 4 deletions inst/tinytest/test_apply_labels.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("apply_labels", "
")
cat("\nCONTEXT:", "apply_labels", "\n")

data(mtcars)
correct_mtcars = mtcars
Expand Down Expand Up @@ -150,8 +149,7 @@ expect_identical(val_lab(dt_mt$vs), c("V-engine" = 0,
expect_silent(dt_mt[,new:=1])
expect_silent(new_mt[,new:=1])

cat("apply_labels list argument", "
")
cat("\nCONTEXT:", "apply_labels list argument", "\n")

data(mtcars)
correct_mtcars = mtcars
Expand Down
3 changes: 1 addition & 2 deletions inst/tinytest/test_category.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("category", "
")
cat("\nCONTEXT:", "category", "\n")
suppressWarnings(RNGversion("3.5.0"))

set.seed(123)
Expand Down
21 changes: 7 additions & 14 deletions inst/tinytest/test_count_if.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("count_if", "
")
cat("\nCONTEXT:", "count_if", "\n")
suppressWarnings(RNGversion("3.5.0"))
df1 = data.frame(
a=c("apples", "oranges", "peaches", "apples"),
Expand Down Expand Up @@ -40,8 +39,7 @@ expect_equal(count_if(35 %thru% 80, df1$b),2L)

expect_equal(count_if(33:85,df1$b),2L)

cat("count_if character", "
")
cat("\nCONTEXT:", "count_if character", "\n")

expect_equal(count_if("a", letters),1L)
expect_equal(count_if(gt("a"), letters),25L)
Expand All @@ -53,8 +51,7 @@ expect_equal(count_if(eq("b"), letters),1L)
# expect_warning(count_if(c(eq(b),"d"), letters))
expect_equal(count_if(c("a","b"), letters),2L)

cat("count_ifs", "
")
cat("\nCONTEXT:", "count_ifs", "\n")

df3 = data.frame(
"Sales Person" = c("Davidoski", "Burke", "Sundaram", "Levitan"),
Expand All @@ -67,8 +64,7 @@ expect_equal(count_if("Yes", df3[1,2:4]), 1) # Counts how many times Davidoski e



cat("count_if complex criteria", "
")
cat("\nCONTEXT:", "count_if complex criteria", "\n")
# more complex criteria
# values with letters
expect_equal(count_if(function(x) grepl("^[A-z]+$",x),df1),4L)
Expand All @@ -79,8 +75,7 @@ expect_equal(count_if(regex("[:alpha:]"),df1),4L)
expect_equal(count_if(function(x) grepl("^a",x),df1),2L)
expect_equal(count_if(perl("^a"),df1),2L)

cat("count_row_if", "
")
cat("\nCONTEXT:", "count_row_if", "\n")


expect_equal(count_row_if(function(x) grepl("^a",x),df1),c(1,0,0,1))
Expand All @@ -92,8 +87,7 @@ expect_equal(df1 %col_in% 'apples', c(a = TRUE, b = FALSE))



cat("count_col_if", "
")
cat("\nCONTEXT:", "count_col_if", "\n")


expect_equal(count_col_if(function(x) grepl("^a",x),t(df1)),
Expand Down Expand Up @@ -182,8 +176,7 @@ expect_equal(
c(9, 8, 9)
)

cat("count_if new examples", "
")
cat("\nCONTEXT:", "count_if new examples", "\n")
set.seed(123)
dfs = as.data.frame(
matrix(sample(c(1:10,NA),30,replace = TRUE),10)
Expand Down
3 changes: 1 addition & 2 deletions inst/tinytest/test_create_dictionary.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("create dictionary/apply_dictionary", "
")
cat("\nCONTEXT:", "create dictionary/apply_dictionary", "\n")


df = sheet(
Expand Down
3 changes: 1 addition & 2 deletions inst/tinytest/test_criteria_functions.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("criteria", "
")
cat("\nCONTEXT:", "criteria", "\n")

expect_equal(gt(5)(5), FALSE)
expect_equal((5 | gt(5))(5), TRUE)
Expand Down
9 changes: 3 additions & 6 deletions inst/tinytest/test_cro_extended.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("cro extended", "
")
cat("\nCONTEXT:", "cro extended", "\n")
suppressWarnings(RNGversion("3.5.0"))

data(mtcars)
Expand Down Expand Up @@ -138,8 +137,7 @@ expect_equal_to_reference(
"rds/long_table26.rds", update = FALSE)


cat("cro extended some exotics", "
")
cat("\nCONTEXT:", "cro extended some exotics", "\n")

mult1 = sheet(v1 = c(1,1,NA), v2 = c(NA, 2, 2))
mult2 = sheet(b1 = c(1, 1, 2), b2 = c(3, NA, 1))
Expand Down Expand Up @@ -207,8 +205,7 @@ expect_equal_to_reference(



cat("cro multiple by multiple", "
")
cat("\nCONTEXT:", "cro multiple by multiple", "\n")

data("product_test")
codeframe_likes = num_lab("
Expand Down
12 changes: 4 additions & 8 deletions inst/tinytest/test_cro_fun_df_extended.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ suppressWarnings(RNGversion("3.5.0"))

#################################

cat("cro_fun_df", "
")
cat("\nCONTEXT:", "cro_fun_df", "\n")

data(mtcars)
mtcars = apply_labels(mtcars,
Expand Down Expand Up @@ -280,8 +279,7 @@ expect_error(



cat("table correlations", "
")
cat("\nCONTEXT:", "table correlations", "\n")



Expand Down Expand Up @@ -377,8 +375,7 @@ expect_equal(cro_spearman(mtcars %>% columns(-vs, -am), col_vars = "Total")[[2]]
unname(cor(mtcars %>% columns(-vs, -am), method = "spearman")[,1]))


cat("table_summary_df datetime", "
")
cat("\nCONTEXT:", "table_summary_df datetime", "\n")

dates = as.POSIXct(rep(paste0("2017-02-", 1:10), each = 10))
measure = runif(length(dates), 1, 2)
Expand All @@ -400,8 +397,7 @@ expect_equal_to_reference(
,"rds/table_summary_df_dates4.rds", update = FALSE
)

cat("cro_fun_df duplicated names", "
")
cat("\nCONTEXT:", "cro_fun_df duplicated names", "\n")

expect_equal_to_reference(
calculate(mtcars, cro_mean(list(mpg, mpg, mpg, mpg), list(am))),
Expand Down
9 changes: 3 additions & 6 deletions inst/tinytest/test_cro_fun_extended.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
if(isTRUE(getOption("covr"))){


cat("cro_fun extended", "
")
cat("\nCONTEXT:", "cro_fun extended", "\n")
suppressWarnings(RNGversion("3.5.0"))


Expand Down Expand Up @@ -324,8 +323,7 @@ if(isTRUE(getOption("covr"))){
fun = combine_functions(w_mean)))
)
# calc(w, fre(a1_1 %to% a1_6))
cat("cro_mean_sd_n", "
")
cat("\nCONTEXT:", "cro_mean_sd_n", "\n")

data(mtcars)
mtcars = apply_labels(mtcars,
Expand Down Expand Up @@ -429,8 +427,7 @@ if(isTRUE(getOption("covr"))){
"rds/cro_mean_sd_n4_1.rds", update = FALSE
)

cat("cro_fun unsafe labels", "
")
cat("\nCONTEXT:", "cro_fun unsafe labels", "\n")

fun = function(x) c(sum(x), mean(x), length(x))

Expand Down
3 changes: 1 addition & 2 deletions inst/tinytest/test_cro_new_test.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("cro new tests", "
")
cat("\nCONTEXT:", "cro new tests", "\n")
a = set_val_lab(1:5, c(a = 1, b = 2, d = 3))
var_lab(a) = "My a"
expect_identical(cro(mrset(a)), cro(a))
Expand Down
18 changes: 6 additions & 12 deletions inst/tinytest/test_custom_tables.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
if(isTRUE(getOption("covr"))) {

cat("custom tables", "
")
cat("\nCONTEXT:", "custom tables", "\n")
suppressWarnings(RNGversion("3.5.0"))

data(mtcars)
Expand Down Expand Up @@ -337,8 +336,7 @@ if(isTRUE(getOption("covr"))) {
tab_pivot(stat_position = "inside_rows")
expect_equal_to_reference(res, "rds/ctable18.rds")

cat("custom tables summary stats", "
")
cat("\nCONTEXT:", "custom tables summary stats", "\n")

mtcars$mpg[1:2] = NA
mtcars$wt[4:5] = NA
Expand Down Expand Up @@ -956,8 +954,7 @@ if(isTRUE(getOption("covr"))) {

expect_output_file(print(res), "rds/print_intermediate_table.txt")

cat("custom tables error", "
")
cat("\nCONTEXT:", "custom tables error", "\n")

expect_error(
mtcars %>% tab_stat_cases()
Expand Down Expand Up @@ -999,8 +996,7 @@ if(isTRUE(getOption("covr"))) {
1:5 %>% tab_cells(42)
)

cat("custom table long expression as argument", "
")
cat("\nCONTEXT:", "custom table long expression as argument", "\n")


res = mtcars %>%
Expand Down Expand Up @@ -1152,8 +1148,7 @@ if(isTRUE(getOption("covr"))) {
tab_stat_cpct() %>%
tab_pivot()

cat("tab_last_vstack/tab_last_hstack", "
")
cat("\nCONTEXT:", "tab_last_vstack/tab_last_hstack", "\n")

res = pr_t %>% tab_cols(total(), age_cat) %>%
tab_cells("Mean" = unlab(a22)) %>%
Expand Down Expand Up @@ -1195,8 +1190,7 @@ if(isTRUE(getOption("covr"))) {
"rds/ctable41.rds", update = FALSE
)

cat("tab_pivot inside columns double labels", "
")
cat("\nCONTEXT:", "tab_pivot inside columns double labels", "\n")
res = mtcars %>%
tab_cells(am) %>%
tab_cols(total(), vs, vs) %>%
Expand Down
6 changes: 2 additions & 4 deletions inst/tinytest/test_custom_tables_sig.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
if(isTRUE(getOption("covr"))){


cat("custom tables significance cpct", "
")
cat("\nCONTEXT:", "custom tables significance cpct", "\n")

data(mtcars)
mtcars = apply_labels(mtcars,
Expand Down Expand Up @@ -174,8 +173,7 @@ if(isTRUE(getOption("covr"))){
"rds/ct_signif_cpct10.rds", update = FALSE)


cat("custom tables significance means", "
")
cat("\nCONTEXT:", "custom tables significance means", "\n")

mtcars_table = cro_mean_sd_n(list(mtcars$mpg, mtcars$hp),
list(total(), mtcars$vs, mtcars$am))
Expand Down
6 changes: 2 additions & 4 deletions inst/tinytest/test_dichotomy.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("dichotomy.default", "
")
cat("\nCONTEXT:", "dichotomy.default", "\n")
suppressWarnings(RNGversion("3.5.0"))


Expand Down Expand Up @@ -250,8 +249,7 @@ expect_identical(dummy(vec,drop_labels=letters[1:3]),structure(c(0, 0, 0, 1, 0,
NULL, c("d", "e")), class = c("dichotomy", MATRIX_CLASS)))


cat("dichotomy.data.frame", "
")
cat("\nCONTEXT:", "dichotomy.data.frame", "\n")
vec = data.frame(1)

expect_identical(dummy(vec),
Expand Down
3 changes: 1 addition & 2 deletions inst/tinytest/test_drop_empty.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("drop_empty_*", "
")
cat("\nCONTEXT:", "drop_empty_*", "\n")
data("mtcars")
mtcars = apply_labels(mtcars,
vs = "Engine",
Expand Down
3 changes: 1 addition & 2 deletions inst/tinytest/test_drop_unused_labels.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cat("drop_unused_labels", "
")
cat("\nCONTEXT:", "drop_unused_labels", "\n")

a = as.double(1:2)
expect_identical(drop_unused_labels(a), a)
Expand Down

0 comments on commit ef8f81a

Please sign in to comment.