[R-pkg-devel] Unicode Name Warnings for Package Constant

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Thu Sep 2 18:18:17 CEST 2021


On 02/09/2021 11:24 a.m., bill using denney.ws wrote:
> Hello,
> 
>   
> 
> In the janitor package, we want to optionally support conversion from
> Unicode characters that visually map to mu or micro to the character "u".
> For that, we were thinking to create an unexported character vector constant
> with names of all the Unicode mu/micro characters and values of "u".  As a
> work-around, I was able to fix the issue using setNames(), but it was a
> non-intuitive fix, and I would prefer to just use create the named character
> vector directly.

I think the warning comes because on non-UTF8 platforms there are 
operations that will mess up names.  So using setNames() may fool the 
check, but it probably won't solve the problem.

On the other hand, I think all current platforms handle UTF8 data fine, 
so keeping the vector of characters as data should be fine.  Then the 
base chartr() function could do your translation for you.

To do the translation you want, you'd use something like

   original <- "45 \u00b5m"
 
chartr("\u00b5\u03bc\u3382\u338c\u338d\u3395\u339b\u33b2\u33b6\u33bc", 
"uuuuuuuuuu", original)

Duncan Murdoch


>   
> 
> Is there a good way to prevent the warnings below?
> 
>   
> 
> When running the following (on Windows 10 with R 4.1.0) either during a
> normal R session or while checking the package (via devtools::check()), we
> get several warnings:
> 
>   
> 
> mu_to_u <-
> 
>    c(
> 
>      "\u00b5"="u", "\u03bc"="u", "\u3382"="u", "\u338c"="u", "\u338d"="u",
> 
>      "\u3395"="u", "\u339b"="u", "\u33b2"="u", "\u33b6"="u", "\u33bc"="u"
> 
>    )
> 
>   
> 
>    Warnings in file 'R/clean_names.R':
> 
>      unable to translate '<U+3382>' to native encoding
> 
>      unable to translate '<U+338C>' to native encoding
> 
>      unable to translate '<U+338D>' to native encoding
> 
>      unable to translate '<U+3395>' to native encoding
> 
>      unable to translate '<U+339B>' to native encoding
> 
>      unable to translate '<U+33B2>' to native encoding
> 
>      unable to translate '<U+33B6>' to native encoding
> 
>      unable to translate '<U+33BC>' to native encoding
> 
>   
> 
> I tried wrapping this in suppressWarnings(), but the warnings still
> occurred.
> 
>   
> 
> Thanks,
> 
>   
> 
> Bill
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



More information about the R-package-devel mailing list