Skip to content

Commit 266c159

Browse files
committed
Read multiple files directly
Has been a feature of readr since 2.0.0: https://readr.tidyverse.org/news/index.html#reading-multiple-files-at-once-2-0-0
1 parent 7c37f2d commit 266c159

1 file changed

Lines changed: 20 additions & 25 deletions

File tree

R/read_from_path.R

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,25 @@ read_from_path <- function(package, resource_name, col_select) {
4747
}
4848
skip <- if (dialect$header %||% TRUE) 1 else 0
4949

50-
# Read data with read_delim for each path (returns tibble)
51-
purrr::map_df(
52-
paths,
53-
function(path) {
54-
readr::read_delim(
55-
file = path,
56-
delim = dialect$delimiter %||% ",",
57-
quote = dialect$quoteChar %||% "\"",
58-
escape_backslash = escape_backslash,
59-
escape_double = escape_double,
60-
col_names = field_names,
61-
col_types = col_types,
62-
# Use rlang {{}} to avoid "col_select" to be interpreted as the name of
63-
# a column, see https://rlang.r-lib.org/reference/topic-data-mask.html
64-
# col_select needs to be assigned/used above to avoid lazy eval error
65-
col_select = {{ col_select }},
66-
locale = locale,
67-
na = schema$missingValues %||% "",
68-
comment = dialect$commentChar %||% "",
69-
trim_ws = dialect$skipInitialSpace %||% FALSE,
70-
# Skip header row when present
71-
skip = skip,
72-
skip_empty_rows = TRUE
73-
)
74-
}
50+
# Read data (one or more paths) with read_delim (returns tibble)
51+
readr::read_delim(
52+
file = paths,
53+
delim = dialect$delimiter %||% ",",
54+
quote = dialect$quoteChar %||% "\"",
55+
escape_backslash = escape_backslash,
56+
escape_double = escape_double,
57+
col_names = field_names,
58+
col_types = col_types,
59+
# Use rlang {{}} to avoid "col_select" to be interpreted as the name of
60+
# a column, see https://rlang.r-lib.org/reference/topic-data-mask.html
61+
# col_select needs to be assigned/used above to avoid lazy eval error
62+
col_select = {{ col_select }},
63+
locale = locale,
64+
na = schema$missingValues %||% "",
65+
comment = dialect$commentChar %||% "",
66+
trim_ws = dialect$skipInitialSpace %||% FALSE,
67+
# Skip header row when present
68+
skip = skip,
69+
skip_empty_rows = TRUE
7570
)
7671
}

0 commit comments

Comments
 (0)