The csv is malformed.
What is the story of how the csv was generated ? that process should be amended.
library(readr)
malformedtxt <- c("\"StudentID, First, Last, Math, Science, Social Studies\"",
"\"011, Bob, Smith, 90, 80, 67\"" ,
"\"012, Jane, Weary, 75, , 80\"" ,
"\"010, Dan, \"\"Thornton, III\"\", 65, 75, 70\"" ,
"\"040, Mary, \"\"O'Leary\"\", 90, 95, 92\"")
tf <- tempfile()
writeLines(malformedtxt,tf)
(r1 <- readLines(tf))
cat(paste0(r1,"\n"))
(df_bad <- readr::read_csv(tf))
workingtxt<-c("StudentID, First, Last, Math, Science, \"Social Studies\"",
"011, Bob, Smith, 90, 80, 67",
"012, Jane, Weary, 75, , 80" ,
"010, Dan, \"Thornton, III\", 65, 75, 70",
"040, Mary,\"O'Leary\", 90, 95, 92")
tf <- tempfile()
writeLines(workingtxt,tf)
(r1 <- readLines(tf))
cat(paste0(r1,"\n"))
(df_good <- readr::read_csv(tf))