How about a left join? First you gather() your coded data to long form, left_join() it with the lookup table, then back to wide with spread().
library(tidyverse)
tbl <-
tribble(
~ FRUIT, ~ NUM, ~ NAME, ~ORDINAL,
1, 1, 1, 1,
2, 2, 2, 2,
3, 3, 3, 4
)
lookup <-
tribble(
~ VAR, ~ CODE, ~ VALUE,
"FRUIT", 1, "apple",
"FRUIT", 2, "banana",
"FRUIT", 3, "cherry",
"NUM", 1, "one",
"NUM", 2, "two",
"NUM", 3, "three",
"NAME", 1, "Adam",
"NAME", 2, "Barb",
"NAME", 3, "Chad",
"ORDINAL", 1, "first",
"ORDINAL", 2, "second",
"ORDINAL", 3, "third",
"ORDINAL", 4, "fourth"
)
tbl %>%
gather(VAR, value = CODE) %>%
left_join(lookup, by = c("VAR", "CODE")) %>%
select(-CODE) %>%
group_by(VAR) %>%
mutate(row_id = 1:n()) %>%
spread(VAR, VALUE) %>%
select(-row_id)
#> # A tibble: 3 x 4
#> FRUIT NAME NUM ORDINAL
#> <chr> <chr> <chr> <chr>
#> 1 apple Adam one first
#> 2 banana Barb two second
#> 3 cherry Chad three fourth
Created on 2018-03-06 by the reprex package (v0.2.0).