25
25
# ' @param warn if \code{TRUE}, warnings are shown (e.g. if not all #A-header
26
26
# ' fields were found)
27
27
# ' @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.
28
32
# ' @param \dots further arguments to be passed to
29
33
# ' \code{kwb.en13508.2:::getObservationRecordsFromEuLines}
30
34
# ' @return list with elements \code{header.info}, \code{inspections},
31
35
# ' \code{observations}
32
- # ' @importFrom kwb.utils catAndRun catIf isTryError .logstart .logok
36
+ # ' @importFrom kwb.utils catAndRun readLinesWithEncoding
33
37
# ' @export
34
38
# '
35
39
readEuCodedFile <- function (
@@ -41,6 +45,7 @@ readEuCodedFile <- function(
41
45
simple.algorithm = TRUE ,
42
46
warn = TRUE ,
43
47
dbg = TRUE ,
48
+ check.encoding = TRUE ,
44
49
...
45
50
)
46
51
{
@@ -54,9 +59,16 @@ readEuCodedFile <- function(
54
59
# If not explicitly given, use the encoding as given in the #A1 header
55
60
if (is.null(file.encoding )) {
56
61
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 )
57
67
}
58
68
59
- stopOnInvalidEncoding(file.encoding )
69
+ if (check.encoding ) {
70
+ stopOnInvalidEncoding(file.encoding )
71
+ }
60
72
61
73
eu_lines <- run(
62
74
sprintf(" Reading %s assuming %s encoding" , input.file , file.encoding ),
0 commit comments