Check if R is running in RStudio

前端 未结 9 675
小鲜肉
小鲜肉 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条回答
  •  -上瘾入骨i
    2020-12-09 02:09

    When I start RStudio it seems to have tools:rstudio in position 2 on the search path. This has a function "RStudio.version" which is undocumented but seems to return the RStudio version string:

    > RStudio.version()
    [1] "0.96.316"
    

    So you can define:

    is.RStudio <- function(){
      if(!exists("RStudio.version"))return(FALSE)
      if(!is.function(RStudio.version))return(FALSE)
      return(TRUE)
    }
    

    and maybe use that.

提交回复
热议问题