Older version of file, corrupted with repeated "<- %>%", when re-opening RStudio project

I'm sorry, I'm not sure how to reproduce this error, nor could find similar issues online.
This has happened twice to me, with dangerous possible consequences. My steps:

  1. Close RStudio Project
  2. Some time later, reopen the same project using "Recent Projects" menu option.
    When the project opens, I have some code files expanded out to their own windows and some in the main Rstudio window.

The problem:

  • a file that I was doing major editing in recently is opened showing unsaved changes (even though I saved all changes before closing).
  • this file is a significantly older version of that file (missing all my recent changes)
  • the file is corrupted in an area of the code with many assignment arrows <- and pipes %>%, as demonstrated in a snippet below. This corruption seems nonsensical. I'm not sure whether it has inserted itself, or replaced existing code. In this most recent case, I believe it has just inserted itself.

I found this dangerous because I instinctively saved the file, and had to revert to an older commit, and lost recent code changes.

Looking into the .Rproj.user folder, I notice that the folder that contains (some of) the open files at the time, sources/s-97E7E170/ also contains the corruption and the older version of the file.
I am on RStudio v1.1.383 and MacOS 10.13.4

run_codex_list_of_dats <- function(codex_date, scan_options, num_cores) {
  #>###
  #># scan options are written once to avoid confusion
  #># returns a saved file of scan objects and metadata
  #>###
  list_of_dats <- readRDS(paste0('sim2018/dfs_codex_', codex_date, '.rds'))
  
  #> we only need to run one direction since we're looking for positive bias
  #>   we could run the other direction to see how many false directions we get
  codex_scan_objs <- <- <- <- <- %>% %>% <- <- %>% <- <- <- <- %>% %>% %>% <- <- <- %>% <- <- %>% <- %>% %>% %>% %>% %>% <- <- <- %>% %>% %>% %>% %>% <- %>% <- %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% <- %>% %>% <- %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% <- <- <- <- <- <- <- <- <- <- <- <- <- %>% %>% %>% %>% %>% %>% %>% <- <- <- %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% <- %>% %>% %>% %>% %>% %>% <- <- <- 
    mclapply(list_of_dats[1:3], mc.cores = num_cores,
             FUN = function(x) {
               scan_obj_list <- run_scan_on_codex_dat(x$dats, scan_options) 
               scan_obj_list
             })
#> ... etc... code continues normally in its older version

Have you tried opening the .Rproj file directly rather than from the recent projects pane? I had an odd problem with that in the daily build a week or so ago, so it might be worth giving it a whirl.

Thanks Mara, will do that going forward and see if it occurs again.
To clarify, when you saw this, did you also see many repeated "<-" and "%>%" inserted into the code?

Oh, no…that part is new to me! ¯\(°_o)/¯