0
f_ep = "/Users/kmein/Desktop/project/data/csv-files/17SK_U1.csv"   

listtxt_ep<-list.files(path = ep_dir, pattern="*.csv", full.names = T) 

d_ep = data.frame()
for(f_ep in listtxt_ep){
  tmp_ep <- read.delim(f_ep,header = T,row.names = NULL,fill = T) %>% as.data.frame(stringsAsFactors = F)
  d_ep <- bind_rows(d_ep, tmp_ep) 
}

I want to read in a bunch of csv files into R.

I want one document with all the csv files in it. But it gives me an error like this:

Error in make.names(col.names, unique = TRUE) : invalid multibyte string 1

The csv files are a table.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
takeITeasy
  • 350
  • 3
  • 19

1 Answers1

0

Here is an approach that proofed pretty efficient in the past for me:

f_ep  "/Users/kmein/Desktop/project/data/csv-files/17SK_U1.csv"   

listtxt_ep <- list.files(path = ep_dir, pattern = "*.csv", full.names = TRUE)

library(data.table)
df_list <- lapply(listtxt_ep, function(f) {
  # message("now reading file:", f) # optionally display status message
  out <- fread(f)
  out$source <- f
  return(out)
})

df <- rbindlist(df_list)

You can also directly bind the list using rbindlist(lapply( but I prefer this way as it gives me the opportunity to check the ingested csv files before binding (in case one has different number of columns etc).

JBGruber
  • 11,727
  • 1
  • 23
  • 45