Unknown column when reading in new csv-files

For my project, I have to read in a bunch of csv-files. Therefore, I wrote a loop to read them. Furthermore, I need to change the encoding, because my datasets contain a lot of umlauts and other special characters. I use the following code:

read_data <- function(directory,debug=FALSE){
  file_list = list.files(path = directory,
                       pattern = "*.csv",
                       full.names = TRUE);

  df_read = data.frame();

  for (filename in file_list){
    df_temp = read.csv(filename,encoding="UTF-16LE", sep=";", header=TRUE);
    
    if(debug){
      print(paste0(c(filename, " : ", dim(df_temp))));  
    }
    
    df_read = rbind(df_read, df_temp);
    
  }
  
  names(df_read) = make.names(names(df_read))
  
  return(df_read)
}

Unfortunately, I get a spurious warning message:

Warning messages:
1: Unknown or uninitialised column: 'y'. 
2: Unknown or uninitialised column: 'y'. 
3: Unknown or uninitialised column: 'y'. 
4: Unknown or uninitialised column: 'y'. 

However, all my columns do have names. What does this error message mean and can I just ignore it or do I have to change something in my code?

Are you able to share the files? Also, if you expect each CSV to have the same columns, you can achieve the binding of CSV's in a simpler way using functionals:

file_list = list.files(path = directory,
                       pattern = "*.csv",
                       full.names = TRUE)

df <- purrr::map_dfr(file_list, ~read.csv(., encoding = "UTF-16LE", sep = ";", header = TRUE))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.