Here's a one liner that'll get you most of the way:
sapply(list.files("~/r"), FUN = function(X) assign(X, rnorm(1)))
This assigns a random number to an object in the global environment, with each object taking its name from the files in my ~/r/
directory.
To give a concrete example, say we had a directory ~/r
and we wished to read the files in and have them as seperate items in the environment -- then one would do the following:
list2env(sapply(list.files("~/r"), FUN = function(X) read.csv(X)), globalenv())
This is a combination of two commands that has the advantage of not cluttering the global environment with the list containing all the files.
In steps we would do:
inList <- sapply(list.files("~/r"), FUN = function(X) read.csv(X))
list2env(inList, globalenv())