Looking at the readxl documentation, I can see, that default column names, when there are no column names, has recently changed to ..1, ..2, ..3,
etc.
This creates some troubles, as illustrated here
library('readxl')
d = read_excel(readxl_example("datasets.xlsx"), skip = 148, col_names = FALSE)
# New names:
# * `` -> `..1`
# * `` -> `..2`
# * `` -> `..3`
# * `` -> `..4`
# * `` -> `..5`
d %>% select(..1)
# Error in .f(.x[[i]], ...) :
# ..1 used in an incorrect context, no ... to look in
d %>% select(`..1`)
# Error in .f(.x[[i]], ...) :
# ..1 used in an incorrect context, no ... to look in
I can naturally do something like this:
colnames(d) = colnames(d) %>% str_replace("..", "X")
d
# # A tibble: 3 x 5
# X1 X2 X3 X4 X5
# <dbl> <dbl> <dbl> <dbl> <chr>
# 1 6.5 3 5.2 2 virginica
# 2 6.2 3.4 5.4 2.3 virginica
# 3 5.9 3 5.1 1.8 virginica
But I'd rather not do this every time I read an excel file, so how to avoid readxl
using ..1
, ..2
as variable names?