Commit 363c34b8 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

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
......@@ -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
filename = system.file("extdata", paste(prefix, "_", sname, ".R", sep = ""), package = p);
if (filename != "") {
require(p, character.only = TRUE) # Make sure the providing package is loaded, in case it provides helper functions
sys.source(filename, envir = globalenv())
# Make sure the providing package is loaded, in case it provides helper functions
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
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment