@@ -7,35 +7,33 @@ extractObservationData_1 <- function(
7
7
# header.info <- kwb.en13508.2::euCodedFileHeader()
8
8
9
9
# Create accessor function to header info fields
10
- header_field <- kwb.utils :: createAccessor(header.info )
10
+ fromHeader <- kwb.utils :: createAccessor(header.info )
11
11
12
12
# Get information on the row numbers where the different blocks start
13
13
indices <- getBlockIndices(eu_lines , dbg = dbg )
14
14
15
15
# Column separator
16
- sep <- header_field (" separator" )
16
+ sep <- fromHeader (" separator" )
17
17
18
18
# Try to get the C-Block captions (if they are unique, otherwise rais error!)
19
19
captions <- tryToGetUniqueCaptions(eu_lines [indices $ C ], sep )
20
20
21
+ tableHeader <- paste(captions , collapse = sep )
22
+ rowsToRemove <- c(indices $ A , indices $ B , indices $ B + 1L , indices $ C , indices $ Z )
23
+ tableBody <- eu_lines [- rowsToRemove ]
24
+
21
25
# Try to find the column types for the given captions
22
26
colClasses <- getColClasses(codes = inspectionDataFieldCodes(), captions )
23
27
24
28
observations <- readObservationsFromCsvText(
25
- text = eu_lines [ - c( indices $ A , indices $ B , indices $ B + 1L , indices $ C , indices $ Z )] ,
29
+ text = c( tableHeader , tableBody ) ,
26
30
sep = sep ,
27
- dec = header_field(" decimal" ),
28
- quote = header_field(" quote" ),
29
- colClasses = unname(colClasses )
31
+ dec = fromHeader(" decimal" ),
32
+ quote = fromHeader(" quote" ),
33
+ colClasses = colClasses ,
34
+ header = TRUE
30
35
)
31
-
32
- # Set the column names to the captions
33
- names(observations ) <- if (identical(colClasses , NA )) {
34
- captions
35
- } else {
36
- captions [! sapply(colClasses , is.null )]
37
- }
38
-
36
+
39
37
indices $ B01 <- indices $ B [grep(" ^#B01=" , eu_lines [indices $ B ])]
40
38
41
39
# Try to generate a vector of inspection numbers assigning to each observation
@@ -143,7 +141,7 @@ getColClasses2 <- function(codes, as.text)
143
141
readObservationsFromCsvText <- function (text , sep , dec , quote , colClasses , ... )
144
142
{
145
143
# If colClasses is specified, reduce it to the columns that actually occur
146
- if (! identical(colClasses , NA )) {
144
+ if (! identical(colClasses , NA )) {
147
145
148
146
# Get the column names from the first line
149
147
colNames <- strsplit(text [1L ], sep )[[1L ]]
0 commit comments