Sys.getenv Function in R (Example) | How to Get Environment Variables
In this R tutorial you’ll learn how to use the Sys.getenv function to obtain the values of 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.
Subscribe to the Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Welcome to the Statistics Globe newsletter. From now on, I’ll send you regular emails about statistics, data science, AI, and programming with R and Python.
I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.
Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Please check your email inbox and click the confirmation link to complete your subscription. If you don’t see the email within a few minutes, please also check your spam/junk folder.






