You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
warningf("Combining a search string as 'skip' and reading a YAML header may not work as expected -- currently, reading will proceed to search for 'skip' from the beginning of the file, NOT from the end of the metadata; please file an issue on GitHub if you'd like to see more intuitive behavior supported.")
185
-
# create connection to stream header lines from file:
186
-
# https://stackoverflow.com/questions/9871307
187
-
f=base::file(input, 'r')
188
-
first_line= readLines(f, n=1L)
189
-
n_read=1L
190
-
yaml_border_re='^#?---'
191
-
if (!grepl(yaml_border_re, first_line)) {
192
-
close(f)
193
-
stopf(
194
-
'Encountered <%s%s> at the first unskipped line (%d), which does not constitute the start to a valid YAML header (expecting something matching regex "%s"); please check your input and try again.',
195
-
substr(first_line, 1L, 50L), if (nchar(first_line) >50L) '...'else'', 1L+skip, yaml_border_re
196
-
)
197
-
}
198
-
199
-
yaml_comment_re='^#'
200
-
yaml_string=character(0L)
201
-
repeat {
202
-
this_line= readLines(f, n=1L)
203
-
n_read=n_read+1L
204
-
if (!length(this_line)){
205
-
close(f)
206
-
stopf('Reached the end of the file before finding a completion to the YAML header. A valid YAML header is bookended by lines matching the regex "%s". Please double check the input file is a valid csvy.', yaml_border_re)
# create connection to stream header lines from file:
359
+
# https://stackoverflow.com/questions/9871307
360
+
con=base::file(f, 'r')
361
+
# NB: close() won't be right if 'f' itself can be a file connection (#561)
362
+
on.exit(close(con))
363
+
364
+
first_line= readLines(con, n=1L)
365
+
n_read=1L
366
+
yaml_border_re='^#?---'
367
+
if (!grepl(yaml_border_re, first_line)) {
368
+
stopf(
369
+
'Encountered <%s%s> at the first unskipped line (%d), which does not constitute the start to a valid YAML header (expecting something matching regex "%s"); please check your input and try again.',
370
+
substr(first_line, 1L, 50L), if (nchar(first_line) >50L) '...'else'', 1L+skip, yaml_border_re
371
+
)
372
+
}
373
+
374
+
yaml_comment_re='^#'
375
+
yaml_string=character(0L)
376
+
repeat {
377
+
this_line= readLines(con, n=1L)
378
+
n_read=n_read+1L
379
+
if (!length(this_line)){
380
+
stopf('Reached the end of the file before finding a completion to the YAML header. A valid YAML header is bookended by lines matching the regex "%s". Please double check the input file is a valid csvy.', yaml_border_re)
0 commit comments