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
|
Package: AMR
|
||||||
Version: 0.5.0.9017
|
Version: 0.5.0.9017
|
||||||
Date: 2019-02-12
|
Date: 2019-02-13
|
||||||
Title: Antimicrobial Resistance Analysis
|
Title: Antimicrobial Resistance Analysis
|
||||||
Authors@R: c(
|
Authors@R: c(
|
||||||
person(
|
person(
|
||||||
|
38
R/freq.R
38
R/freq.R
@ -352,6 +352,14 @@ frequency_tbl <- function(x,
|
|||||||
NAs <- x[is.na(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) {
|
if (na.rm == TRUE) {
|
||||||
x_class <- class(x)
|
x_class <- class(x)
|
||||||
x <- x[!x %in% NAs]
|
x <- x[!x %in% NAs]
|
||||||
@ -364,13 +372,6 @@ frequency_tbl <- function(x,
|
|||||||
}
|
}
|
||||||
x_align <- "l"
|
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))) {
|
if (!is.null(levels(x))) {
|
||||||
header_list$levels <- levels(x)
|
header_list$levels <- levels(x)
|
||||||
header_list$ordered <- is.ordered(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$na_length <- length(NAs)
|
||||||
header_list$unique <- n_distinct(x)
|
header_list$unique <- n_distinct(x)
|
||||||
|
|
||||||
@ -559,7 +559,7 @@ format_header <- function(x, markdown = FALSE, decimal.mark = ".", big.mark = ",
|
|||||||
|
|
||||||
header <- header(x)
|
header <- header(x)
|
||||||
x_class <- header$class
|
x_class <- header$class
|
||||||
has_length <- header$length + header$na_length > 0
|
has_length <- header$length > 0
|
||||||
|
|
||||||
# FORMATTING
|
# FORMATTING
|
||||||
# rsi
|
# rsi
|
||||||
@ -633,23 +633,25 @@ format_header <- function(x, markdown = FALSE, decimal.mark = ".", big.mark = ",
|
|||||||
}
|
}
|
||||||
# levels
|
# levels
|
||||||
if (!is.null(header$levels)) {
|
if (!is.null(header$levels)) {
|
||||||
n_levels <- header$levels %>% length()
|
if (markdown == TRUE) {
|
||||||
n_levels_list <- header$levels
|
header$levels <- paste0("`", header$levels, "`")
|
||||||
if (n_levels > 5) {
|
|
||||||
n_levels_list <- c(n_levels_list[1:5], "...")
|
|
||||||
}
|
}
|
||||||
if (header$ordered == TRUE) {
|
if (header$ordered == TRUE) {
|
||||||
n_levels_list <- paste0(n_levels_list, collapse = " < ")
|
levels_text <- paste0(header$levels, collapse = " < ")
|
||||||
} else {
|
} 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"]
|
header <- header[names(header) != "ordered"]
|
||||||
}
|
}
|
||||||
# length and NAs
|
# length and NAs
|
||||||
if (has_length == TRUE) {
|
if (has_length == TRUE) {
|
||||||
na_txt <- paste0(header$na_length %>% format(decimal.mark = decimal.mark, big.mark = big.mark), " = ",
|
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))
|
sub("NaN", "0", ., fixed = TRUE))
|
||||||
if (!na_txt %like% "^0 =") {
|
if (!na_txt %like% "^0 =") {
|
||||||
na_txt <- red(na_txt)
|
na_txt <- red(na_txt)
|
||||||
@ -660,7 +662,7 @@ format_header <- function(x, markdown = FALSE, decimal.mark = ".", big.mark = ",
|
|||||||
} else {
|
} else {
|
||||||
na_txt <- ""
|
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)
|
na_txt)
|
||||||
header <- header[names(header) != "na_length"]
|
header <- header[names(header) != "na_length"]
|
||||||
|
|
||||||
|
@ -38,9 +38,9 @@ $( document ).ready(function() {
|
|||||||
if ($(".template-article").length > 0) {
|
if ($(".template-article").length > 0) {
|
||||||
$('#sidebar').prepend(
|
$('#sidebar').prepend(
|
||||||
'<div id="r4ds">' +
|
'<div id="r4ds">' +
|
||||||
' <a href="https://r4ds.had.co.nz/">Learn R reading this great book: R for Data Science.' +
|
' <a target="_blank" href="https://r4ds.had.co.nz/">' +
|
||||||
' <br>' +
|
' Learn R reading this great book: R for Data Science.' +
|
||||||
' <br>' +
|
' <br><br>' +
|
||||||
' Click to read it online - it was published for free.' +
|
' Click to read it online - it was published for free.' +
|
||||||
' <img src="../../AMR/cover_r4ds.png" height="100px">' +
|
' <img src="../../AMR/cover_r4ds.png" height="100px">' +
|
||||||
' </a> ' +
|
' </a> ' +
|
||||||
|
@ -261,7 +261,7 @@
|
|||||||
<h4 class="hasAnchor">
|
<h4 class="hasAnchor">
|
||||||
<a href="#whonet--ears-net" class="anchor"></a>WHONET / EARS-Net</h4>
|
<a href="#whonet--ears-net" class="anchor"></a>WHONET / EARS-Net</h4>
|
||||||
<p><img src="./whonet.png"></p>
|
<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>
|
<p>Read our tutorial about <a href="./articles/WHONET.html">how to work with WHONET data here</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
<div id="antimicrobial-reference-data" class="section level4">
|
<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">
|
<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).
|
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) {
|
if ($(".template-article").length > 0) {
|
||||||
$('#sidebar').prepend(
|
$('#sidebar').prepend(
|
||||||
'<div id="r4ds">' +
|
'<div id="r4ds">' +
|
||||||
' <a href="https://r4ds.had.co.nz/">Learn R reading this great book: R for Data Science.' +
|
' <a target="_blank" href="https://r4ds.had.co.nz/">' +
|
||||||
' <br>' +
|
' Learn R reading this great book: R for Data Science.' +
|
||||||
' <br>' +
|
' <br><br>' +
|
||||||
' Click to read it online - it was published for free.' +
|
' Click to read it online - it was published for free.' +
|
||||||
' <img src="../../AMR/cover_r4ds.png" height="100px">' +
|
' <img src="../../AMR/cover_r4ds.png" height="100px">' +
|
||||||
' </a> ' +
|
' </a> ' +
|
||||||
|
Loading…
Reference in New Issue
Block a user