mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 20:46:11 +01:00
fix freq length calculation
This commit is contained in:
parent
30ff770c93
commit
ae44b185e6
@ -1,6 +1,6 @@
|
||||
Package: AMR
|
||||
Version: 0.5.0.9017
|
||||
Date: 2019-02-12
|
||||
Date: 2019-02-13
|
||||
Title: Antimicrobial Resistance Analysis
|
||||
Authors@R: c(
|
||||
person(
|
||||
|
38
R/freq.R
38
R/freq.R
@ -352,6 +352,14 @@ frequency_tbl <- function(x,
|
||||
NAs <- x[is.na(x)]
|
||||
}
|
||||
|
||||
if (mult.columns > 0) {
|
||||
header_list <- list(columns = mult.columns)
|
||||
} else {
|
||||
header_list <- list(class = class(x),
|
||||
mode = mode(x))
|
||||
}
|
||||
header_list$length <- length(x)
|
||||
|
||||
if (na.rm == TRUE) {
|
||||
x_class <- class(x)
|
||||
x <- x[!x %in% NAs]
|
||||
@ -364,13 +372,6 @@ frequency_tbl <- function(x,
|
||||
}
|
||||
x_align <- "l"
|
||||
|
||||
if (mult.columns > 0) {
|
||||
header_list <- list(columns = mult.columns)
|
||||
} else {
|
||||
header_list <- list(class = class(x),
|
||||
mode = mode(x))
|
||||
}
|
||||
|
||||
if (!is.null(levels(x))) {
|
||||
header_list$levels <- levels(x)
|
||||
header_list$ordered <- is.ordered(x)
|
||||
@ -381,7 +382,6 @@ frequency_tbl <- function(x,
|
||||
}
|
||||
}
|
||||
|
||||
header_list$length <- length(x)
|
||||
header_list$na_length <- length(NAs)
|
||||
header_list$unique <- n_distinct(x)
|
||||
|
||||
@ -559,7 +559,7 @@ format_header <- function(x, markdown = FALSE, decimal.mark = ".", big.mark = ",
|
||||
|
||||
header <- header(x)
|
||||
x_class <- header$class
|
||||
has_length <- header$length + header$na_length > 0
|
||||
has_length <- header$length > 0
|
||||
|
||||
# FORMATTING
|
||||
# rsi
|
||||
@ -633,23 +633,25 @@ format_header <- function(x, markdown = FALSE, decimal.mark = ".", big.mark = ",
|
||||
}
|
||||
# levels
|
||||
if (!is.null(header$levels)) {
|
||||
n_levels <- header$levels %>% length()
|
||||
n_levels_list <- header$levels
|
||||
if (n_levels > 5) {
|
||||
n_levels_list <- c(n_levels_list[1:5], "...")
|
||||
if (markdown == TRUE) {
|
||||
header$levels <- paste0("`", header$levels, "`")
|
||||
}
|
||||
if (header$ordered == TRUE) {
|
||||
n_levels_list <- paste0(n_levels_list, collapse = " < ")
|
||||
levels_text <- paste0(header$levels, collapse = " < ")
|
||||
} else {
|
||||
n_levels_list <- paste0(n_levels_list, collapse = ", ")
|
||||
levels_text <- paste0(header$levels, collapse = ", ")
|
||||
}
|
||||
header$levels <- n_levels_list
|
||||
if (nchar(levels_text) > 70) {
|
||||
# levels text wider than half the console
|
||||
levels_text <- paste0(substr(levels_text, 1, 70 - 3), "...")
|
||||
}
|
||||
header$levels <- paste0(length(header$levels), ": ", levels_text)
|
||||
header <- header[names(header) != "ordered"]
|
||||
}
|
||||
# length and NAs
|
||||
if (has_length == TRUE) {
|
||||
na_txt <- paste0(header$na_length %>% format(decimal.mark = decimal.mark, big.mark = big.mark), " = ",
|
||||
(header$na_length / (header$na_length + header$length)) %>% percent(force_zero = TRUE, round = digits, decimal.mark = decimal.mark) %>%
|
||||
(header$na_length / header$length) %>% percent(force_zero = TRUE, round = digits, decimal.mark = decimal.mark) %>%
|
||||
sub("NaN", "0", ., fixed = TRUE))
|
||||
if (!na_txt %like% "^0 =") {
|
||||
na_txt <- red(na_txt)
|
||||
@ -660,7 +662,7 @@ format_header <- function(x, markdown = FALSE, decimal.mark = ".", big.mark = ",
|
||||
} else {
|
||||
na_txt <- ""
|
||||
}
|
||||
header$length <- paste((header$na_length + header$length) %>% format(decimal.mark = decimal.mark, big.mark = big.mark),
|
||||
header$length <- paste(format(header$length, decimal.mark = decimal.mark, big.mark = big.mark),
|
||||
na_txt)
|
||||
header <- header[names(header) != "na_length"]
|
||||
|
||||
|
@ -38,9 +38,9 @@ $( document ).ready(function() {
|
||||
if ($(".template-article").length > 0) {
|
||||
$('#sidebar').prepend(
|
||||
'<div id="r4ds">' +
|
||||
' <a href="https://r4ds.had.co.nz/">Learn R reading this great book: R for Data Science.' +
|
||||
' <br>' +
|
||||
' <br>' +
|
||||
' <a target="_blank" href="https://r4ds.had.co.nz/">' +
|
||||
' Learn R reading this great book: R for Data Science.' +
|
||||
' <br><br>' +
|
||||
' Click to read it online - it was published for free.' +
|
||||
' <img src="../../AMR/cover_r4ds.png" height="100px">' +
|
||||
' </a> ' +
|
||||
|
@ -261,7 +261,7 @@
|
||||
<h4 class="hasAnchor">
|
||||
<a href="#whonet--ears-net" class="anchor"></a>WHONET / EARS-Net</h4>
|
||||
<p><img src="./whonet.png"></p>
|
||||
<p>We support WHONET and EARS-Net data. Exported files from WHONET can be imported into R and can be analysed easily using this package. For education purposes, we created an <a href="./reference/WHONET.html">example data set <code>WHONET</code></a> with the exact same structure and a WHONET export file. Furthermore, this package also contains a <a href="./reference/antibiotics.html">data set <code>antibiotics</code></a> with all EARS-Net antibiotic abbreviations, and knows almost all WHONET abbreviations for microorganisms. When using WHONET data as input for analysis, all input parameters will be set automatically.</p>
|
||||
<p>We support WHONET and EARS-Net data. Exported files from WHONET can be imported into R and can be analysed easily using this package. For education purposes, we created an <a href="./reference/WHONET.html">example data set <code>WHONET</code></a> with the exact same structure as a WHONET export file. Furthermore, this package also contains a <a href="./reference/antibiotics.html">data set <code>antibiotics</code></a> with all EARS-Net antibiotic abbreviations, and knows almost all WHONET abbreviations for microorganisms. When using WHONET data as input for analysis, all input parameters will be set automatically.</p>
|
||||
<p>Read our tutorial about <a href="./articles/WHONET.html">how to work with WHONET data here</a>.</p>
|
||||
</div>
|
||||
<div id="antimicrobial-reference-data" class="section level4">
|
||||
|
2
index.md
2
index.md
@ -81,7 +81,7 @@ To find out how to conduct AMR analysis, please [continue reading here to get st
|
||||
|
||||
<img src="./whonet.png">
|
||||
|
||||
We support WHONET and EARS-Net data. Exported files from WHONET can be imported into R and can be analysed easily using this package. For education purposes, we created an [example data set `WHONET`](./reference/WHONET.html) with the exact same structure and a WHONET export file. Furthermore, this package also contains a [data set `antibiotics`](./reference/antibiotics.html) with all EARS-Net antibiotic abbreviations, and knows almost all WHONET abbreviations for microorganisms. When using WHONET data as input for analysis, all input parameters will be set automatically.
|
||||
We support WHONET and EARS-Net data. Exported files from WHONET can be imported into R and can be analysed easily using this package. For education purposes, we created an [example data set `WHONET`](./reference/WHONET.html) with the exact same structure as a WHONET export file. Furthermore, this package also contains a [data set `antibiotics`](./reference/antibiotics.html) with all EARS-Net antibiotic abbreviations, and knows almost all WHONET abbreviations for microorganisms. When using WHONET data as input for analysis, all input parameters will be set automatically.
|
||||
|
||||
Read our tutorial about [how to work with WHONET data here](./articles/WHONET.html).
|
||||
|
||||
|
@ -38,9 +38,9 @@ $( document ).ready(function() {
|
||||
if ($(".template-article").length > 0) {
|
||||
$('#sidebar').prepend(
|
||||
'<div id="r4ds">' +
|
||||
' <a href="https://r4ds.had.co.nz/">Learn R reading this great book: R for Data Science.' +
|
||||
' <br>' +
|
||||
' <br>' +
|
||||
' <a target="_blank" href="https://r4ds.had.co.nz/">' +
|
||||
' Learn R reading this great book: R for Data Science.' +
|
||||
' <br><br>' +
|
||||
' Click to read it online - it was published for free.' +
|
||||
' <img src="../../AMR/cover_r4ds.png" height="100px">' +
|
||||
' </a> ' +
|
||||
|
Loading…
Reference in New Issue
Block a user