How to read a text file to a list array?

r

Solution

Your pseudocode in R style:

dat = readLines("file.txt")

Now `dat` is a vector where each line in the file is an element in the vector. R is a functionally oriented language, so this performs a given function on each element:

l = lapply(dat, process_line)

Where `process_line` is the function that processes each line. The result is a list of processed lines. To put them into a `data.frame`:

do.call("rbind", l)

Or use `ldply` from the `plyr` package to do this in one go:

require(plyr)
ldply(dat, process_line)

Problem

I just started coding in R-Lang and I was wondering what the best way to read a plan text file is? I am looking for something like this pseudo-code: ``` data = new List(); data = file.readall("myfile.txt") close foreach (a in data) { print(a) } ``` pretty simple text, I read the tutorials but dont understand how R's file access works, it looks very much different to anything im used to.. I'm unsure what args to use.

Original source