代码之家  ›  专栏  ›  技术社区  ›  JD Long

r:确定脚本是在Windows还是Linux中运行

  •  30
  • JD Long  · 技术社区  · 15 年前

    有没有一种简单的方法可以通过编程确定是否在Windows和Linux中执行R脚本?

    4 回复  |  直到 6 年前
        1
  •  35
  •   Marek    13 年前
    if(.Platform$OS.type == "unix") {
    } else {
    
    }
    
        2
  •  11
  •   rcs    15 年前
    Sys.info()["sysname"]
    
        3
  •  8
  •   Marek    13 年前
    .Platform$OS.type
    

    收益率

    [1] "unix"
    

    或者别的什么。

        4
  •  7
  •   Mus mzuba    6 年前

    if(R.Version()$os == "linux-gnu"){
      dir.pre <- "/home"
    } else {
      dir.pre <- "C:/Users"
    }
    

    > .Platform$OS.type
    [1] "unix"
    > R.Version()$os
    [1] "linux-gnu"
    

    > .Platform$OS.type
    [1] "windows"
    > R.Version()$os
    [1] "mingw32"