diff --git a/NEWS.md b/NEWS.md index 24176ff9..7aef6641 100755 --- a/NEWS.md +++ b/NEWS.md @@ -26,6 +26,7 @@ ```r my_list = list(age = septic_patients$age, sex = septic_patients$sex) my_list %>% freq(age) + my_list %>% freq(sex) ``` #### Other @@ -53,8 +54,8 @@ * New Lancefield classification for *Streptococcus* to categorise them into Lancefield groups * For convience, new descriptive statistical functions `kurtosis` and `skewness` that are lacking in base R - they are generic functions and have support for vectors, data.frames and matrices * Function `g.test` to perform the Χ2 distributed [*G*-test](https://en.wikipedia.org/wiki/G-test), which use is the same as `chisq.test` -* Function `ratio` to transform a vector of values to a preset ratio - * For example: `ratio(c(10, 500, 10), ratio = "1:2:1")` would return `130, 260, 130` +* ~~Function `ratio` to transform a vector of values to a preset ratio~~ + * ~~For example: `ratio(c(10, 500, 10), ratio = "1:2:1")` would return `130, 260, 130`~~ * Support for Addins menu in RStudio to quickly insert `%in%` or `%like%` (and give them keyboard shortcuts), or to view the datasets that come with this package * Function `p.symbol` to transform p values to their related symbols: `0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1` * Functions `clipboard_import` and `clipboard_export` as helper functions to quickly copy and paste from/to software like Excel and SPSS. These functions use the `clipr` package, but are a little altered to also support headless Linux servers (so you can use it in RStudio Server) diff --git a/R/freq.R b/R/freq.R index 15010cc0..88de0ca4 100755 --- a/R/freq.R +++ b/R/freq.R @@ -413,11 +413,9 @@ frequency_tbl <- function(x, df <- df %>% summarise(count = n()) if (df$item %>% paste(collapse = ',') %like% '\033') { - df <- df %>% - mutate(item = item %>% - # remove escape char - # see https://en.wikipedia.org/wiki/Escape_character#ASCII_escape_character - gsub('\033', ' ', ., fixed = TRUE)) + # remove escape char + # see https://en.wikipedia.org/wiki/Escape_character#ASCII_escape_character + df <- df %>% mutate(item = item %>% gsub('\033', ' ', ., fixed = TRUE)) } # sort according to setting diff --git a/tests/testthat/test-freq.R b/tests/testthat/test-freq.R index 8e6a0338..08bb835d 100755 --- a/tests/testthat/test-freq.R +++ b/tests/testthat/test-freq.R @@ -51,6 +51,7 @@ test_that("frequency table works", { expect_output(septic_patients %>% select(1:7) %>% freq() %>% print()) expect_output(septic_patients %>% select(1:8) %>% freq() %>% print()) expect_output(septic_patients %>% select(1:9) %>% freq() %>% print()) + expect_output(print(freq(septic_patients$age), nmax = 20)) # top 5 expect_equal( diff --git a/tests/testthat/test-join_microorganisms.R b/tests/testthat/test-join_microorganisms.R index 3436a3f7..404fe6f7 100755 --- a/tests/testthat/test-join_microorganisms.R +++ b/tests/testthat/test-join_microorganisms.R @@ -23,9 +23,18 @@ test_that("joins work", { expect_true(nrow(unjoined) < nrow(right)) expect_true(nrow(unjoined) < nrow(full)) + expect_equal(nrow(inner_join_microorganisms("ESCCOL")), 1) + expect_equal(nrow(inner_join_microorganisms("ESCCOL", by = c("bactid" = "bactid"))), 1) + expect_warning(inner_join_microorganisms("Escherichia", by = c("bactid" = "genus"))) + expect_equal(nrow(left_join_microorganisms("ESCCOL")), 1) + expect_warning(left_join_microorganisms("Escherichia", by = c("bactid" = "genus"))) + expect_equal(nrow(semi_join_microorganisms("ESCCOL")), 1) expect_equal(nrow(anti_join_microorganisms("ESCCOL")), 0) + eexpect_warning(right_join_microorganisms("ESCCOL")) + eexpect_warning(full_join_microorganisms("ESCCOL")) + })