Rename columns when they don't exist

I'm reading and processing on a cron job a daily spreadsheet from the state of Texas tracking COVID vaccination data. I'm having issues because some columns tend to come and go, which rename does not like. For example, I have this statement:

  readxl::read_excel(Vaccine_path, sheet=2) %>% 
  rename(County="County Name", 
         Region="Public Health Region (PHR)", 
         Doses_Alloc="Total Doses Allocated", 
         Doses_Admin="Vaccine Doses Administered", 
         People_one_dose="People Vaccinated with at least One Dose", 
         People_fully="People Fully Vaccinated")

which works fine except when for a few random days the Allocated Doses column disappeared.

Suggestions on the cleanest way to deal with this inconsistent behavior in an automatic job?


I would use R's standard control flow syntax if(){} to test if a name is present, before conditionally renaming it.