I have a fixed width character vector input called "text" that looks something like this:
[1] " Report"
[2] "Group ID Name"
[3] "Number"
[4] "AA A134 abcd"
[5] "AB A123 def"
[6] "AC A345 ghikl"
[7] "BA B134 jklmmm"
[8] "AD A987 mn"
I need to create a standard DataFrame. My approach is to first create a text file and then use the read.fwf function to create a clean DataFrame from a fixed width text file input. What I have works, but it forces me to create a text file in my working directory and then read it back in as a fwf:
> cat(text, file = "mytextfile", sep = "\n", append = TRUE)
> read.fwf("mytextfile", skip = 3, widths = c(12, 14, 20))
Is it possible to achieve the same result without saving the intermediate output to my working directory? I tried using paste() and capture.output() without success. While
x = paste(text, collapse = "\n")
seemed to work at first, but when I passed it to
read.fwf(x, skip = 3, widths = c(12, 14, 20))
I got
Error in file(file, "rt") : cannot open the connection
In addition: Warning Message:
In file(file, "rt") : cannot open file '
and capture.output() got me back to square one, a character vector. Any advice is greatly appreciated. Thank you.