с file_helper.R
как:
library(stringr)
cleanStringFunctionSourced <- function(string) {
result <- stringr::str_replace_all(string, c("ü" = "ue", "ï" = "ie", "ë" = "ee", "ä" = "ae", "ö" = "oe", "ß" = "ss"))
return(paste0("with function from file_helper.R : ", result))
}
с test.R
как:
library(stringr)
source("file_helper.R")
test_string <- "ü,ï,ë,ä,ö,ß"
cleanStringFunctionLocal <- function(string) {
result <- stringr::str_replace_all(string, c("ü" = "ue", "ï" = "ie", "ë" = "ee", "ä" = "ae", "ö" = "oe", "ß" = "ss"))
return(paste0("with same file function : ", result))
}
print(paste0("original string :", test_string))
#> [1] "original string :ü,ï,ë,ä,ö,ß"
print(cleanStringFunctionLocal(test_string))
#> [1] "with same file function : ue,ie,ee,ae,oe,ss"
print(cleanStringFunctionSourced(test_string))
#> [1] "with function from file_helper.R : ü,ï,ë,ä,ö,ß"
#> R version 3.6.3 (2020-02-29)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 18362)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
#> [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
#> [5] LC_TIME=German_Germany.1252
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> loaded via a namespace (and not attached):
#> [1] compiler_3.6.3 magrittr_1.5 tools_3.6.3 htmltools_0.4.0
#> [5] yaml_2.2.1 Rcpp_1.0.3 stringi_1.4.6 rmarkdown_2.1
#> [9] highr_0.8 knitr_1.28 stringr_1.4.0 xfun_0.12
#> [13] digest_0.6.25 rlang_0.4.5 evaluate_0.14
При вызове из внешнего исходного файла stringr::str_replace_all
, похоже, не работает . Может ли кто-нибудь сказать мне, что я здесь сделал не так? Заранее большое спасибо.