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:

 

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.


Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Top