1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-09 04:02:19 +02:00

support for French and Italian, added quote to freq

This commit is contained in:
2018-09-10 15:45:25 +02:00
parent b83e6a9380
commit cb0d74a4f0
9 changed files with 81 additions and 18 deletions

View File

@ -27,6 +27,7 @@
#' @param row.names a logical value indicating whether row indices should be printed as \code{1:nrow(x)}
#' @param markdown print table in markdown format (this forces \code{nmax = NA})
#' @param digits how many significant digits are to be used for numeric values in the header (not for the items themselves, that depends on \code{\link{getOption}("digits")})
#' @param quote a logical value indicating whether or not strings should be printed with surrounding quotes
#' @param sep a character string to separate the terms when selecting multiple columns
#' @param f a frequency table
#' @param n number of top \emph{n} items to return, use -n for the bottom \emph{n} items. It will include more than \code{n} rows if there are ties.
@ -148,6 +149,7 @@ frequency_tbl <- function(x,
row.names = TRUE,
markdown = FALSE,
digits = 2,
quote = FALSE,
sep = " ") {
mult.columns <- 0
@ -429,6 +431,10 @@ frequency_tbl <- function(x,
}
}
if (quote == TRUE) {
df$item <- paste0('"', df$item, '"')
}
df <- as.data.frame(df, stringsAsFactors = FALSE)
df$percent <- df$count / base::sum(df$count, na.rm = TRUE)

2
R/mo.R
View File

@ -127,7 +127,7 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE) {
x_backup <- x
# translate to English for supported languages of mo_property
x <- gsub("(Gruppe|gruppe|groep|grupo)", "group", x)
x <- gsub("(Gruppe|gruppe|groep|grupo|gruppo|groupe)", "group", x)
# remove 'empty' genus and species values
x <- gsub("(no MO)", "", x, fixed = TRUE)
# remove dots and other non-text in case of "E. coli" except spaces

View File

@ -214,9 +214,9 @@ mo_translate <- function(x, language) {
return(x)
}
supported <- c("en", "de", "nl", "es", "pt")
supported <- c("en", "de", "nl", "es", "pt", "it", "fr")
if (!language %in% supported) {
stop("Unsupported language: '", language, "' - use one of ", paste0("'", sort(supported), "'", collapse = ", "), call. = FALSE)
stop("Unsupported language: '", language, "' - use one of: ", paste0("'", sort(supported), "'", collapse = ", "), call. = FALSE)
}
case_when(
@ -302,7 +302,50 @@ mo_translate <- function(x, language) {
gsub("biotype", "bi\u00f3tipo", ., fixed = TRUE) %>%
gsub("vegetative", "vegetativo", ., fixed = TRUE) %>%
gsub("([([ ]*?)group", "\\1grupo", .) %>%
gsub("([([ ]*?)Group", "\\1Grupo", .)
gsub("([([ ]*?)Group", "\\1Grupo", .),
# Italian
language == "it" ~ x %>%
gsub("Coagulase Negative Staphylococcus","Staphylococcus negativo coagulasi", ., fixed = TRUE) %>%
gsub("Coagulase Positive Staphylococcus","Staphylococcus positivo coagulasi", ., fixed = TRUE) %>%
gsub("Beta-haemolytic Streptococcus", "Streptococcus Beta-emolitico", ., fixed = TRUE) %>%
gsub("(no MO)", "(non MO)", ., fixed = TRUE) %>%
gsub("Negative rods", "Bastoncini Gram-negativi", ., fixed = TRUE) %>%
gsub("Negative cocci", "Cocchi Gram-negativi", ., fixed = TRUE) %>%
gsub("Positive rods", "Bastoncini Gram-positivi", ., fixed = TRUE) %>%
gsub("Positive cocci", "Cocchi Gram-positivi", ., fixed = TRUE) %>%
gsub("Parasites", "Parassiti", ., fixed = TRUE) %>%
gsub("Fungi and yeasts", "Funghi e lieviti", ., fixed = TRUE) %>%
gsub("Bacteria", "Batterio", ., fixed = TRUE) %>%
gsub("Fungus/yeast", "Fungo/lievito", ., fixed = TRUE) %>%
gsub("Parasite", "Parassita", ., fixed = TRUE) %>%
gsub("biogroup", "biogruppo", ., fixed = TRUE) %>%
gsub("biotype", "biotipo", ., fixed = TRUE) %>%
gsub("vegetative", "vegetativo", ., fixed = TRUE) %>%
gsub("([([ ]*?)group", "\\1gruppo", .) %>%
gsub("([([ ]*?)Group", "\\1Gruppo", .),
# French
language == "fr" ~ x %>%
gsub("Coagulase Negative Staphylococcus","Staphylococcus \u00e0 coagulase n\u00e9gative", ., fixed = TRUE) %>%
gsub("Coagulase Positive Staphylococcus","Staphylococcus \u00e0 coagulase positif", ., fixed = TRUE) %>%
gsub("Beta-haemolytic Streptococcus", "Streptococcus B\u00eata-h\u00e9molytique", ., fixed = TRUE) %>%
gsub("(no MO)", "(pas MO)", ., fixed = TRUE) %>%
gsub("Negative rods", "Bacilles n\u00e9gatif", ., fixed = TRUE) %>%
gsub("Negative cocci", "Cocci n\u00e9gatif", ., fixed = TRUE) %>%
gsub("Positive rods", "Bacilles positif", ., fixed = TRUE) %>%
gsub("Positive cocci", "Cocci positif", ., fixed = TRUE) %>%
# gsub("Parasites", "Parasites", ., fixed = TRUE) %>%
gsub("Fungi and yeasts", "Champignons et levures", ., fixed = TRUE) %>%
gsub("Bacteria", "Bact\u00e9rie", ., fixed = TRUE) %>%
gsub("Fungus/yeast", "Champignon/levure", ., fixed = TRUE) %>%
# gsub("Parasite", "Parasite", ., fixed = TRUE) %>%
gsub("biogroup", "biogroupe", ., fixed = TRUE) %>%
# gsub("biotype", "biotype", ., fixed = TRUE) %>%
gsub("vegetative", "v\u00e9g\u00e9tatif", ., fixed = TRUE) %>%
gsub("([([ ]*?)group", "\\1groupe", .) %>%
gsub("([([ ]*?)Group", "\\1Groupe", .)
)
}
@ -314,7 +357,9 @@ mo_getlangcode <- function() {
sys %like% '(Deutsch|German|de_)' ~ "de",
sys %like% '(Nederlands|Dutch|nl_)' ~ "nl",
sys %like% '(Espa.ol|Spanish|es_)' ~ "es",
sys %like% '(Fran.ais|French|fr_)' ~ "fr",
sys %like% '(Portugu.s|Portuguese|pt_)' ~ "pt",
sys %like% '(Italiano|Italian|it_)' ~ "it",
TRUE ~ "en"
)
}