Using lappy to read all csv in folder (using read_csv) causes parsing error

Hello everyone,

I have done some reading and can not find the exact problem I am having. I am attempting to input data into an RShiny dashboard. There is a folder with many files within it I want to read at the same time in order to add it to the RShiny dashboard.

I have used this code:

'''

 data_all <- list.files(path = "/Users/PATHWAY/",      # Identify all csv files in folder
                        pattern = "*.csv", 
                        full.names = TRUE) %>% 
                        lapply(read_csv) %>%                                          
                        bind_rows

'''

However, this is causing the following error:
"Warning message:
One or more parsing issues, see problems() for details "

From what I have read, my understanding is that I need to use the col_types function. However, I am unsure how to add this function into my code to read the all files within my data folder. I would love to learn some more about this.

Thank you for your time and feedback regarding my code, and different ways I can achieve my goal without errors.

Thank you.

What was the output of problems()?

Is there an issue in your files perhaps?

Otherwise you could try purrr.

1 Like

The output of problems() is

"# A tibble: 0 × 5

… with 5 variables: row , col , expected , actual , file "

Despite this error, I can use view() to see the data frame and it seems to be correct upon first glance. The issue being that it is then difficult to deal with the data frame later in RShiny as a result of the error

1 Like

Thank you for your second piece of advice. I have utilized purrr to input my data (as per the resource you have sent) and it is producing the same error as above. Once again, problems() has the same output.

This makes me think something is wrong with my data. I have looked at it and all the headings match. I have previously successfully read in one csv at a time with no issues.

With some experimentation, I can break this down further. I can read_csv each file individually with no errors. When manually attempting to use bind_rows() this causes the same parsing error. Do you have any thoughts as to why this may be happening?

Possibly some numeric columns are being read in as character. Other than that, I don't really know. If it is that, you could use the guess_maxargument in read_csv().

1 Like

This topic was automatically closed 7 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.