简体   繁体   中英

R: determine if a script is running in Windows or Linux

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

if(.Platform$OS.type == "unix") {
} else {

}
Sys.info()["sysname"]
.Platform$OS.type

returns

[1] "unix"

or something else.

I run the same code from any of three Linux or Windows machines. I use the following to set up working directories:

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

On my debian linux server and my Ubuntu laptop:

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

On my Windows 10 laptop, in RStudio:

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

Feel free to edit and add to this list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM