The rstudioapi package provides an interface for interacting with the RStudio IDE with R code. Using rstudioapi, you can:

Please see the other articles for more detailed information.