I would like to vectorize the assign
function and create a set of arguments reflecting provided named vector that would be directly available in the .GlobalEnv
.
Code
vec_args <- c(arg1 = 1,
arg2 = 2,
arg3 = 3)
Vectorize(assign)(x = names(vec_args),
value = vec_args,
envir = globalenv())
Error
Error in dots[[3L]][[1L]] : wrong arguments for subsetting an environment
Desired results
ag1 <- 1; arg2 <- 2; arg3 <- 3; ls()
# [1] "ag1" "arg2" "arg3" "vec_args"
or via assign
:
In effect, I would like to replicate the call:
assign(x = "arg1", value = vec_args[1], envir = globalenv())
for each element of a vector and use vector names to create names in .GlobalEnv
.
This functionality is already available via
list2env
:Something like the following would also work: