Mon - Fri : 08:00 AM - 5:00 PM
734.544-8038

How Can I Install New R Packages?

How Can I Install New R Packages?

///
Comment0

The vast majority of programs that have been written for R do not come with the default installation, but they can be easily installed from the command prompt or using R’s menus.

To install a new package by pointing-and-clicking through R’s menus in a Windows environment, first go to Packages → Install package(s)….

pack1-119

If a CRAN mirror has not yet been set for the current R session, a list of servers will display.

pack2-120

Choose the nearest mirror and click OK. Next, a list of packages displays. Scroll down and select the package of interest. For example, say you are interested in downloading the sem package for structural equation models. Highlight it, and click on OK.

pack3-121

Use the library function to load the package.

>library(sem)


 

Installing Packages from the R Command Prompt

To install a new package from the command prompt, use the function install.packages with the package name (in quotes) as the argument. For example, to install the sem package for structural equation models, enter:

>install.packages("sem")

If no CRAN mirror has yet been specified, it may be necessary to choose one by entering the number corresponding to the nearest location. One can also use the chooseCRANmirror() function, called without any arguments, to change the preferred server at any time.

Once the new package has been downloaded and installed, use the library function to load it.

Consult the help files for each of these functions for more information.

Still have questions? Contact us!