brunobrr / bdc

Check out the vignettes with detailed documentation on each module of the bdc package
https://brunobrr.github.io/bdc
GNU General Public License v3.0
23 stars 7 forks source link

fix: cran encoding problem on regular check #234

Closed kguidonimartins closed 2 years ago

kguidonimartins commented 2 years ago

This change try to fix the below problem hiding the characters in a internal data file. So, the CHECK will not read it.

Last updated on 2022-08-16 22:51:02 CEST.

 Version: 1.1.1
Check: whether package can be installed
Result: WARN
    Found the following significant warnings:
     Warning: unable to re-encode 'bdc_clean_names.R' line 934
Flavor: r-devel-linux-x86_64-debian-clang

Version: 1.1.1

The proposed change was tested as below:

library(bdc)

## read our problematic encoding characters.
encod_chars <-
  readLines(system.file("extdata/encoding-chars.txt", package = "bdc"))

encod_chars
#> [1] "²\\?" "²"    "\\?"  "´"    "'"

## create a few groups for substitution.
first_group <- paste0("(", paste0(encod_chars[1:3], collapse = "|"), ")")
first_group
#> [1] "(²\\?|²|\\?)"
second_group <- paste0("(", paste0(encod_chars[4:5], collapse = "|"), ")")
second_group
#> [1] "(´|')"

## can we use the characters directly...
gsub(encod_chars[1], "", "²?") # get ²?
#> [1] ""
gsub(encod_chars[2], "", "²") # get ²
#> [1] ""
gsub(encod_chars[3], "", "?")
#> [1] ""
## or via groups with the same results.
gsub(first_group, "", "²?") # get ²?
#> [1] ""
gsub(first_group, "", "²") # get ²
#> [1] ""
gsub(first_group, "", "?")
#> [1] ""
## idem.
gsub(encod_chars[4], " ", "´") # get ´
#> [1] " "
gsub(encod_chars[5], " ", "'")
#> [1] " "
## idem.
gsub(second_group, " ", "´") # get ´
#> [1] " "
gsub(second_group, " ", "'")
#> [1] " "

Created on 2022-08-16 by the reprex package (v2.0.1)