Sys.getenv Function in R (Example) | How to Get Environment Variables
The article consists of the following topics:
Let’s take a look at some R codes in action:
Example: Get Environment Variables Using Sys.getenv() Function
In this example, I’ll illustrate how to return all variables in an environment using the R programming language.
For this task, we can apply the Sys.getenv function as shown below:
my_getenv <- Sys.getenv() # Apply Sys.getenv function head(my_getenv) # First six values of output # ALLUSERSPROFILE C:\ProgramData # APPDATA C:\Users\Joach\AppData\Roaming # CLICOLOR_FORCE 1 # CommonProgramFiles C:\Program Files\Common Files # CommonProgramFiles(x86) C:\Program Files (x86)\Common Files # CommonProgramW6432 C:\Program Files\Common Files
As you can see, the previous R code has created a new data object called my_getenv. The previous RStudio console output shows the first six variables and names stored in this data object.
Video, Further Resources & Summary
Would you like to know more about the application of the Sys.getenv function? Then you may watch the following video on my YouTube channel. In the video, I’m explaining the contents of this tutorial in a live session:
The YouTube video will be added soon.
In addition, you might have a look at the other articles on my website:
- Sys.Date & Sys.time Functions in R
- Sys.chmod Function in R
- System Calls & Commands
- Useful Functions in R (Programming Examples)
- Introduction to R Programming
In summary: At this point you should have learned how to use the Sys.getenv function to return the values of variables in the environment in R. Let me know in the comments below, in case you have additional questions.