@@ -84,7 +84,10 @@ token_is_on_aligned_line <- function(pd_flat) {
84
84
if (any(starting_with_comma )) {
85
85
return (FALSE )
86
86
}
87
- pd_is_multi_line <- map_lgl(pd_by_line , ~ any(.x $ multi_line > 0L , na.rm = TRUE ))
87
+ pd_is_multi_line <- map_lgl(
88
+ pd_by_line ,
89
+ ~ any(.x $ multi_line > 0L , na.rm = TRUE )
90
+ )
88
91
if (any(pd_is_multi_line )) {
89
92
return (FALSE )
90
93
}
@@ -110,17 +113,24 @@ token_is_on_aligned_line <- function(pd_flat) {
110
113
# check 1: match by comma
111
114
# might have fewer lines in subsequent columns.
112
115
max_previous_col <- max(current_col )
113
- current_col <- nchar(by_line ) - as.integer(column > 1 ) # fir col has no leading ,
116
+
117
+ # first col has no leading ,
118
+ current_col <- nchar(by_line ) - as.integer(column > 1 )
114
119
if (column > 1 ) {
115
- previous_line <- previous_line [intersect(names(previous_line ), names(by_line ))]
120
+ previous_line <- previous_line [
121
+ intersect(names(previous_line ), names(by_line ))
122
+ ]
116
123
# must add previous columns, as first column might not align
117
124
current_col <- current_col + previous_line
118
125
}
119
126
120
127
is_aligned <- length(unique(current_col )) == 1L
121
128
if (! is_aligned || length(current_col ) < 2 ) {
122
129
# check 2: left aligned after ,
123
- current_col <- nchar(gsub(" ^(,[\\ s\\ t]*)[^ ]*.*$" , " \\ 1" , by_line , perl = TRUE )) - 1
130
+ current_col <- " ^(,[\\ s\\ t]*)[^ ]*.*$" %> %
131
+ gsub(" \\ 1" , by_line , perl = TRUE ) %> %
132
+ nchar() %> %
133
+ magrittr :: subtract(1 )
124
134
125
135
if (column > 1 ) {
126
136
# must add previous columns, as first column might not align
@@ -142,7 +152,7 @@ token_is_on_aligned_line <- function(pd_flat) {
142
152
previous_line <- current_col
143
153
next
144
154
}
145
- # check 3: match by = (no extra spaces around it allowed. )
155
+ # check 3: match by = (no extra spaces around it allowed)
146
156
# match left aligned after =
147
157
start_after_eq <- regexpr(" = [^ ]" , by_line )
148
158
names(start_after_eq ) <- names(by_line )
@@ -152,14 +162,17 @@ token_is_on_aligned_line <- function(pd_flat) {
152
162
if (length(start_after_eq ) == 0 ) {
153
163
return (FALSE )
154
164
}
155
- # when match via comma unsuccessful, matching by = must yield at least one =
165
+ # when match via , unsuccessful, matching by = must yield at least one =
156
166
if (column == 1 ) {
157
167
current_col <- start_after_eq
158
168
} else {
159
169
current_col <- start_after_eq +
160
170
previous_line [intersect(names(previous_line ), names(start_after_eq ))]
161
171
}
162
- is_aligned <- length(unique(current_col )) == 1 && length(start_after_eq ) > 1
172
+ is_aligned <- all(
173
+ length(unique(current_col )) == 1 ,
174
+ length(start_after_eq ) > 1
175
+ )
163
176
if (! is_aligned ) {
164
177
return (FALSE )
165
178
}
0 commit comments