rorus, I like your solution, its elegant.
Here is a slightly longer alternative though, as it is a little more explicit, and lets the programmer 'interfere` with the labels easily also
library(tidyverse)
library(WDI)
library(Hmisc)
x <- c("GE.EST", "RQ.EST") %>%
WDI::WDI(country = "all", indicator = .,
start = 2014, end = 2019, extra = FALSE)
catchlabel <- enframe(x=Hmisc::label(x),
name = "indicator",
value= "label")
x2 <- x %>%
pivot_longer(ends_with("EST"), names_to = "indicator") %>%
left_join(catchlabel)
I have never thought that _join functions that can work without mention by in the code.
c("GE.EST", "RQ.EST") %>%
WDI::WDI(country = "all", indicator = .,
start = 2014, end = 2019) %>%
{left_join(pivot_longer(., -c(iso2c, country, year), "code"), # i used -c in case of having lot of variables.
Hmisc::label(.) %>% enframe("code", "indicator"))}
Thanks again for your help