Multiple CSV can't import in the new version of RStudio-2022.02.0-443

Hi,
Recently, I have updated RStudio. I am facing a problem in reading multiple CSV files. It is showing NULL. Please, help me if I am doing something wrong.
I am using the following script--

setwd("D:/work/")

> file <- list.files(pattern="*.csv")
> multifiles <- sapply(file, read.csv)

> file
NULL

> multifiles
list()

> 

FYI, in the previous version of R, this same script is working fine :slight_smile:

Thank you, any help is appreciated.

What is the result of running

setwd("D:/work/")
list.files()

Do you see your csv files in that?

Hi, thank you so much for your response. list.files() is showing all the CSV files that are in a folder.

Could it be the difference between csv and CSV? Try

list.files(pattern="*.CSV|csv")

It is showing (I have added-- "*." before CSV/csv, in comment its not visible)---

list.files(pattern=".CSV|csv")
NULL
list.files(pattern="
.CSV")
NULL
list.files(pattern="*.csv")
NULL

The pattern argument of list.files() is a regular expression. The * by itself does not act as a wildcard; it means "zero or more of the preceding". Similarly, a . represents "any character". Placing *. before csv is not having the effect you want. I do not think that is the origin of the problem but let's clean that up just in case. If you want to search for csv at the end of the file name, place a $ after csv. The $ represents the end of the input.
Here is a series of trials I ran. Notice the last one where I search for a pattern that does not exist I get character(0) not NULL.

list.files(pattern = "csv|CSV$")
[1] "AgeGenderID.csv" "Dummy.csv"       "Junk.CSV"       
list.files(pattern = "csv$")
[1] "AgeGenderID.csv" "Dummy.csv"      
list.files(pattern = "CSV$")
[1] "Junk.CSV"
list.files(pattern = "ZZZ$")
character(0)

You said earlier that if you run list.files() you do see the csv files. Could you post that result, copied from the console? If it is too many files, just post a small section showing some of the csv files found.

Thank you very much for supporting my request :slight_smile:
here is the result of list.files()----

list.files()
[1] "Africa_100.png"
[2] "Africa_50.png"
[3] "Atlas_Mountains.csv"
[4] "Burundi.csv"
[5] "Chaara_and_Grotte_de_Piste_Cave.csv"
[6] "Lake_Challa.csv"
[7] "Lake_Edward.csv"
[8] "Lake_Naivasha.csv"
[9] "Morocco.csv"

Please confirm whether

list.files(pattern = "csv$")

returns the csv file names.

1 Like

Yes, you are right. list.files(pattern = "csv$") showing csv only :slight_smile:

list.files(pattern = "csv$")
[1] "Atlas_Mountains.csv"
[2] "Burundi.csv"
[3] "Chaara_and_Grotte_de_Piste_Cave.csv"
[4] "Lake_Challa.csv"
[5] "Lake_Edward.csv"
[6] "Lake_Naivasha.csv"
[7] "Morocco.csv"

I tried reading the CSV file by adding ---- "pattern = "csv$". Now I am able to read all files. Thank you so much for helping me :slight_smile: I appreciate it. In the previous version of R, I was using " * .csv", but in a new version it is "csv$" :slight_smile:
Finally worked :slight_smile:

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.