Skip to content

Commit fba4bef

Browse files
committed
Improve efficiency of identifying columns to read
1 parent c658c87 commit fba4bef

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

R/csv.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -852,16 +852,15 @@ remaining_columns_to_read <- function(requested, currently_read, all) {
852852
unread <- requested[!(requested %in% currently_read)]
853853
} else {
854854
all_remaining <- all[!(all %in% currently_read)]
855-
unread <- c()
856-
for (p in requested) {
857-
if (any(all_remaining == p)) {
858-
unread <- c(unread, p)
859-
}
860-
is_unread_element <- startsWith(all_remaining, paste0(p, "["))
861-
if (any(is_unread_element)) {
862-
unread <- c(unread, all_remaining[is_unread_element])
863-
}
855+
# identify exact matches
856+
matched <- as.list(match(requested, all_remaining))
857+
# loop over requests not exactly matched
858+
for (id in which(is.na(matched))) {
859+
matched[[id]] <-
860+
which(startsWith(all_remaining, paste0(requested[id], "[")))
864861
}
862+
# collect all unread variables
863+
unread <- all_remaining[unlist(matched)]
865864
}
866865
if (length(unread)) {
867866
unique(unread)

0 commit comments

Comments
 (0)