I have a very basic question.
I want to set the working directory based on the OS the Rstudio is running(MAC, Windows). Can you please suggest on how to use getwd()
and setwd()
for getting this done ? What functions can give OS details in R ?
I have a very basic question.
I want to set the working directory based on the OS the Rstudio is running(MAC, Windows). Can you please suggest on how to use getwd()
and setwd()
for getting this done ? What functions can give OS details in R ?
You can get the OS details by simply type Sys.info()
at the console. I don't have access to R currently but I think the answer should be like this:
a = Sys.info()[1]
if( a == "Windows") { set the working dir in windows}
if( a != "Windows") { set the working dir in other OS}
Sys.info()
returns a vector containing the following values which you can find also in the help by ?Sys.info
:
sysname
The operating system name.
release
The OS release.
version
The OS version.
nodename
A name by which the machine is known on the network (if any).
machine
A concise description of the hardware, often the CPU type.
login
The user s login name, or "unknown" if it cannot be ascertained.
user
The name of the real user ID, or "unknown" if it cannot be ascertained.
effective_user
The name of the effective user ID, or "unknown" if it cannot be ascertained. This may differ from the real user in ‘set-user-ID’ processes.
You can return the first element for OS name.