I've got a flatfile, fixed width with neither newline nor linefeed (dump from AS400).
How do I load this file into an R data.frame?
I've tried different combinations of textConnection and read.fwf, to no avail.
The code below crashes Rstudio, so I'm assuming I'm overloading the system.
len
below is 24376400, which is tame as far as the files I usually load using read.table.
Record length is 400.
Is there any RECLEN parameter I should set, similar to SAS? Is there an option to set EOL = "\n" or "\r\n" ? Thank you.
fname <- "AS400FILE.TXT"
len <- file.info(fname)$size
conn <- file(fname, 'r')
contents <- readChar(conn, len)
close(conn)
df <- read.fwf( textConnection(contents) , widths=layout$length , sep="")
> dput(layout)
structure(list(start = c(1L, 41L, 81L, 121L, 161L, 201L, 224L,
226L, 231L, 235L, 237L, 238L, 240L, 280L, 290L, 300L, 305L, 308L,
309L, 330L, 335L, 337L, 349L, 350L, 351L, 355L, 365L), end = c(40L,
80L, 120L, 160L, 200L, 223L, 225L, 230L, 234L, 236L, 237L, 239L,
279L, 289L, 299L, 304L, 307L, 308L, 329L, 334L, 336L, 348L, 349L,
350L, 354L, 364L, 400L), length = c(40L, 40L, 40L, 40L, 40L,
23L, 2L, 5L, 4L, 2L, 1L, 2L, 40L, 10L, 10L, 5L, 3L, 1L, 21L,
5L, 2L, 12L, 1L, 1L, 4L, 10L, 36L), label = c("TITLE", "SUFFIX",
"ADDRESS1", "ADDRESS2", "ADDRESS3", "CITY", "STATE",
"ZIP", "ZIP+4", "DELIVERY", "CHECKD", "FILLER", "NAME",
"SOURCECODE", "ID", "FILLER", "BATCH", "FILLER", "FILLER",
"GRID", "LOT", "FILLER", "CONTROL",
"ZIPIND", "TROUTE", "SOURCEA", "FILLER")), .Names = c("start",
"end", "length", "label"), class = "data.frame", row.names = c(NA,
-27L))
> dim(layout)
[1] 27 4
>