3.4 Install and open required packages

A package is collection of functions and data sets, which has been developed by advanced users and programmers of the R-community. Packages make working with R a lot easier. In ecology, we often use advanced statistical analysis. Building the functions and required procedures from scratch would require a long list of commands and result in long and complicated scripts. For biologists, packages specifically built for biological/ecological data analysis are of great help. More detailed information about R-packages e.g. from DataCamp tutorials. An overview of all available packages can be found at CRAN.

For AB-202, besides the base packages following with the R and R-studio installations, we are using the following packages: vegan, MASS, OCE. There are loads of packages around, and a lot of analysis can be done with several packages. With time, you’ll find your own preferences.

To install a package you use the command:

[code language=”r”]library("name of package")[/code]

To open the package you use:

[code language=”r”]library("name of package")[/code]

How to install and open packages via code is also explained under R-1-First steps: 5. Installing packages.

In R-studio, you can also install and open packages via a separate tab that manages your package library. You can simply check and uncheck the different packages to open and close them.

To install a library you simply click on the “Install” button and fill in the name of the package you want to install (with autocompletion and the possibility to choose from a drop-down menu). You can also choose where to download it from and the library location to save it to. In most cases you can use the default. If you need to work on the UNIS computers and need a certain package which is not pre-installed, ask the IT-support to install it for you.


I recommend to include the line of code to open your library in your script. The next time you want to do the analysis, you do not have to think about which library was used and open it manually with a click. You can just run the whole script from import of data over opening library to analysis in one go.

  Fant du det du lette etter? Did you find this helpful?
[Average: 0]