R 脚本:确定脚本是在 GUI 中运行还是从命令行运行 [英] R Script: Determine whether the script is run in the GUI or from command line
问题描述
是否可以从脚本中确定脚本是在 R-GUI 中运行(特别是 OS X 上的 R.app)还是从终端/命令行调用(即 R--vanilla -f script.R
)?如果是这样,这怎么可能?
Is it possible to determine - from within the script - whether the script is running in the R-GUI (specifically R.app on OS X) or whether it has been called from Terminal/command line (i.e. R --vanilla -f script.R
)? If so, how is this possible?
我之所以这么问,是因为我有一个可以并行运行的脚本(使用 doMC
库),不应在 GUI 中使用该脚本.有时我需要进一步处理脚本中计算出的数据,所以我想在这些场合从GUI调用脚本.
I'm asking because I have a script that can run parallelized (using the doMC
library), which should not be used from the GUI. Sometimes I need to further process the data calculated in the script, so I'd like to call the script from the GUI on these occasions.
推荐答案
也许您正在寻找 interactive()
?
这篇关于R 脚本:确定脚本是在 GUI 中运行还是从命令行运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!