I recently implemented a function to escape characters interpretable as regex that go into a system call for my R package 'rNOMADS'
SanitizeWGrib2Inputs <- function(check.strs) {
#Escape regex characters before inputting to wgrib2
#INPUTS
# CHECK.STRS - Strings possibly containing regex metacharacters
#OUTPUTS
# CHECKED.STRS - Strings with metacharacters appropriately escaped
meta.chars <- paste0("\\", c("(", ")", ".", "+", "*", "^", "$", "?", "[", "]", "|"))
for(k in 1:length(meta.chars)) {
check.strs <- stringr::str_replace(check.strs, meta.chars[k], paste0("\\\\", meta.chars[k]))
}
checked.strs <- check.strs
return(checked.strs)
}
and I include an example in my package documentation:
check.strs <- c("frank", "je.rry", "har\\old", "Johnny Ca$h")
checked.strs <- SanitizeWGrib2Inputs(check.strs)
This works fine on my ubuntu machine and passed the CRAN checks. However, when I uploaded the package to CRAN, their windows checker said:
> check.strs <- c("frank", "je.rry", "har\\old", "Johnny Ca$h")
> checked.strs <- SanitizeWGrib2Inputs(check.strs) Error in stri_replace_first_regex(string, pattern, fix_replacement(replacement), : Invalid capture group name. (U_REGEX_INVALID_CAPTURE_GROUP_NAME) Calls: SanitizeWGrib2Inputs -> <Anonymous> -> stri_replace_first_regex -> .Call Execution halted
** running examples for arch 'x64' ... ERROR Running examples in 'rNOMADS-Ex.R' failed The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: SanitizeWGrib2Inputs
> ### Title: Make sure regex metacharacters are properly escaped
> ### Aliases: SanitizeWGrib2Inputs
> ### Keywords: internal
>
> ### ** Examples
>
>
> check.strs <- c("frank", "je.rry", "har\\old", "Johnny Ca$h")
> checked.strs <- SanitizeWGrib2Inputs(check.strs) Error in stri_replace_first_regex(string, pattern, fix_replacement(replacement), : Invalid capture group name. (U_REGEX_INVALID_CAPTURE_GROUP_NAME) Calls: SanitizeWGrib2Inputs -> <Anonymous> -> stri_replace_first_regex -> .Call Execution halted
I verified this behavior on my Windows partition. What is the work around for this?