Skip to content

Commit 198bef1

Browse files
committed
Replace encoding iso-8859-1:1998 with latin1
and add argument "check.encoding"
1 parent a5df320 commit 198bef1

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

NAMESPACE

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ export(readEuCodedFile)
1111
export(readEuCodedFiles)
1212
export(writeEuCodedFile)
1313
export(writeEuCodedFiles)
14-
importFrom(kwb.utils,.logok)
15-
importFrom(kwb.utils,.logstart)
1614
importFrom(kwb.utils,catAndRun)
1715
importFrom(kwb.utils,catIf)
1816
importFrom(kwb.utils,isTryError)
1917
importFrom(kwb.utils,orderBy)
18+
importFrom(kwb.utils,readLinesWithEncoding)
2019
importFrom(kwb.utils,selectColumns)
2120
importFrom(kwb.utils,setColumns)
2221
importFrom(kwb.utils,stopFormatted)

R/readEuCodedFile.R

+14-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525
#' @param warn if \code{TRUE}, warnings are shown (e.g. if not all #A-header
2626
#' fields were found)
2727
#' @param dbg if \code{TRUE}, debug messages are shown, else not
28+
#' @param check.encoding logical indicating whether or not to check if the
29+
#' encoding string that is given in the \code{#A1} header of the file is
30+
#' "known". The default is \code{TRUE}, i.e. the check is performed and an
31+
#' error is thrown if the encoding is not in the list of known encodings.
2832
#' @param \dots further arguments to be passed to
2933
#' \code{kwb.en13508.2:::getObservationRecordsFromEuLines}
3034
#' @return list with elements \code{header.info}, \code{inspections},
3135
#' \code{observations}
32-
#' @importFrom kwb.utils catAndRun catIf isTryError .logstart .logok
36+
#' @importFrom kwb.utils catAndRun readLinesWithEncoding
3337
#' @export
3438
#'
3539
readEuCodedFile <- function(
@@ -41,6 +45,7 @@ readEuCodedFile <- function(
4145
simple.algorithm = TRUE,
4246
warn = TRUE,
4347
dbg = TRUE,
48+
check.encoding = TRUE,
4449
...
4550
)
4651
{
@@ -54,9 +59,16 @@ readEuCodedFile <- function(
5459
# If not explicitly given, use the encoding as given in the #A1 header
5560
if (is.null(file.encoding)) {
5661
file.encoding <- readFileEncodingFromHeader(input.file)
62+
63+
# Replace "iso-8859-1:1998" with "latin1"
64+
# (see https://de.wikipedia.org/wiki/ISO_8859-1:
65+
# "ISO 8859-1, genauer ISO/IEC 8859-1, auch bekannt als Latin-1 [...]")
66+
file.encoding <- gsub("^iso-8859-1:1998$", "latin1", file.encoding)
5767
}
5868

59-
stopOnInvalidEncoding(file.encoding)
69+
if (check.encoding) {
70+
stopOnInvalidEncoding(file.encoding)
71+
}
6072

6173
eu_lines <- run(
6274
sprintf("Reading %s assuming %s encoding", input.file, file.encoding),

man/readEuCodedFile.Rd

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)