library(purrr)
prfx <- letters[1:4]
sffx <- letters[2:5]
var_names <- as.vector(outer(
X = prfx,
Y = sffx,
FUN = paste,
sep = "_"
))
Create a named list
set_names(flatten(map(prfx, function(p) {
map_int(sffx, function(s, p) {
sum(c(as.integer(charToRaw(p)),
as.integer(charToRaw(s))))
}, p)
})), var_names) -> a
Inspect it
str(a)
## List of 16
## $ a_b: int 195
## $ b_b: int 196
## $ c_b: int 197
## $ d_b: int 198
## $ a_c: int 196
## $ b_c: int 197
## $ c_c: int 198
## $ d_c: int 199
## $ a_d: int 197
## $ b_d: int 198
## $ c_d: int 199
## $ d_d: int 200
## $ a_e: int 198
## $ b_e: int 199
## $ c_e: int 200
## $ d_e: int 201
If you really need to avoid typing a$a_b (etc) then
attach(as.environment(a))
And you can reference them directly
a_b
## [1] 195
a_c
## [1] 196
But, as Thomas said, you should really keep them in a list.