【问题标题】:Get host computer information from within R code从 R 代码中获取主机信息
【发布时间】:2015-09-03 20:44:33
【问题描述】:

我想从 R 代码中获取主机信息。对于我的机器设置程序,脚本部分的初始设置略有不同,具体取决于所使用的机器,我需要阅读这些信息才能知道该怎么做。例如,我必须这样做:

if( isServer() ) {
  resultsDir <- "U:\\Share\\Results\\"
  maxIterations <- 1000
} else {
  resultsDir <- "D:\\Temp\\"
  maxIterations <- 50
}

我在本地用的是Win7,另一台机器是Win 2008 Server。

【问题讨论】:

    标签: r windows server


    【解决方案1】:

    您可以使用Sys.info。在我的系统上:

    Sys.info()
    #  sysname                      release                      version                     nodename                      machine                  </snip>
    #"Windows"                      "7 x64" "build 7601, Service Pack 1"                        "***"                     "x86-64"                  </snip>
    

    【讨论】:

    • 对,如果你这样做Sys.info()["release"],你会得到“7 x64”,所以你应该可以在你的控制结构中使用这个值。
    • 谢谢,这正是我想要的。
    【解决方案2】:

    R 获取当前计算机的主机名

    get_hostname <- function(){ 
        return(as.character(Sys.info()["nodename"])) 
    } 
    print(get_hostname())   #prints this computer's hostname
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-09
      • 1970-01-01
      • 2022-12-24
      • 2016-06-15
      • 2012-02-18
      • 1970-01-01
      相关资源
      最近更新 更多