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.
Your pseudocode in R style:
Now
datis 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:Where
process_lineis the function that processes each line. The result is a list of processed lines. To put them into adata.frame:Or use
ldplyfrom theplyrpackage to do this in one go: