Skip to content

Commit c50c7f7

Browse files
committed
Fix selection when col_names = FALSE
If `col_names = FALSE` we pass `character()` to `col_types_standardise()`, not `NULL`. So we need to check the length rather than explicitly for `NULL`. Fixes #381
1 parent bc71013 commit c50c7f7

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# vroom (development version)
22

3+
* `vroom(col_select=)` now works if `col_names = FALSE` as intended (#381)
4+
35
* `vroom(n_max=)` now correctly handles cases when reading from a connection and the file does _not_ end with a newline (https://github.com/tidyverse/readr/issues/1321)
46

57
* `vroom()` no longer issues a spurious warning when the parsing needs to be restarted due to the presence of embedded newlines (https://github.com/tidyverse/readr/issues/1313)

R/col_types.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ col_types_standardise <- function(spec, num_cols, col_names, col_select, name_re
382382
}
383383
}
384384

385-
if (is.null(col_names)) {
385+
if (length(col_names) == 0) {
386386
col_names <- make_names(NULL, num_cols)
387387
}
388388

tests/testthat/test-select.R

+8
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,11 @@ test_that("col_select can select the id column", {
6363
c("path", "model", "mpg")
6464
)
6565
})
66+
67+
test_that("col_select works with col_names = FALSE", {
68+
res <- vroom(I("foo\tbar\n1\t2\n"), col_names = FALSE, col_select = 1, col_types = list())
69+
expect_equal(res[[1]], c("foo", "1"))
70+
71+
res2 <- vroom(I("foo\tbar\n1\t2\n"), col_names = FALSE, col_select = c(X2), col_types = list())
72+
expect_equal(res2[[1]], c("bar", "2"))
73+
})

0 commit comments

Comments
 (0)