EOF within quoted string warning when merging csv files

Viewed 54

I have more than 70 CSV files and I am trying to merge them row-wise (they all have same columns). I tried to combine them using this code:

library(tidyverse)
library(plyr)
library(readr)
setwd("*\\data")
myfolder="test"
allfiles= list.files(path=myfolder, pattern="*.csv", full.names = T)
allfiles
combined_csv= ldply(allfiles, read.csv)

Once I run this code I get a warning message:

Warning message:
In scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  :
  EOF within quoted string

It looks like that I am losing some rows. How can I fix this?

2 Answers

It is possible that same columns in different files are read as different types when some of them have some 'character' element and some are just numeric. Here, is one method to read with all columns specified as "character" column, rbind the elements and then use type.convert to automatically convert the column classes based on the value it have

library(data.table)
out <- rbindlist(lapply(list.files(path=myfolder, full.names = TRUE), 
       fread, colClasses = "character"))
out <- type.convert(out, as.is = TRUE)

Try this:

library(dplyr)
library(readr)

myfolder="test" 

df <- list.files(path=myfolder, full.names = TRUE) %>% 
  lapply(read_csv) %>% 
  bind_rows 
Related