Update freq function

This commit is contained in:
uscloud
2018-05-22 16:34:22 +02:00
parent 0d80647d41
commit dcc26dd942
71 changed files with 26 additions and 28 deletions
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
+6 -7
View File
@@ -1,5 +1,3 @@
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
# Setting up R deps
language: r
r: 3.2
@@ -10,10 +8,11 @@ cache: packages
os:
- linux
- osx
before_install:
- if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get -qq update; fi
- if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -y xclip; fi
- if [ $TRAVIS_OS_NAME = osx ]; then brew install xclip; fi
#before_install:
# # needed for clipboard function:
# - if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get -qq update; fi
# - if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -y xclip; fi
# - if [ $TRAVIS_OS_NAME = osx ]; then brew install xclip; fi
# postrun
after_success:
@@ -22,6 +21,6 @@ notifications:
email:
recipients:
- m.s.berends@umcg.nl
- c.f.luz@umcg.nl
# - c.f.luz@umcg.nl
on_success: change
on_failure: change
Regular → Executable
+1 -1
View File
@@ -1,6 +1,6 @@
Package: AMR
Version: 0.2.0.9000
Date: 2018-05-09
Date: 2018-05-22
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
+1 -1
View File
@@ -1,4 +1,4 @@
# 0.2.9000 (development version)
# 0.2.0.9000 (development version)
#### New
* Vignettes about frequency tables
* Possibility to globally set the default for the amount of items to print in frequency tables (`freq` function), with `options(max.print.freq = n)`
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
+12 -12
View File
@@ -21,7 +21,7 @@
#' Create a frequency table of a vector of data, a single column or a maximum of 9 columns of a data frame. Supports markdown for reports.
#' @param x data
#' @param sort.count Sort on count. Use \code{FALSE} to sort alphabetically on item.
#' @param nmax number of row to print. The default, \code{15}, uses \code{\link[base]{getOption}("max.print.freq")}. Use \code{nmax = 0} or \code{nmax = NA} to print all rows.
#' @param nmax number of row to print. The default, \code{15}, uses \code{\link{getOption}("max.print.freq")}. Use \code{nmax = 0} or \code{nmax = NA} to print all rows.
#' @param na.rm a logical value indicating whether NA values should be removed from the frequency table. The header will always print the amount of \code{NA}s.
#' @param markdown print table in markdown format (this forces \code{nmax = NA})
#' @param as.data.frame return frequency table without header as a \code{data.frame} (e.g. to assign the table to an object)
@@ -337,18 +337,18 @@ freq <- function(x,
align = column_align,
padding = 1)
)
cat('... and ',
format(nrow(df) - nmax),
' more ',
paste0('(n = ',
format(Count.rest),
'; ',
(Count.rest / length(x)) %>% percent(force_zero = TRUE),
')'),
'.', sep = '')
if (nmax.set == FALSE) {
cat(' Use `nmax` to show more or less rows.')
if (nmax.set == TRUE) {
cat('[ reached `nmax = ', nmax, '`', sep = '')
} else {
cat('[ reached getOption("max.print.freq")')
}
cat(' -- omitted ',
format(nrow(df) - nmax),
' entries, n = ',
format(Count.rest),
' (',
(Count.rest / length(x)) %>% percent(force_zero = TRUE),
') ]\n', sep = '')
cat('\n')
} else {
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
-1
View File
@@ -1 +0,0 @@
theme: jekyll-theme-cayman
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Regular → Executable
View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Regular → Executable
View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Regular → Executable
View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Regular → Executable
View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Regular → Executable
View File

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

Regular → Executable
View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Regular → Executable
View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Regular → Executable
View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Regular → Executable
View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Regular → Executable
View File
Regular → Executable
+1 -1
View File
@@ -18,7 +18,7 @@ frequency_tbl(x, sort.count = TRUE, nmax = getOption("max.print.freq"),
\item{sort.count}{Sort on count. Use \code{FALSE} to sort alphabetically on item.}
\item{nmax}{number of row to print. The default, \code{15}, uses \code{\link[base]{getOption}("max.print.freq")}. Use \code{nmax = 0} or \code{nmax = NA} to print all rows.}
\item{nmax}{number of row to print. The default, \code{15}, uses \code{\link{getOption}("max.print.freq")}. Use \code{nmax = 0} or \code{nmax = NA} to print all rows.}
\item{na.rm}{a logical value indicating whether NA values should be removed from the frequency table. The header will always print the amount of \code{NA}s.}
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
+3 -3
View File
@@ -2,12 +2,12 @@ context("rsi_analysis.R")
test_that("rsi works", {
# amox resistance in `septic_patients` should be around 53.86%
expect_equal(rsi(septic_patients$amox), 0.5386, tolerance = 0.0001)
expect_equal(rsi(septic_patients$amox), 0.5386, tolerance = 0.0001)
expect_equal(rsi(septic_patients$amox), 0.5756, tolerance = 0.0001)
expect_equal(rsi(septic_patients$amox), 0.5756, tolerance = 0.0001)
expect_equal(rsi_df(septic_patients,
ab = "amox",
info = FALSE),
0.5386,
0.5756,
tolerance = 0.0001)
# pita+genta susceptibility around 98.09%
expect_equal(rsi(septic_patients$pita,
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
+2 -2
View File
@@ -105,7 +105,7 @@ So for example, the above frequency table quickly shows the median age of patien
Frequencies of factors will be sorted on factor level instead of item count by default. This can be changed with the `sort.count` parameter. Frequency tables of factors always show the factor level as an additional last column.
`sort.count` is `TRUE` by default, except for factors. Compare this default behaviour:
`sort.count` is `TRUE` by default, except for factors. Compare this default behaviour...
```{r, echo = TRUE}
septic_patients %>%
@@ -113,7 +113,7 @@ septic_patients %>%
freq()
```
To this, where items are now sorted on item count:
... with this, where items are now sorted on count:
```{r, echo = TRUE}
septic_patients %>%