【问题标题】:Is there a way to determine if an R program was run from the command line? [duplicate]有没有办法确定 R 程序是否从命令行运行? [复制]
【发布时间】:2019-11-08 13:11:02
【问题描述】:

我希望控制流根据调用 R 程序的位置而有所不同。类似的东西

if (called_from == 'GUI') {
print('Hello GUI')} else {
print('Hello command line')
}

这可能吗?如果有,请提供尽可能多的详细信息。

【问题讨论】:

  • 您可以使用interactive()。如果为 TRUE,则代码可能正在 GUI 中运行,如果为 FALSE,则可能正在命令行中运行。有关详细信息,请参阅?interactive 帮助页面。

标签: r


【解决方案1】:
if (interactive()) {
  print('Hello GUI')
} else {
  print('Hello command line')
}

【讨论】:

    猜你喜欢
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 2019-12-31
    相关资源
    最近更新 更多