Check if R is running in RStudio

前端 未结 9 682
小鲜肉
小鲜肉 2020-12-09 01:46

I am looking for a way to test if R is being run from RStudio. For some reason I could find the answer on google yesterday but not today, but I think it had to do with testi

9条回答
  •  旧巷少年郎
    2020-12-09 02:22

    Neat solution is now available through the startup package via the is_rstudio_console function:

    startup:::is_rstudio_console()
    [1] TRUE
    

    It may be worth adding that this function checks for two environment variables, RSTUDIO, which was mentioned in the answer by @krlmr and RSTUDIO_TERM that doesn't seem to be mentioned across the preceding answers at the moment.

    function ()
    {
        (Sys.getenv("RSTUDIO") == "1") && !nzchar(Sys.getenv("RSTUDIO_TERM"))
    }
    

提交回复
热议问题