Skip to content
Snippets Groups Projects
Commit 363c34b8 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Modify mortalityTables.load to force UTF-8 for all input files

-) sys.source on Windows uses the default locale and NOT
   UTF-8, so all UTF8-strings will be broken. Instead
   explicitly use the same code (readLines with subsequent
   parse and eval calls) as sys.source, but add the UTF-8
   encoding to readLines.
parent 6adc19d2
No related branches found
No related tags found
No related merge requests found
...@@ -31,8 +31,18 @@ mortalityTables.load = function(dataset, package = c("^MortalityTables", "^Pensi ...@@ -31,8 +31,18 @@ mortalityTables.load = function(dataset, package = c("^MortalityTables", "^Pensi
if (any(sapply(package, grepl, p))) { # package matches the pattern given as argument if (any(sapply(package, grepl, p))) { # package matches the pattern given as argument
filename = system.file("extdata", paste(prefix, "_", sname, ".R", sep = ""), package = p); filename = system.file("extdata", paste(prefix, "_", sname, ".R", sep = ""), package = p);
if (filename != "") { if (filename != "") {
require(p, character.only = TRUE) # Make sure the providing package is loaded, in case it provides helper functions # Make sure the providing package is loaded, in case it provides helper functions
sys.source(filename, envir = globalenv()) require(p, character.only = TRUE)
# Taken from the definition of sys.source and adjusted to include the
# encoding (required for Windows, otherwise UTF8-strings will be broken!)
lines = readLines(filename, encoding = "UTF-8", warn = FALSE)
srcfile = srcfilecopy(filename, lines, file.mtime(filename), isFile = TRUE)
exprs = parse(text = lines, srcfile = srcfile, keep.source = TRUE)
for (i in seq_along(exprs))
eval(exprs[i], envir = globalenv())
# sys.source(filename, envir = globalenv())
loaded = TRUE loaded = TRUE
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment