system.file Function in R (2 Examples)
In this R post you’ll learn how to find the names of system files using the system.file function.
Table of contents:
Here’s how to do it.
Example 1: Find System Files of Base R Using system.file() Function
This section shows how to apply the system.file function to return the root of the base R package.
For this, we simply have to execute the system.file command without any additional specifications:
system.file() # Apply system.files function #  "C:/PROGRA~1/R/R-41~1.0/library/base"
As you can see based on the previous output of the RStudio console, we have returned the path to the base R package on my computer.
Example 2: Find System Files of Certain Package Using system.file() Function
The following R programming code illustrates how to return the path to a particular add-on package.
In this example, we’ll return the root of the dplyr package:
system.file( = "dplyr") # Apply system.files function #  "C:/Users/Joach/Documents/R/win-library/4.1/dplyr"
Video, Further Resources & Summary
Have a look at the following video on my YouTube channel. In the video, I’m explaining the R codes of this page in R.
The YouTube video will be added soon.
Furthermore, you may want to read some of the other R posts on this website. A selection of posts that are related to the application of the system.file function is shown below:
- Create Directory & File Path in R
- Extract File & Directory Name from Path
- Change Default Time Zone in R
- Introduction to System Calls & Commands
- List of R Functions (Programming Examples)
- All R Programming Examples
You have learned in this tutorial how to find the root of packages and files using the system.file function in R. In case you have any further questions, let me know in the comments below. Furthermore, don’t forget to subscribe to my email newsletter for updates on new tutorials.