Error: cannot allocate vector of size 17348.7 Gb

The rtools40 instructions include: writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")

I got the same ‘rtools has been deleted’ warning before I ran that.

I’d recommend just starting with a clean Renviron and Makevars.win, then run that line above, and see whether it works.