Error in dev.off() : cannot shut down device 1 (the null device)

P.S. This is definitely an RStudio issue, as the code runs fine in R.