target of assignment expands to non-language object ERROR message

I am trying to assign model results to an object in a programmatic way so that I would only need to change the model run number to view particular model run results. However I am getting error message of "target of assignment expands to non-language object"

run = 1

paste0("model", run) <- c(run, 4, 74, 2)
hist(paste0("model", run))
boxplot(paste0("model", run))

I found a solution using the assign function. However, I have to add in eval(parse(text = ...) to the function for it to execute. Is there a way to streamline in the beginning code to include this eval(parse(text = ...)?

run = 1

assign(paste0("model", run), c(run, 4, 74, 2))

hist(eval(parse(text = paste0("model", run))))
boxplot(eval(parse(text = paste0("model", run))))

perhaps it would be more convenient to save the different model results into a list, and then index into the list for any particular result.

model_list <- list()

model_list[[1]] <-  c(1, 4, 74, 2)
model_list[[2]] <-  c(2, 7, 8, 60)


run <- 1


Thank you! the models were evaluated in different software but the outputs are used in R to explore. I will placing model results in list and then index to explore.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.