talira

rstudioapi

Safely call the RStudio IDE's API from R packages

open sourceMITfree

rstudioapi is an R package from Posit that lets code, including CRAN packages, call the RStudio IDE's API when it's available and get an informative error when it isn't, so packages that use it still pass R CMD check outside RStudio. It wraps the API in a handful of functions that are always called with the rstudioapi:: prefix rather than attached.

Problems it solves

  • call RStudio IDE functions from my R package without breaking R CMD check
  • open a file or get the current selection in RStudio from R code
  • detect whether my R code is running inside RStudio

Features

  • calls the RStudio IDE API when it's available
  • informative errors when it isn't
  • safe to use from CRAN packages under R CMD check