Reputation: 49
I am having a problem reading text files that were created when exporting the output from Android's Top command line that was running in a console.
The script I am using to read the file is pretty straight forward:
file_to_read <- paste(folder,file,sep="/")
myfile <- readLines(file_to_read)
writeLines(myfile, paste(folder,(paste((paste("Read_File_", 1, sep="")),".txt", sep="")), sep="/"), useBytes = FALSE)
I am saving the file read with a different name, and when I compare the two, I see that the 'Read_File" is only part of the original file. I have tried this with many of the files captured, and the majority show the same thing, only a partial read.
Now, checking the original file there are a bunch of extra characters that were added during the export (yes, that was my mistake, and I have corrected that problem). These are ANSI characters related to colors and other things on a command window.
The one thing I noticed is that when the following characters appear in the original file, [0më, that is as far as readlines will import, so I imagine these combination is some sort of break or EOF, or something that tells R, to stop the import or that there is nothing more to read.
The smallest section of the text file that I have that reproduces the problem is added to the end of the question.
I have also tried importing the file using read.table, but this also fails and I only get a partial import.
I am really at a loss as to what these extra characters are. The one thing I do know is just the these characters [0mà without the << does NOT cause the issue, so somehow the entire combination is the problem.
Tips are appreciated.
Section of text that has problem (similar to other files):
610 media -2 -2 22M 3.3M 3.0M S 12.5 0.2 317:13.30 vpud -f
417 system -3 -8 72M 6.4M 5.1M S 9.3 0.3 215:31.44 surfaceflinger
[?25h[0m[1000;1H[K [0më
~[----------
[s[999C[999B[6n[u[H[J[?25l[H[J[s[999C[999B[6n[uTasks: 288 total, 2 running, 286 sleeping, 0 stopped, 0 zombie
Mem: 1702176K total, 1658740K used, 44478464 free, 20733952 buffers
Swap: 425540K total, 414648K used, 11153408 free, 399640K cached
400%cpu 75%user 0%nice 75%sys 247%idle 0%iow 0%irq 3%sirq 0%host
Upvotes: 1
Views: 141