You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for your time and work on the roxygen2 package. It makes developing R packages much more convenient to me.
I have a function that takes a string with a default value that contains non-breaking spaces. When I use devtools::document() and afterwards devtools::check() I get a WARNING pointing out a mismatch between my code and the help page.
A minimal function with roxygen documentation that gives the WARNING:
#' A dummy function#'#' @param str_with_nbsp A string, potentially with non-breaking spaces#'#' @return Not relevant#' @export#'myfun<-function(str_with_nbsp="x\u00a0=\u00a04") {print(str_with_nbsp)}
Here is some reproducible example that could be easily converted into a unit test for this bug:
myfun<-function(str_with_nbsp="x\u00a0=\u00a04") {print(str_with_nbsp)}
# The wrap_usage function replaces all my nbsp characters by regular charactersfun_usage<-roxygen2:::wrap_usage("myfun", identity, formals= formals(myfun))
fun_usage#> <rd> myfun(str_with_nbsp = "x = 4")# The nbsp 00a0 character was replaced by regular spaces:
grepl(pattern="\u00a0", as.character(fun_usage)) # I expected this to be TRUE#> [1] FALSE
It feels like first roxygen2 introduces: \u{A0}=\u{A0} (in args_string). Afterwards it replaces all nbsp with regular spaces. A simple solution would be change the final search and replace so instead of out <- gsub("\u{A0}", " ", out, useBytes = TRUE) it becomes out <- gsub("\u{A0}=\u{A0}", "=", out, useBytes = TRUE), so it would replace the non breaking spaces that roxygen adds, but not the ones that were present before.
However I don't know if \u{A0} and other UTF-8 characters are still problematic on some Windows locales or not... maybe with the recent changes in Windows support many of these workarounds can now be simplified...
Any help will be very much appreciated 🙏
The text was updated successfully, but these errors were encountered:
Hi,
Thanks for your time and work on the roxygen2 package. It makes developing R packages much more convenient to me.
I have a function that takes a string with a default value that contains non-breaking spaces. When I use
devtools::document()
and afterwardsdevtools::check()
I get a WARNING pointing out a mismatch between my code and the help page.A minimal function with roxygen documentation that gives the WARNING:
You can find a minimal package that includes this function, with github actions set up here: https://github.com/zeehio/testnbsp
The CRAN WARNING (not that helpful to read given that the regular space and the non-breaking space look the same...)
Here is some reproducible example that could be easily converted into a unit test for this bug:
Created on 2022-05-02 by the reprex package (v2.0.1)
After looking at the code, I have been able to see that the replacement happens here:
roxygen2/R/rd-usage.R
Line 145 in 630ab47
It feels like first roxygen2 introduces:
\u{A0}=\u{A0}
(inargs_string
). Afterwards it replaces all nbsp with regular spaces. A simple solution would be change the final search and replace so instead ofout <- gsub("\u{A0}", " ", out, useBytes = TRUE)
it becomesout <- gsub("\u{A0}=\u{A0}", "=", out, useBytes = TRUE)
, so it would replace the non breaking spaces that roxygen adds, but not the ones that were present before.However I don't know if
\u{A0}
and other UTF-8 characters are still problematic on some Windows locales or not... maybe with the recent changes in Windows support many of these workarounds can now be simplified...Any help will be very much appreciated 🙏
The text was updated successfully, but these errors were encountered: