Search code examples
rvariablespathxlsx

How to add a variable to a file path


I have:

points <- read_xlsx ("Data / PC-2021050200.xlsx", sheet = "coordinate")

Earlier in the code, I put the date "2021-05-02" which is a variable. How to enter date as a variable in the file path?


Solution

  • We can use glue

    date <-  as.Date("2021-05-02")
    points <- read_xlsx(glue::glue("Data /PC-{format(date, '%Y%m%d00')}.xlsx"))