test_that(".keep works as expected for univar tables", { expected <- tibble::tribble( ~cyl, ~label, ~X3, ~X4, ~X5, ~row_type, ~group_level, "4", "4", "", "", "", "BY_HEADER1", 0, "4", "N", "1", "8", "2", "N", 0, "4", "Mean (SD)", "21.50 (-)", "26.93 (4.807)", "28.20 (3.111)", "VALUE", 0, "4", "Median", "21.50", "25.85", "28.20", "VALUE", 0, "4", "Range", "(21.5; 21.5)", "(21.4; 33.9)", "(26.0; 30.4)", "VALUE", 0, "4", "IQ range", "(21.50; 21.50)", "(22.80; 31.40)", "(26.00; 30.40)", "VALUE", 0, "6", "6", "", "", "", "BY_HEADER1", 0, "6", "N", "2", "4", "1", "N", 0, "6", "Mean (SD)", "19.75 (2.333)", "19.75 (1.552)", "19.70 (-)", "VALUE", 0, "6", "Median", "19.75", "20.10", "19.70", "VALUE", 0, "6", "Range", "(18.1; 21.4)", "(17.8; 21.0)", "(19.7; 19.7)", "VALUE", 0, "6", "IQ range", "(18.10; 21.40)", "(18.50; 21.00)", "(19.70; 19.70)", "VALUE", 0, "8", "8", "", "", "", "BY_HEADER1", 0, "8", "N", "12", "0", "2", "N", 0, "8", "Mean (SD)", "15.05 (2.774)", "-", "15.40 (0.566)", "VALUE", 0, "8", "Median", "15.20", "-", "15.40", "VALUE", 0, "8", "Range", "(10.4; 19.2)", "(-; -)", "(15.0; 15.8)", "VALUE", 0, "8", "IQ range", "(13.80; 16.85)", "(-; -)", "(15.00; 15.80)", "VALUE", 0 ) expect_equal( mtcars %>% univar( colvar = "gear", rowvar = "mpg", rowbyvar = "cyl", .keep = TRUE ), expected, ignore_attr = TRUE ) })