diff --git a/NEWS.md b/NEWS.md index cf984b00..66ee0641 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,38 +1,38 @@ -## 0.2.0 +# 0.2.0 #### New -- Full support for Windows, Linux and macOS -- Function `guess_bactid` to determine the ID of a microorganism based on genus/species or known abbreviations like MRSA -- Functions `clipboard_import` and `clipboard_export` as helper functions to quickly copy and paste from/to software like Excel and SPSS -- Function `MDRO` to determine Multi Drug Resistant Organisms (MDRO) with support for country-specific guidelines. Suggest your own via https://github.com/msberends/AMR/issues/new. Functions `BRMO` and `MRGN` are wrappers for Dutch and German guidelines, respectively -- Function `freq` to create frequency tables, with additional info in a header -- New algorithm to determine weighted isolates, can now be `"points"` or `"keyantibiotics"`, see `?first_isolate` -- New print format for tibbles and data.tables +* Full support for Windows, Linux and macOS +* Function `guess_bactid` to determine the ID of a microorganism based on genus/species or known abbreviations like MRSA +* Functions `clipboard_import` and `clipboard_export` as helper functions to quickly copy and paste from/to software like Excel and SPSS +* Function `MDRO` to determine Multi Drug Resistant Organisms (MDRO) with support for country-specific guidelines. Suggest your own via [this link](https://github.com/msberends/AMR/issues/new?title=New%20guideline%20for%20MDRO&body=%3C--%20Please%20add%20your%20country%20code,%20guideline%20name,%20version%20and%20source%20below%20and%20remove%20this%20line--%3E). Functions `BRMO` and `MRGN` are wrappers for Dutch and German guidelines, respectively +* Function `freq` to create frequency tables, with additional info in a header +* New algorithm to determine weighted isolates, can now be `"points"` or `"keyantibiotics"`, see `?first_isolate` +* New print format for tibbles and data.tables #### Changed -- Support for older R versions, only R 3.1.0 and later is needed -- Renamed dataset `ablist` to `antibiotics` -- Renamed dataset `bactlist` to `microorganisms` -- Added more microorganisms to `bactlist` -- Added analysis examples on help page of dataset `septic_patients` -- Added support for character vector in `join` functions -- Added warnings when a join results in more rows after than before the join -- Altered `%like%` to make it case insensitive -- For parameters of functions `first_isolate` and `EUCAST_rules` the column names are now case-insensitive -- Functions `as.rsi` and `as.mic` now add the package name and version as attribute +* Support for older R versions, only R 3.1.0 and later is needed +* Renamed dataset `ablist` to `antibiotics` +* Renamed dataset `bactlist` to `microorganisms` +* Added more microorganisms to `bactlist` +* Added analysis examples on help page of dataset `septic_patients` +* Added support for character vector in `join` functions +* Added warnings when a join results in more rows after than before the join +* Altered `%like%` to make it case insensitive +* For parameters of functions `first_isolate` and `EUCAST_rules` the column names are now case-insensitive +* Functions `as.rsi` and `as.mic` now add the package name and version as attribute #### Other -- Expanded README.md with more examples -- Added ORC IDs of authors to DESCRIPTION file -- Added unit testing with the `testthat` package -- Added build tests for Linux and macOS using Travis CI (https://travis-ci.org/msberends/AMR) -- Added Line coverage checking using CodeCov (https://codecov.io/gh/msberends/AMR/tree/master/R) +* Expanded README.md with more examples +* Added ORC IDs of authors to DESCRIPTION file +* Added unit testing with the `testthat` package +* Added build tests for Linux and macOS using Travis CI (https://travis-ci.org/msberends/AMR) +* Added Line coverage checking using CodeCov (https://codecov.io/gh/msberends/AMR/tree/master/R) -## 0.1.1 -- `EUCAST_rules` applies for amoxicillin even if ampicillin is missing -- Edited column names to comply with GLIMS, the laboratory information system -- Added more valid MIC values -- Renamed 'Daily Defined Dose' to 'Defined Daily Dose' -- Added barplots for `rsi` and `mic` classes +# 0.1.1 +* `EUCAST_rules` applies for amoxicillin even if ampicillin is missing +* Edited column names to comply with GLIMS, the laboratory information system +* Added more valid MIC values +* Renamed 'Daily Defined Dose' to 'Defined Daily Dose' +* Added barplots for `rsi` and `mic` classes -## 0.1.0 -- First submission to CRAN. +# 0.1.0 +* First submission to CRAN. diff --git a/R/misc.R b/R/misc.R index b28f32dc..75b5f19f 100644 --- a/R/misc.R +++ b/R/misc.R @@ -112,11 +112,23 @@ size_humanreadable <- function(bytes, decimals = 1) { out } + +# Support for older R versions -------------------------------------------- + # strrep is only available in R 3.3 and later -# and we want to support R 3.2 too, so: strrep <- function(x, times) { for (i in 1:length(x)) { x[i] <- paste(rep(x[i], times[i]), collapse = "") } x } +# trimws is only available in R 3.2 and later +trimws <- function(x, which = "both") { + if (which %in% c("left", "both", "l", "b")) { + x <- gsub('^ {1,255}', '', x) + } + if (which %in% c("right", "both", "r", "b")) { + x <- gsub(' {1,255}$', '', x) + } + x +} diff --git a/README.md b/README.md index 91125054..205f5fec 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ This R package contains functions to make microbiological, epidemiological data With AMR you can also apply EUCAST rules to isolates, identify first isolates of every patient, translate antibiotic codes from the lab (like `"AMOX"`) or the [WHO](https://www.whocc.no/atc_ddd_index/?code=J01CA04&showdescription=no) (like `"J01CA04"`) to trivial names (like `"amoxicillin"`), or predict antimicrobial resistance for the nextcoming years with the `rsi_predict` function. +With the `MDRO` function (abbreviation of mutli-drug resistant organisms), you can check your isolates for exceptional resistance with country-specific guidelines. Currently guidelines for Germany and the Netherlands are supported. Please suggest addition of your own country here: [https://github.com/msberends/AMR/issues](https://github.com/msberends/AMR/issues/new?title=New%20guideline%20for%20MDRO&body=%3C--%20Please%20add%20your%20country%20code,%20guideline%20name,%20version%20and%20source%20below%20and%20remove%20this%20line--%3E). + For regular AMR analysis, the `rsi` function can be used. This function als works with the `dplyr` package (e.g. in conjunction with `summarise`) to calculate the resistance percentages of different antibiotic columns of a table. This package contains an example data set `septic_patients`, consisting of 2000 isolates from anonymised septic patients between 2001 and 2017. diff --git a/tests/testthat/test-misc.R b/tests/testthat/test-misc.R index d526ef27..30792859 100644 --- a/tests/testthat/test-misc.R +++ b/tests/testthat/test-misc.R @@ -14,3 +14,14 @@ test_that("percentages works", { expect_equal(percent(0.1234), "12.3%") }) +test_that("size format works", { + expect_equal(size_humanreadable(123456), "121 kB") +}) + +test_that("functions missing in older R versions work", { + expect_equal(strrep("A", 5), "AAAAA") + expect_equal(strrep(c("A", "B"), c(5, 2)), c("AAAAA", "BB")) + expect_equal(trimws(" test "), "test") + expect_equal(trimws(" test ", "l"), "test ") + expect_equal(trimws(" test ", "r"), " test") +})