Table of Contents
The R language is a familiar concept for students who are learning to code and programmers. When learning about R, installing packages is a necessary skill to be able to make full use of its functions. So in this article we will show you “How to install packages in r“. This will help you to develop a more research-oriented mindset, and make it easier for you to answer these types of questions. Let’s check out!
What are Packages in R?
Packages include R functions, data, and compiled code in a well-defined format. R comes with a set of standard packages. Users can download and install available packages.
How to install packages in R?
Installing packages in R is quite simple. Below we will give you 2 easiest ways to install them. If you know the package to be installed is available on CRAN and know the name, you can choose method 1. In case, some packages are not available in the CRAN repository, we need to download it before proceeding to open this dialog box. Follow along and choose the method that is right for you.
Method 1: Install the package by CLick ( using CRAN)
Start the R software and from the main interface, select the menu Packages/Install package(s)…
The dialog box appears like below:
Next you will choose the CRAN mirror and press OK. When the menu appears, drag and select the package you need to install
Then the machine will automatically run your package of choice and here is an example when it shows you:
Method 2: Install the package by typing the command
You will still have to start R first. Then its control box will appear.
To install the package you would type into the R console in the following form:
install.packages("package_name")
For example, you need to install the writexl package, so the command will look like this:
install.packages ("writexl")
Then select press enter to install.
After successfully installing the package. Every time you start R software and start working with any package, you need to “call” that package with the following syntax:
library("name of package")
Example like below:
library("writexl")
In addition, you can also install multiple packages at once. For example the following:
install.packages(c("Vector", "Math"))
So you already know 2 ways to install packages in R.
Conclusion
In conclusion, above we have helped you better understand the concept of packages in R and detailed instructions on how to install packages. Hopefully, through the article “How to install packages in r” you can manipulate and install your own package yourself. If you have any further questions, you can leave your comments in the Comments section. I hope you have a productive day with your subject. See you in the next session!
Leave a comment