Instead of 2018_01 I want n-36, i.e., the 36th previous month.
Instead of 2018_02 I want n-35, i.e., the 35th previous month.
Instead of 2018_03 I want n-34, i.e., the 34th previous month.
I want to define a base month on the code and then count backwards 36 months.
floor_date(Sys.Date(), "month") will output the 1st of the current month. I calculate that to avoid any complications around different-length months. All months have a 1st so that should be predictable.
Then I use lubridate's odd-looking %m-% operator which subracts months (basically equivalent to using negative numbers with Excel's EDATE function, as far as I can tell).
Finally, I paste the results together into a string like we need.
(I assume you are actually saving the results to different files, otherwise the 2nd line will just overwrite the result of the 1st line, and then again with the 3rd line.)