Question: Why does the colnames
function generate a tibble, when used with the pipe operator %>%
and the [
selector?
Example: Given the following tibble:
library(tidyverse)
x <- tribble(
~a, ~b,
1, 0,
0, 1
)
Problem: The colnames function generates a tibbe, when used with the pipe operator and the [
selector:
x %>% colnames(.)[1]
#> # A tibble: 2 x 1
#> a
#> <dbl>
#> 1 NA
#> 2 NA
Whereas I would expect it to generate a vector, as if no pipe operator was used:
colnames(x)[1]
#> [1] "a"