I have a function whose output is a list. For a package I'm writing, users will create a number of lists using this function. The order in which these lists are created really matters. Here's the issue: I need a list of these lists, in the correct order (the order in which the objects were created), and I don't want to have to make users declare the list objects again. What I'd like to do is something like the following:
# Approach 1
list_of_lists <- list(
m1 <- function_that_makes_list(arg1, arg2)
m2 <- function_that_makes_list( arg3, arg4)
m3 <- function_that_makes_list( arg5, arg6)
)
So this would be equivalent to the following (which obviously works, but involves having to re-type m1, m2, m3, which I don't want):
m1 <- function_that_makes_list(arg1, arg2)
m2 <- function_that_makes_list(arg3, arg4)
m3 <- function_that_makes_list(arg5, arg6)
list_of_lists <- list(m1, m2, m3)
How can I make Approach 1 work? Any suggestions? Thanks!
lapply(1:n, function_that_makes_list).