Reading a text file in R is possible and a user wants to read a text file in R and that too line by line.How to do that?
Reading all the lines at a time is possible but can be ricky so to process the line one at a time for reading, we can do the following
processFile = function(filepath) {
connection = file(filepath, "r")
while ( TRUE ) {
lines = readLines(connection, n = 1)
if ( length(lines) == 0 ) {
break
}
print(lines)
}
close(connection)
}