0

I need to set up different paths for my code depending on whether it is being run in windows or unix. I currently have it set up so that the user has to change a variable "Renvironment" before running, as below.

Renvironment <- "windows"

if (Renvironment == "windows") {
  working_dir <- "windows_path..."
  function_library <- "windows_path..."
} else if (Renvironment == "unix") {
  working_dir <- "unix_path..."
  function_library <- "unix_path..."
}

I was wondering though whether there are default R environment variables that I can use instead to save the user having to remember to manually change the variable?

Sam Gilbert
  • 1,642
  • 3
  • 21
  • 38

1 Answers1

6

The command .Platform returns details of the platform. You can access the information about the operating system with

.Platform$OS.type

This returns either "unix" or "windows".

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168