0

I am using readbulk::read_bulk() to load several (~40+) .dat files into R. I was able to successfully load in another set of .dat files that used , as delimiters, but I was unable to do it for a set of files that used | as delimiters. How can I load these files and separate the data into columns given the | delimiter? Or, how can I separate the loaded data.frame by the | delimiter?

Example:

TEMP <- read_bulk(directory = "C:/Users/ABC/Desktop/Dat Files")

This produces a TEMP file with 19799 obs of 3 variables. As such, it is not separating them out by the | delimiter.

I've also tried:

files <- list.files(path = "C:/Users/ABC/Desktop/Dat Files2", pattern = "*.dat")

TEMP <- read_bulk(directory = "C:/Users/ABC/Desktop/Dat Files2", fun = utils::read.csv(file = files, sep = "\\|"))

But I get:

Error in file(file, "rt") : invalid 'description' argument
tyler
  • 3
  • 1
  • 4
  • 1
    Looking at `?read_bulk` I see that you can specify a reader function, which will take further arguments through `...`, by default its `read.csv()`. Take a look at `?read.csv` and see if it will take a seperator argument. – AkselA May 17 '19 at 19:22
  • I tried that, however, the issue is the `read.csv` is file specific, and I have 48 files I need to load into a single dataframe. – tyler May 17 '19 at 19:41
  • And some use `,` as delimiter, while others use `|`? – AkselA May 17 '19 at 20:12
  • 1
    That's not really a reproducible example. We need the contents of a few of those .dat files. A representative subset, small enough to reproduce the error, but not so big it will fill up a computer screen. – AkselA May 17 '19 at 20:16
  • Unless we have access to your C drive, showing the code that you use for reading files doesn't make it reproducible. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – camille May 17 '19 at 22:29

0 Answers0