Q: Creating a separate object for each iteration of for-loop within a function I have a function that contains a for-loop that iterates 160 times, producing a 3-dimensional array after every iteration. I want the for-loop to save each array separately as object under the name, such as array001, array002, array003, etc., preferably without spitting those out to global workspace. Finally, I want to be able to call some of these arrays later on within the same function.  
array.function <- function(df, parameter = 0) {
                      for (i in 1:160) {
                           DO A LOT OF STUFF
                           SAVE OUTPUT AS array###
                      }

                      DO MORE STUFF with arrays generated by for-loop above
                   }

Any ideas on how to save the arrays as objects with corresponding numbers in its' names? Thank you! 

A: The comment from lmo is a great workable solution for storing the arrays and accessing them later in the function. However, if you really want them to be stored as separate variables instead of as a list, assign() and get() are your friends:
array.function <- function(df, parameter = 0) {
  # This stores the function's environment for convenience:
  env <- environment()
  for ( i in 1:160 ) { # Then for each iteration
    # make an array and store it in the function's environment
    assign(paste0('array', i), array(c(i, 2:27), dim=c(3, 3, 3)))
  }
  # Then print out a randomly selected array to make sure it worked
  print(get(paste0('array', sample(1:160, 1))))
  # I don't know what you want to do with the arrays,
  # for now just return the whole function's environment
  # (the arrays as well as 'i', 'df', 'env', and 'parameter')
  return(as.list(sapply(ls(envir=env), get, envir=env)))
}

x <- array.function(1) # the 1 is just because I kept your arguments

, , 1

     [,1] [,2] [,3]
[1,]  158    4    7
[2,]    2    5    8
[3,]    3    6    9

, , 2

     [,1] [,2] [,3]
[1,]   10   13   16
[2,]   11   14   17
[3,]   12   15   18

, , 3

     [,1] [,2] [,3]
[1,]   19   22   25
[2,]   20   23   26
[3,]   21   24   27

For each iteration of your loop, assign(paste0('array', i), value) creates a variable in the function's environment -- not the global environment, at least not by default -- whose name is the result of paste0('array', i) and whose value is value (whatever array you create). You can access it later using get(paste0('array', x)), where x is the number of the array you need.
An excellent resource for learning more about function environments is Hadley Wickham's book.
