检查 R 是否在 RStudio 中运行 [英] Check if R is running in RStudio

查看:35
本文介绍了检查 R 是否在 RStudio 中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来测试 R 是否正在从 RStudio 运行.出于某种原因,我昨天可以在 google 上找到答案,但今天不行,但我认为这与测试是否设置了某个系统变量有关.

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 testing if a certain system variable was set.

推荐答案

没有在 RStudio 内运行".RStudio 只是一个围绕 R 的 IDE 层;在一天结束时,它只是启动正常的 R 可执行文件,您需要在 $PATH 上拥有它才能运行 RStudio.

There is no "running inside RStudio". RStudio is merely an IDE layer that wraps around R; at the end of the day it just launches the normal R executable you need to have on your $PATH anyway to operate RStudio.

作为代理和 R Studio 您可以测试 available.packages() 的manipulate"包,或者作为较短的版本,看看 RStudio 是否将自身添加到 .libPath()内容:

As a proxy, and as R Studio You could test available.packages() for the 'manipulate' package though, or as a shorter version see if RStudio added itself to the .libPath() content:

R> any(grepl("RStudio", .libPaths()))
[1] TRUE
R> 
R> 

在 2020 年 5 月或八年后编辑 问题确实出现了,并且可以从内部查询各种内容.这是来自 RStudio 终端的示例:

Edit in May 2020 or eight years later The question does come up, and one can query a variety of things from within. Here is an example from the terminal of RStudio:

$ env | grep -i rstudio | sort
GIO_LAUNCHED_DESKTOP_FILE=/usr/share/applications/rstudio.desktop
PATH=[...redacted...]
RMARKDOWN_MATHJAX_PATH=/usr/lib/rstudio/resources/mathjax-27
RS_RPOSTBACK_PATH=/usr/lib/rstudio/bin/rpostback
RSTUDIO=1
RSTUDIO_CONSOLE_COLOR=256
RSTUDIO_CONSOLE_WIDTH=111
RSTUDIO_PANDOC=/usr/lib/rstudio/bin/pandoc
RSTUDIO_PROGRAM_MODE=desktop
RSTUDIO_PROJ_NAME=chshli
RSTUDIO_SESSION_ID=9C62D3D4
RSTUDIO_SESSION_PORT=13494
RSTUDIO_TERM=2BD6BB88
RSTUDIO_USER_IDENTITY=edd
RSTUDIO_WINUTILS=bin/winutils
$ 

同样,在 R 会话中:

Similarly, from within the R session:

R> se <- Sys.getenv()
R> se[grepl("rstudio",se,ignore.case=TRUE)]
GIO_LAUNCHED_DESKTOP_FILE        /usr/share/applications/rstudio.desktop
PATH                             [...also redacted...]
RMARKDOWN_MATHJAX_PATH           /usr/lib/rstudio/resources/mathjax-27
RS_RPOSTBACK_PATH                /usr/lib/rstudio/bin/rpostback
RSTUDIO_PANDOC                   /usr/lib/rstudio/bin/pandoc
R> 

这篇关于检查 R 是否在 RStudio 中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆