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

為{幸葍}努か 提交于 2019-11-27 01:15:20

问题


Is there a simple way to programmatically determine if an R script is being executed in Windows vs. Linux?


回答1:


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

}



回答2:


Sys.info()["sysname"]



回答3:


.Platform$OS.type

returns

[1] "unix"

or something else.




回答4:


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.



来源:https://stackoverflow.com/questions/2096473/r-determine-if-a-script-is-running-in-windows-or-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!