How to Check Current OS Information in R
Overview
R is frequently used on Linux for various reasons. One notable use case is for handling big data using Hadoop.
Although R itself doesn’t differ much between Windows and Linux, the change in the working environment, including the working directory, can make file I/O operations a bit cumbersome. To easily set the working directory regardless of the environment, it’s necessary to check the current OS.
Sys.info()
To check the current working environment, the Sys.info() function can be used.
Sys.info()
Sys.info()["sysname"]
Below is an example of checking the working environment on Windows. Referring to the “sysname” column of Sys.info()
neatly provides the OS.
Next is an example from Ubuntu. Since Ubuntu is a Linux system, Sys.info()["sysname"]
returns "Linux"
.