rnorouzian
rnorouzian

Reputation: 7517

Can R know if it is running on Windows or not?

I was wondering if there might be a logical test in R to evaluate whether R is Running under a "Windows" (win) OS or not?

What is this for:

if("OS is windows") { ## Here is the logical test I need !!!

  setwd("~/../Desktop")  

  } else {

  setwd("~") }          


x <- paste0(getwd(),"/", "Animation")
dir.create(x)

Upvotes: 1

Views: 369

Answers (1)

austensen
austensen

Reputation: 3007

Here is a function that might help:

https://github.com/hadley/rappdirs/blob/master/R/utils.r#L1

    get_os <- function() {
  if (.Platform$OS.type == "windows") { 
    "win"
  } else if (Sys.info()["sysname"] == "Darwin") {
    "mac" 
  } else if (.Platform$OS.type == "unix") { 
    "unix"
  } else {
    stop("Unknown OS")
  }
}

Upvotes: 4

Related Questions