A freshly installed version of R-Project can do some pretty nice things already, but much more functionality can be obtained by installing packages that contain new functions. These packages are available by the internet and can be installed from within R-Project. Let’s say we want to use the lme4-package, which can be used to estimate linear and generalized multilevel models. The lme4-package does not come pre-installed with R-Project, so we have to download and install is manually. The way this is done is shown based on an R-installation on windows XP.
Is the package installed?
Before we start to install a package, it is a good custom to check whether or not it is already installed. We start R-project and see the basic screen of the software. Choose ‘Packages’ from the menu’s at the top of the screen. Six options are offered:
- Load Package: This is used to load packages that are already installed
- Set CRAN Mirror: Choose from which server the packages should be downloaded
- Select repositories: Choose CRAN and CRAN (extras)
- Install package(s): Download and install new packages
- Update packages: Download new versions of already installed packages when available
- Install package(s) from local zip files: Used for computers not connected to the internet
By selecting ‘Load Package’ we can check whether the ‘lme4′-package we want is already installed. It appears not to. Click on ‘Cancel’ to return to the main screen of P-Project. Note that some R-syntax is printed in red in the R-Console window. This is the syntax that can be used to manually call for the window to selects packages to load.
Installing the package
Since the lme-package we want is not already installed, we are now going to do this. Select ‘Packages’ from the menu at the top of the screen and then ‘Install Package(s)…’. A window pops up asking us to choose a CRAN-mirror. This is done only once during a session of R-Project. We have to choose where the package will be downloaded from and it is advisable to select one near the location you’re at. I chose ‘Netherlands (Utrecht)’.
After a short while that is needed to download a list of the available packages (internet connection is needed!), a new screen called ‘Packages’ pops forward and allows the user to select a package to install. The length of the list gives an impression of the many packages available and the many ways R-Project can be extended to fit your specific needs. I choose lme4 here and click on ‘OK’. The lme4-package is downloaded and installed automatically and can be activated now. But first: note that in some cases other packages are loaded as well. In this case the Matrix-package is installed, because the requested lme4-package depends on it. This is done to ensure a fully working version of R-Project at all times.
Loading the package
Now, the new package can be loaded and used. As described above, this can be done by clicking on ‘Packages’ on the menu-bar at the top of the screen and then on ‘Load Packages …’. It can be done manually as well using the following syntax:
This loads the package and by default loads the packages it depends on as well if these were not loaded already. In this case, the lattice-package (for trellis graphics) and the Matrix-package are loaded automatically.
– – — — —– ——–
- Discuss this article and pose additional questions in the R-Sessions Forum
- Find the original article embedded in the manual.
– – — — —– ——–
R-Sessions is a collection of manual chapters for R-Project, which are maintained on Curving Normality. All posts are linked to the chapters from the R-Project manual on this site. The manual is free to use, for it is paid by the advertisements, but please refer to it in your work inspired by it. Feedback and topic requests are highly appreciated.
——– —– — — – –