热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

检查R是否在RStudio中运行-CheckifRisrunninginRStudio

IamlookingforawaytotestifRisbeingrunfromRStudio.ForsomereasonIcouldfindtheansw

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.

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

9 个解决方案

#1


8  

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.

没有“在RStudio内部运行”。 RStudio只是一个环绕R的IDE层;在一天结束时,它只是启动您需要在$ PATH上运行RStudio的正常R可执行文件。

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 Studio您可以测试'manipulate'包的available.packages(),或者作为更短的版本,看看RStudio是否将自己添加到.libPath()内容中:

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

#2


31  

This is from ?rstudio:

这是来自?rstudio:

# Test whether running under RStudio 
isRStudio <- Sys.getenv("RSTUDIO") == "1"

There is also rstudioapi::isAvailable(), but checking this is not as reliable because RStudio doesn't seem to really need the rstudioapi package to work correctly.

还有rstudioapi :: isAvailable(),但检查这个并不可靠,因为RStudio似乎并不真正需要rstudioapi包才能正常工作。

#3


6  

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时,似乎有工具:rstudio在搜索路径的第2位。这有一个函数“RStudio.version”,它没有文档但似乎返回RStudio版本字符串:

> 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.

也许使用它。

#4


6  

Check the .Platform$GUI option for "RStudio"

检查“RStudio”的.Platform $ GUI选项

is.rstudio = function(){
  .Platform$GUI == "RStudio"
}

See:

看到:

http://thecoatlessprofessor.com/programming/detecting-if-r-is-in-rstudio-and-changing-rstudios-default-graphing-device/

http://thecoatlessprofessor.com/programming/detecting-if-r-is-in-rstudio-and-changing-rstudios-default-graphing-device/

#5


3  

To add to the number of nice guesses, here is a message from 2011 (Ice Age)

为了增加猜测的数量,这里有一条来自2011年(冰河世纪)的消息

http://support.rstudio.org/help/discussions/problems/413-location-of-installed-packages

http://support.rstudio.org/help/discussions/problems/413-location-of-installed-packages

if (Sys.getenv("RSTUDIO_USER_IDENTITY")!= ""){
.libPaths(.Library) # Avoid additional libraries } else { # not rstudio ...

#6


2  

I find the following works for me

我发现以下作品适合我

checkRstudio <- function () {
  return ("tools:rstudio" %in% search())
}

I am sort of new to R myself, but I believe Rstudio necessarily loads the package "tools:rstudio" in order to run.

我对R本人有点新意,但我相信Rstudio必须加载“tools:rstudio”软件包才能运行。

#7


2  

As of today, there are a few packages which include functions to check whether RStudio is running:

截至今天,有一些软件包包含检查RStudio是否正在运行的函数:

rstudioapi::isAvailable()
assertive::is_rstudio()

(list is non-exhaustive)

(清单不详尽)

The assertive and assertive.reflections packages, resp., do include additional functions to check for other IDEs, desktop/server versions of RStudio, and various R releases (e.g., alpha, beta, devel, release, patched, etc.)

assertive和assertive.reflections包,包括其他功能,以检查其他IDE,桌面/服务器版本的RStudio和各种R版本(例如,alpha,beta,devel,release,patched等)

#8


0  

On a Mac only the Sys.getenv answer works

在Mac上只有Sys.getenv的答案有效

platform x86_64-apple-darwin10.8.0
version.string R version 3.1.0 (2014-04-10)

平台x86_64-apple-darwin10.8.0 version.string R版本3.1.0(2014-04-10)

Sys.getenv("RSTUDIO")=="1" [1] TRUE

Sys.getenv(“RSTUDIO”)==“1”[1] TRUE

RStudio.version() Error: could not find function "RStudio.version"

RStudio.version()错误:找不到函数“RStudio.version”

any(grepl("RStudio", .libPaths())) [1] FALSE

any(grepl(“RStudio”,。libibss()))[1] FALSE

.libPaths() [1] "/Library/Frameworks/R.framework/Versions/3.1/Resources/library"

.libPaths()[1]“/ Library / Frameworks / R.framework / Version / 3.1 / Resources / library”

#9


0  

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

现在可以通过is_rstudio_console函数通过启动包获得整洁的解决方案:

startup:::is_rstudio_console()
[1] TRUE

推荐阅读
  • 本文介绍了如何使用PHP向系统日历中添加事件的方法,通过使用PHP技术可以实现自动添加事件的功能,从而实现全局通知系统和迅速记录工具的自动化。同时还提到了系统exchange自带的日历具有同步感的特点,以及使用web技术实现自动添加事件的优势。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文介绍了Perl的测试框架Test::Base,它是一个数据驱动的测试框架,可以自动进行单元测试,省去手工编写测试程序的麻烦。与Test::More完全兼容,使用方法简单。以plural函数为例,展示了Test::Base的使用方法。 ... [详细]
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • 本文介绍了一些好用的搜索引擎的替代品,包括网盘搜索工具、百度网盘搜索引擎等。同时还介绍了一些笑话大全、GIF笑话图片、动态图等资源的搜索引擎。此外,还推荐了一些迅雷快传搜索和360云盘资源搜索的网盘搜索引擎。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 关键词:Golang, Cookie, 跟踪位置, net/http/cookiejar, package main, golang.org/x/net/publicsuffix, io/ioutil, log, net/http, net/http/cookiejar ... [详细]
  • Android系统移植与调试之如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏
    本文介绍了如何修改Android设备状态条上音量加减键在横竖屏切换时的显示与隐藏。通过修改系统文件system_bar.xml实现了该功能,并分享了解决思路和经验。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • Ihavethefollowingonhtml我在html上有以下内容<html><head><scriptsrc..3003_Tes ... [详细]
  • Java自带的观察者模式及实现方法详解
    本文介绍了Java自带的观察者模式,包括Observer和Observable对象的定义和使用方法。通过添加观察者和设置内部标志位,当被观察者中的事件发生变化时,通知观察者对象并执行相应的操作。实现观察者模式非常简单,只需继承Observable类和实现Observer接口即可。详情请参考Java官方api文档。 ... [详细]
  • Python爬虫中使用正则表达式的方法和注意事项
    本文介绍了在Python爬虫中使用正则表达式的方法和注意事项。首先解释了爬虫的四个主要步骤,并强调了正则表达式在数据处理中的重要性。然后详细介绍了正则表达式的概念和用法,包括检索、替换和过滤文本的功能。同时提到了re模块是Python内置的用于处理正则表达式的模块,并给出了使用正则表达式时需要注意的特殊字符转义和原始字符串的用法。通过本文的学习,读者可以掌握在Python爬虫中使用正则表达式的技巧和方法。 ... [详细]
  • CEPH LIO iSCSI Gateway及其使用参考文档
    本文介绍了CEPH LIO iSCSI Gateway以及使用该网关的参考文档,包括Ceph Block Device、CEPH ISCSI GATEWAY、USING AN ISCSI GATEWAY等。同时提供了多个参考链接,详细介绍了CEPH LIO iSCSI Gateway的配置和使用方法。 ... [详细]
  • (三)多表代码生成的实现方法
    本文介绍了一种实现多表代码生成的方法,使用了java代码和org.jeecg框架中的相关类和接口。通过设置主表配置,可以生成父子表的数据模型。 ... [详细]
  • Android系统源码分析Zygote和SystemServer启动过程详解
    本文详细解析了Android系统源码中Zygote和SystemServer的启动过程。首先介绍了系统framework层启动的内容,帮助理解四大组件的启动和管理过程。接着介绍了AMS、PMS等系统服务的作用和调用方式。然后详细分析了Zygote的启动过程,解释了Zygote在Android启动过程中的决定作用。最后通过时序图展示了整个过程。 ... [详细]
author-avatar
_______王晓
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有