Q:

R - convert a 2-d vector into a 1-d named vector

How can this be done more elegantly?  I'm looking to convert a vector of key value pairs as concatenated strings, into a vector of values with the keys as names.
library(tidyverse)
library(purrr)

x <- c("key1|value1", "key2|value2")

# Current way
x_split <- x %>% str_split("\\|")
keys <- x_split %>% map(pluck(1)) %>% unlist()
values <- x_split %>% map(pluck(2)) %>% unlist()

y <- values %>% set_names(keys)

# More elegant way
y <- x %>% some_functions()

A:

You can use  simplify = TRUE in str_split and use set_names. 
stringr::str_split(x, "\\|", simplify = TRUE) %>% {purrr::set_names(.[, 2], .[, 1])}

#    key1     key2 
#"value1" "value2" 

