From e3e10c2e882d36970de6cce01609e57ac9febd9e Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Wed, 11 Jul 2018 12:34:02 +0200 Subject: [PATCH] fix for macOS and older tidyr versions --- DESCRIPTION | 4 ++-- R/freq.R | 15 ++++----------- R/globals.R | 2 ++ tests/testthat/test-freq.R | 4 +--- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4549789c..6a3c0aba 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR Version: 0.2.0.9010 -Date: 2018-07-10 +Date: 2018-07-11 Title: Antimicrobial Resistance Analysis Authors@R: c( person( @@ -44,7 +44,7 @@ Suggests: covr (>= 3.0.1), rmarkdown, rstudioapi, - tidyr (>= 0.8.0) + tidyr VignetteBuilder: knitr URL: https://github.com/msberends/AMR BugReports: https://github.com/msberends/AMR/issues diff --git a/R/freq.R b/R/freq.R index e7cb4f71..6665500b 100755 --- a/R/freq.R +++ b/R/freq.R @@ -166,18 +166,11 @@ frequency_tbl <- function(x, if (!"tidyr" %in% rownames(installed.packages())) { stop('transformation from `table` to frequency table requires the tidyr package.', call. = FALSE) } - values <- x %>% + x <- x %>% as.data.frame(stringsAsFactors = FALSE) %>% - # delete last variable: these are frequencies - select(-ncol(.)) %>% - # paste all other columns: - tidyr::unite(sep = sep) %>% - .[, 1] - counts <- x %>% - as.data.frame(stringsAsFactors = FALSE) %>% - # get last variable: these are frequencies - pull(ncol(.)) - x <- rep(values, counts) + # paste first two columns + tidyr::unite(col = "Pasted", 1:2, sep = sep, remove = TRUE) + x <- rep(x %>% pull(Pasted), x %>% pull(Freq)) x.name <- "a `table` object" cols <- NULL mult.columns <- 2 diff --git a/R/globals.R b/R/globals.R index 1bfa1f5f..bb1e3503 100755 --- a/R/globals.R +++ b/R/globals.R @@ -30,6 +30,7 @@ globalVariables(c('abname', 'days_diff', 'fctlvl', 'first_isolate_row_index', + 'Freq', 'fullname', 'genus', 'gramstain', @@ -46,6 +47,7 @@ globalVariables(c('abname', 'n', 'na.omit', 'other_pat_or_mo', + 'Pasted', 'patient_id', 'quantile', 'real_first_isolate', diff --git a/tests/testthat/test-freq.R b/tests/testthat/test-freq.R index d4770978..be3de4c3 100755 --- a/tests/testthat/test-freq.R +++ b/tests/testthat/test-freq.R @@ -18,9 +18,7 @@ test_that("frequency table works", { # factor expect_output(print(freq(septic_patients$hospital_id))) # table - #if (Sys.info()['sysname'] %in% c("Windows", "Linux")) { - expect_output(print(freq(table(septic_patients$sex, septic_patients$age)))) - #} + expect_output(print(freq(table(septic_patients$sex, septic_patients$age)))) library(dplyr) expect_output(septic_patients %>% select(1:2) %>% freq() %>% print())