Search code examples
rtidyversepurrr

What is a proper alternative for pluck(col_name)


This is a pretty common operation in my toolbox. I want a pure tidyverse solution without using a character.

suppressWarnings(library(tidyverse))
tibble(a=1) %>% pluck('a')
#> [1] 1
tibble(a=1) %>% pluck(a)
#> Error in list2(...): object 'a' not found

Created on 2023-01-10 by the reprex package (v2.0.1)


Solution

  • We may use pull

    tibble(a =1) %>%
       pull(a)
    [1] 1
    

    Or if we want to use pluck

    tibble(a=1) %>% 
     pluck(deparse(substitute(a)))
    [1] 1