fix for macOS and older tidyr versions

This commit is contained in:
dr. M.S. (Matthijs) Berends 2018-07-11 12:34:02 +02:00
parent eca406b18b
commit e3e10c2e88
4 changed files with 9 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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',

View File

@ -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())