As mentioned in the comments, this is because the number of columns is determined by the first five lines of input. If you're in a traffic jam, here is a possible workaround I checked and seems to work well. The secret is to introduce a vector for col.names , which is the length of the number of columns in the data. We can get the number of columns using count.fields() . Insert the file name for file .
#
Here is the tested code with your data:
txt <- "10000011791441224671,V_Display,exit\n10000011951441812316,V_Display,exit\n1000000191441228436,V_Display,exit\n10000013211441319797,V_Display,exit\n1000001331441725509,V_Display,exit\n10000013681418242863,C_GoogleNonBrand,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,exit\n10000014031441295393,V_Display,exit" ncols <- max(count.fields(textConnection(txt), sep = ",")) df <- read.csv(text = txt, header = FALSE, col.names = paste0("V", seq_len(ncols))) dim(df) , exit \ n1000000191441228436, V_Display, exit \ n10000013211441319797, V_Display, exit \ n1000001331441725509, V_Display, exit \ n10000013681418242863, C_GoogleNonBrand, V_Display, V_Display, V_Display, V_Display, V_Display, V_Display, txt <- "10000011791441224671,V_Display,exit\n10000011951441812316,V_Display,exit\n1000000191441228436,V_Display,exit\n10000013211441319797,V_Display,exit\n1000001331441725509,V_Display,exit\n10000013681418242863,C_GoogleNonBrand,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,V_Display,exit\n10000014031441295393,V_Display,exit" ncols <- max(count.fields(textConnection(txt), sep = ",")) df <- read.csv(text = txt, header = FALSE, col.names = paste0("V", seq_len(ncols))) dim(df)