In this tutorial, we will discover how to install an R package and how to select a CRAN mirror in R. After its installation is completed, we will follow to call the R package in R console.

Check Out: How to Download and Install R for Windows

How to Install a Package in R

We use install.packages() function to install a package in R. We need to write the name of package in double quotes. After this step, a window opens to select a mirror. You may choose a mirror closer to your geographic location. As an example, we install onewaytests package (Dag et al., 2018) in R.


When the window opens to select a mirror, we select 0-Cloud (automatic redirection to servers worldwide). You may select a mirror closer to your location.

Also Check: How to Change Working Directory in R

How to Specify a CRAN Mirror in R

You can also specify the mirror in install.packages() function. In this way, you do not need to choose a mirror from mirror selection window. We can use repos argument for specification of the mirror.

Since we are interested to install the onewaytests package in our case, then you need to type this command in the R console:

install.packages("onewaytests", repos = "")

In our case, we choose 0-Cloud. For this purpose, we write its url. You can select your nearest mirror from the list of mirrors here.

We can also specify any other mirror. For example, let’s specify the mirror placed in Iowa State University, Ames, IA.

install.packages("onewaytests", repos = "")

Also Check: How to Clean Data in R

How to Load a Package in R

When the installation is completed, you can load the package in R console with library() function. We load onewaytests package in R console as an example.


Don’t forget to check: How to Import Data into R


Dag, O., Dolgun, A., Konar, N.M. (2018). onewaytests: An R Package for One-Way Tests in Independent Groups Designs. R Journal, 10(1), 175-199.