Home > front end >  Importing csv files based on part of file name only in r
Importing csv files based on part of file name only in r

Time:02-25

I have two questionnaires that automatically assigns the date of the download in the file name. I want future researchers to be able to download the files and use the r code without having to change the file name.

So instead of being

questionnaire1.csv
questionnaire2.csv

they get downloaded as

questionnaire1_February 24, 2022_06.16.csv
questionnaire2_February 24, 2022_06.17.csv

Is there a way I can make r just take the first part of the name like:

q1 <- read.csv("Path where your CSV file is located on your computer\\questionnaire1*.csv")
q2 <- read.csv("Path where your CSV file is located on your computer\\questionnaire2*.csv")

CodePudding user response:

You can search files using a pattern:

q1 <- read.csv(list.files("your/path/", full.names = TRUE,
      pattern = "questionnaire1")[[1]])
  • Related