From cde65141d9b00ae5e64802ba1b3674ecf0283541 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Tue, 14 Apr 2020 15:10:09 +0200 Subject: [PATCH] (v1.0.1.9007) small bugfix --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/mo.R | 44 +++++++++++++++++---------------------- docs/404.html | 2 +- docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/authors.html | 2 +- docs/index.html | 2 +- docs/news/index.html | 8 +++---- docs/pkgdown.yml | 2 +- docs/reference/index.html | 2 +- 11 files changed, 32 insertions(+), 38 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f6907376..c41aa3a3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.0.1.9006 +Version: 1.0.1.9007 Date: 2020-04-14 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index fff8a90e..b6485ec5 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.0.1.9006 +# AMR 1.0.1.9007 ## Last updated: 14-Apr-2020 ### New diff --git a/R/mo.R b/R/mo.R index aa4e5da4..5d5b8309 100755 --- a/R/mo.R +++ b/R/mo.R @@ -178,7 +178,7 @@ as.mo <- function(x, check_dataset_integrity() # start off with replaced language-specific non-ASCII characters with ASCII characters - x <- parse_encoding(x) + x <- parse_and_convert(x) # WHONET: xxx = no growth x[tolower(as.character(paste0(x, ""))) %in% c("", "xxx", "na", "nan")] <- NA_character_ @@ -263,7 +263,7 @@ exec_as.mo <- function(x, check_dataset_integrity() # start off with replaced language-specific non-ASCII characters with ASCII characters - x <- parse_encoding(x) + x <- parse_and_convert(x) # WHONET: xxx = no growth x[tolower(as.character(paste0(x, ""))) %in% c("", "xxx", "na", "nan")] <- NA_character_ @@ -277,27 +277,7 @@ exec_as.mo <- function(x, options(mo_renamed = NULL) } options(mo_renamed_last_run = NULL) - - if (NCOL(x) == 2) { - # support tidyverse selection like: df %>% select(colA, colB) - # paste these columns together - x_vector <- vector("character", NROW(x)) - for (i in seq_len(NROW(x))) { - x_vector[i] <- paste(pull(x[i, ], 1), pull(x[i, ], 2), sep = " ") - } - x <- x_vector - } else { - if (NCOL(x) > 2) { - stop("`x` can be 2 columns at most", call. = FALSE) - } - x[is.null(x)] <- NA - - # support tidyverse selection like: df %>% select(colA) - if (!is.vector(x) & !is.null(dim(x))) { - x <- pull(x, 1) - } - } - + uncertainties <- data.frame(uncertainty = integer(0), input = character(0), fullname = character(0), @@ -1977,9 +1957,23 @@ trimws2 <- function(x) { trimws(gsub("[\\s]+", " ", x, perl = TRUE)) } -parse_encoding <- function(x) { +parse_and_convert <- function(x) { tryCatch({ - x <- unname(unlist(x)) + if (!is.null(dim(x))) { + if (NCOL(x) > 2) { + stop("A maximum of two columns is allowed.", call. = FALSE) + } else if (NCOL(x) == 2) { + # support tidyverse selection like: df %>% select(colA, colB) + # paste these columns together + x <- as.data.frame(x, stringsAsFactors = FALSE) + colnames(x) <- c("A", "B") + x <- paste(x$A, x$B) + } else { + # support tidyverse selection like: df %>% select(colA) + x <- as.data.frame(x, stringsAsFactors = FALSE)[[1]] + } + } + x[is.null(x)] <- NA parsed <- iconv(x, to = "UTF-8") parsed[is.na(parsed) & !is.na(x)] <- iconv(x[is.na(parsed) & !is.na(x)], from = "Latin1", to = "ASCII//TRANSLIT") parsed <- gsub('"', "", parsed, fixed = TRUE) diff --git a/docs/404.html b/docs/404.html index b9d1eaa7..3bfb6237 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.0.1.9006 + 1.0.1.9007 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 90da6705..1f15ad97 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.0.1.9006 + 1.0.1.9007 diff --git a/docs/articles/index.html b/docs/articles/index.html index 14cfd114..935c9470 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.0.1.9006 + 1.0.1.9007 diff --git a/docs/authors.html b/docs/authors.html index e29d84c5..62529f71 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.0.1.9006 + 1.0.1.9007 diff --git a/docs/index.html b/docs/index.html index 37d62515..7afd4af8 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.0.1.9006 + 1.0.1.9007 diff --git a/docs/news/index.html b/docs/news/index.html index bef2b431..e11fde5d 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.0.1.9006 + 1.0.1.9007 @@ -229,9 +229,9 @@ Source: NEWS.md -
-

-AMR 1.0.1.9006 Unreleased +
+

+AMR 1.0.1.9007 Unreleased

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 5657e8c3..35e234aa 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -10,7 +10,7 @@ articles: WHONET: WHONET.html benchmarks: benchmarks.html resistance_predict: resistance_predict.html -last_built: 2020-04-14T12:12Z +last_built: 2020-04-14T12:56Z urls: reference: https://msberends.gitlab.io/AMR/reference article: https://msberends.gitlab.io/AMR/articles diff --git a/docs/reference/index.html b/docs/reference/index.html index 3e57e9e9..0ad0d241 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.0.1.9006 + 1.0.1.9007