mr_puddles
mr_puddles

Reputation: 117

Save file with variable text in file name in R

in R I'm trying to read in a file name where part of the file name references a string variable. I'm having issues with the paste function.

Without the variable reference I was reading the file as follows:

adp <- readxl::read_xlsx('Data//2020-08-28 Hours.xlsx')

I also have the following variable:

pdate <- as.Date('2020-08-28')

I tried to incorporate the variable as follows, but something is wrong with my syntax:

adp <- readxl::read_xlsx(paste(''Data//'. pdate, 'Hours.xlsx'')

Upvotes: 0

Views: 620

Answers (1)

ekoam
ekoam

Reputation: 8844

This is the correct syntax:

readxl::read_xlsx(paste0('Data//', pdate, ' Hours.xlsx'))

Upvotes: 1

Related Questions