error reading CSV with read_csv()

hello there. I was writing a file CSV on my own on Excel and saved it as "UTF-8 comma separated CSV". when I read the CSV in R, the only line read correctly is the header while the others lines of the CSV are in the first column although they are comma separated. here i share the example for my problem:

FILE.csv:
String,Number,Number,Number,Number,Number,Number(0-1),Number,Number,String,Date,Date
NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,"YYYY-MM-DD","YYYY-MM-DD"
NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,"YYYY-MM-DD","YYYY-MM-DD"
NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,"YYYY-MM-DD","YYYY-MM-DD"

R:
library(tidyverse)
data <- read_csv("Data/FileName.csv")

OUTPUT:
String Number Number.1 Number.2
1 NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,"YYYY-MM-DD","YYYY-MM-DD" NA NA NA
2 NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,"YYYY-MM-DD","YYYY-MM-DD" NA NA NA
3 NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,"YYYY-MM-DD","YYYY-MM-DD" NA NA NA
Number.3 Number.4 Number.0.1. Number.5 Number.6 String.1 Date Date.1
1 NA NA NA NA NA NA NA NA
2 NA NA NA NA NA NA NA NA
3 NA NA NA NA NA NA NA NA

I can't understand the reason for why R is reading correctly the first row but can't read the rest of the file. someone can help with any advice?

The data you posted are handled correctly by read_csv() when I tried it.

library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 4.3.3
DATA <- read_csv("~/R/Play/Dummy.csv")
#> New names:
#> Rows: 3 Columns: 12
#> ── Column specification
#> ──────────────────────────────────────────────────────── Delimiter: "," chr
#> (4): String...1, String...10, Date...11, Date...12 dbl (8): Number...2,
#> Number...3, Number...4, Number...5, Number...6, Number(...
#> ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
#> Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> • `String` -> `String...1`
#> • `Number` -> `Number...2`
#> • `Number` -> `Number...3`
#> • `Number` -> `Number...4`
#> • `Number` -> `Number...5`
#> • `Number` -> `Number...6`
#> • `Number` -> `Number...8`
#> • `Number` -> `Number...9`
#> • `String` -> `String...10`
#> • `Date` -> `Date...11`
#> • `Date` -> `Date...12`
DATA
#> # A tibble: 3 × 12
#>   String...1 Number...2 Number...3 Number...4 Number...5 Number...6
#>   <chr>           <dbl>      <dbl>      <dbl>      <dbl>      <dbl>
#> 1 NAME             14.4        200       14.0         10       84.1
#> 2 NAME             14.4        200       14.0         10       84.1
#> 3 NAME             14.4        200       14.0         10       84.1
#> # ℹ 6 more variables: `Number(0-1)` <dbl>, Number...8 <dbl>, Number...9 <dbl>,
#> #   String...10 <chr>, Date...11 <chr>, Date...12 <chr>

Created on 2024-05-08 with reprex v2.0.2

The csv file looks like this:

String,Number,Number,Number,Number,Number,Number(0-1),Number,Number,String,Date,Date
NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,"YYYY-MM-DD","YYYY-MM-DD"
NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,"YYYY-MM-DD","YYYY-MM-DD"
NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,"YYYY-MM-DD","YYYY-MM-DD"

Thank you @FJCC for your feedback. I found the error when loading my data. it seems that excel when I save my CSV is saving it in this format:

String,Number,Number,Number,Number,Number,Number(0-1),Number,Number,String,Date,Date
"NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,""YYYY-MM-DD"",""YYYY-MM-DD"""
"NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,""YYYY-MM-DD"",""YYYY-MM-DD"""
"NAME,14.45,200.00,14.04,10,84.13,0,28.45,289.26,S,""YYYY-MM-DD"",""YYYY-MM-DD"""

as you can see there are "" at the beginning and end of the rows 2-4 that is not allowing R to read the file the right way. do yoy have any idea for why this is happening and how I can solve it? i tried to modify the csv with R pasting your example and it works but if I modify it from excel it saves the file as shown in my example with "" for some reason.

What is the origin of the data? Is there a version of it that has not been touched by Excel? If so, open that in a plain text editor, e.g. NotePad on Windows, and see what it looks like.

I had some untidy data on excel so I was writing a CSV myself with excel because it is not a big database. I tried to open the original data (the one with error when reading on R) with text editor and they looked the same way R was reading them (with ""). Since I found out that writing the CSV in R, opening it from the project's files, does not get an error I'll finish writing it on R.
Thank you again for your help! this is my first time in the Posit comunity and it has already given me a big help.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.