From 3fa67f7b807d020fb4d8ba849f29bf3487b7f909 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Sun, 30 Oct 2022 08:21:56 +0100 Subject: [PATCH] v1.5.4 --- .Rbuildignore | 1 + CRAN-SUBMISSION | 3 +++ DESCRIPTION | 6 +++--- NEWS.md | 15 +++++++++++++-- R/currency.R | 31 ++++++++++++++++--------------- R/zzz.R | 8 ++++++++ README.md | 2 +- inst/symbols.txt | 7 +++++++ tests/testthat/test-currency.R | 1 + 9 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 CRAN-SUBMISSION create mode 100644 inst/symbols.txt diff --git a/.Rbuildignore b/.Rbuildignore index a5af489..c1f53d3 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,3 +8,4 @@ ^cran-comments\.md$ ^lintr\.R$ ^.github$ +^CRAN-SUBMISSION$ diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION new file mode 100644 index 0000000..78d2a85 --- /dev/null +++ b/CRAN-SUBMISSION @@ -0,0 +1,3 @@ +Version: 1.5.4 +Date: 2022-10-28 13:00:25 UTC +SHA: 8b6f7806f6cad942907166ec76ea256667f1e23f diff --git a/DESCRIPTION b/DESCRIPTION index 41bee9c..ba21650 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: cleaner Title: Fast and Easy Data Cleaning -Version: 1.5.3.9003 -Date: 2022-10-24 +Version: 1.5.4 +Date: 2022-10-28 Authors@R: person( given = c("Matthijs", "S."), @@ -27,7 +27,7 @@ Suggests: ggplot2, rmarkdown, testthat (>= 1.0.2) -URL: https://github.com/msberends/cleaner +URL: https://msberends.github.io/cleaner/, https://github.com/msberends/cleaner BugReports: https://github.com/msberends/cleaner/issues License: GPL-2 Encoding: UTF-8 diff --git a/NEWS.md b/NEWS.md index f0147ab..6800b3a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,10 @@ -# cleaner 1.5.3.9xxx +# cleaner 1.5.4 -* Fix for `digits` in `format()` * For `clean_Date()` and `clean_POSIXct()`: allow argument `max_date` to be the same length as `x` +* Fix for `digits` in `format()` +* Fix for currency symbols +* Fix CRAN check error + # cleaner 1.5.3 @@ -23,6 +26,7 @@ * `freq()` now contains a `wt` argument to set the weights. The default (`NULL`) yields the old behaviour. * Fixed a bug in `clean_POSIXct()` that led to the warning `Incompatible methods ("Ops.POSIXt", "Ops.Date") for ">"` + # cleaner 1.5.1 * New function `format_p_value()` to format raw p values according to the APA guideline @@ -34,6 +38,7 @@ * Currency now prints and formats without symbols as default, use `as_symbol = TRUE` to print/format with currency symbols * Support for older versions of R (v3.2) + # cleaner 1.5.0 * New function `format_names()` to quickly and easily change names of `data.frame` columns, `list`s or `character` vectors. @@ -66,6 +71,7 @@ ``` * Support for the upcoming R 4.1.0 + # cleaner 1.4.0 * New function `rdate()` to generate random dates (in analogy to e.g. `runif()`) @@ -100,11 +106,13 @@ ``` * Cleaned all code using the `lintr` package + # cleaner 1.3.1 * Fixed a bug when using a `percentage` class into the `percentage()` function, i.e. `percentage(as.percentage(1))` would fail * Fixed extremely small percentages, like `as.percentage(2.5e-14)` + # cleaner 1.3.0 * Added functions `clean_double()` and `clean_integer()` @@ -112,6 +120,7 @@ * Fixed a bug where `NA` in percentages would not be formatted correctly * Fixed a bug in frequency tables where sometimes the number of digits used for percentages would be astronomical + # cleaner 1.2.0 * **DUE TO CRAN POLICY: RENAMED TO PACKAGE TO `cleaner`** @@ -121,6 +130,7 @@ * Fix for `clean_character()` on R v3.5 and lower * Fix for digits in frequency tables for numeric values + # clean 1.1.0 * Added support for currency as a new class: `as.currency()` and `clean_currency()`. They also come with 'S3 methods' for `print`, `format`, `sum`, `min` and `max`. @@ -132,6 +142,7 @@ * `clean_numeric()` now supports currency * Fix for `freq()` where the precentage of NAs in the header was not calculated right + # clean 1.0.0 * First release diff --git a/R/currency.R b/R/currency.R index a6a02b7..6577bbd 100644 --- a/R/currency.R +++ b/R/currency.R @@ -96,21 +96,22 @@ c.currency <- function(x, ...) { } txt2symb <- function(txt) { - switch(txt, - "USD" = "\u0024", - "EUR" = "\u20ac", - "JPY" = "\u00a5", - "GBP" = "\u00a3", - txt) -} - -symb2txt <- function(txt) { - switch(txt, - "\u0024" = "USD", - "\u20ac" = "EUR", - "\u00a5" = "JPY", - "\u00a3" = "GBP", - txt) + txt <- toupper(txt) + sym <- unname(pkg_env$symbols[which(names(pkg_env$symbols) == txt)]) + if (length(sym) == 0) { + txt + } else { + sym + } +} + +symb2txt <- function(sym) { + txt <- unname(names(pkg_env$symbols)[which(pkg_env$symbols == sym)]) + if (length(txt) == 0) { + sym + } else { + txt + } } #' @rdname currency diff --git a/R/zzz.R b/R/zzz.R index b17660d..bc1e1ec 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -17,6 +17,14 @@ # useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. # # ==================================================================== # +pkg_env <- new.env(hash = FALSE) .onLoad <- function(libname, pkgname) { backports::import(pkgname) + # read symbols from external file to prevent CRAN errors + symbols <- tryCatch(utils::read.delim(system.file("symbols.txt", package = "cleaner"), sep = ","), error = function(e) NULL) + if (!is.null(symbols)) { + pkg_env$symbols <- stats::setNames(symbols$symbol, symbols$txt) + } else { + pkg_env$symbols <- character(0) + } } diff --git a/README.md b/README.md index a85a79f..e80ef7e 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Contents: ---- ## Why this package -As a data scientist, I'm often served with data that is not clean, not tidy and consequently not ready for analysis at all. For tidying data, there's of course the `tidyverse` (https://www.tidyverse.org), which lets you manipulate data in any way you can think of. But for *cleaning*, I think our community was still lacking a neat solution that makes data cleaning fast and easy with functions that kind of 'think on their own' to do that. +You are probably often served with data that is not clean, not tidy and consequently not ready for analysis at all. For tidying data, there's of course the `tidyverse` (https://www.tidyverse.org), which lets you manipulate data in any way you can think of. But for *cleaning*, our community might still have been lacking a neat solution that makes data cleaning fast and easy with functions that kind of 'think on their own' to do that. If the CRAN button at the top of this page is green, install the package with: diff --git a/inst/symbols.txt b/inst/symbols.txt new file mode 100644 index 0000000..78c5df9 --- /dev/null +++ b/inst/symbols.txt @@ -0,0 +1,7 @@ +txt,symbol +"CNY","元" +"EUR","€" +"GBP","£" +"JPY","¥" +"KRW","₩" +"USD","$" diff --git a/tests/testthat/test-currency.R b/tests/testthat/test-currency.R index 7c1e89a..b146c05 100644 --- a/tests/testthat/test-currency.R +++ b/tests/testthat/test-currency.R @@ -21,4 +21,5 @@ context("currency.R") test_that("currency works", { expect_true(is.currency(clean_currency(c("no5538", "no929", "yes2390", "no841", "no2610")))) + expect_identical(symb2txt(txt2symb("EUR")), "EUR") })