Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In this page:

Table of Contents


...


This article outlines details about installing R packages in IDAS. We also recommend using tools like conda and Python virtual environments in IDAS to manage your projects.

...

Code Block
install.packages(c("PACKAGE_NAME_1", "PACKAGE_NAME_2", ...), repos="http://cran.r-project.org")


For more information about the  install.packages() function, type the following in the Console tab in RStudio:

Code Block
?install.packages

That will display the documentation in the Help tab in RStudio:

...

Switching to a Newer Version of R in IDAS

If you want to switch to using a newer version of R in IDAS for the first time, for example, from R 4.1 to R 4.2, you will need to:

1. Double check and set your user library path using .libPaths() in R.  For more details, please see the section Setting (Changing) the User Library Path below. 

2. After you have done step 1 above, you will need to reinstall any R packages that you need for each the newer version of R that you useare switching to. After you have set the user library path as in step 1 above, you can install packages with install.packages() in R as usual.

R Library Path in IDAS

Getting (Viewing) the Library Paths in IDAS

In IDAS, R looks for packages in 2 locations: a) the user library and b) the system library.

You can view the paths to these libraries by typing the following code in R:

Code Block
.libPaths()


The screenshot below shows the output of the .libPaths() function. The output shows 2 paths:

  • "/home/grudderham/R/x86_64-pc-linux-gnu-library/4.1" is the user library.

  • "/opt/R/lib/R/library" is the system library.

...

More About the User Library

The path to the R user library in IDAS is:

Code Block
/home/HAWKID/R/x86_64-pc-linux-gnu-library


Any IDAS user can install R packages in their personal user library. The screenshot below shows the location of the user library, as seen in the Files tab in RStudio. For each version of R, a folder is created to store the packages for that version. For example, the folder 3.6 contains the packages that have been installed for R version 3.6.1:

...

Setting (Changing) the User Library Path

The .libPaths() function can also be used to set the library path where R looks for packages. You may need to do this if you are switching to a newer R version in IDAS for the first time.

...

1. After you log in to IDAS and select an IDAS instance with R 4.2.2, use .libPaths() to check the library paths:Image Removed

...

2. The output above shows that R is still looking for packages in the 4.1 folder. We can also check the "~/R/x86_64-pc-linux-gnu-library" folder to see if a 4.2 folder has been created automatically:Image Removed

...

3. If a 4.2 folder has not been created automatically as in the above screenshot, we can create it by typing the following command in the Console tab in RStudio:

Code Block
dir.create("~/R/x86_64-pc-linux-gnu-library/4.2")

4. After running the command, a 4.2 folder will be created:Image Removed

...


5. Next, use .libPaths() to change the user library path to the new folder. Run the following in RStudio:

Code Block
 .libPaths("~/R/x86_64-pc-linux-gnu-library/4.2")

...

6. Finally, use .libPaths() again to double check the library paths. In the screenshot below, the user library path has been changed to the 4.2 folder. The system library path has not been changed:Image Removed

...


7. You can now install packages in R version 4.2.2 as usual.

For example, install the "XML" package:

> install.packages(“XML”)

If you want to be sure, you can also specify exactly where you want to install packages by using the “lib” argument:

> install.packages("XML", lib = "~/R/x86_64-pc-linux-gnu-library/4.2")

Then load the package as usual:

> library(XML)

More About the System Library

...

The instructor also has their own user library. Please see the sections on R Library Paths in IDAS above.

Important: Sometimes a package that is installed in the global library might use dependencies from the instructor's personal library. In that case, the students might have trouble loading the package even though it looks like the package is already installed in the global library. Therefore, instructors please make sure that you install all packages in the global library so all dependencies are available there for students.

...

If you have any questions or comments, please contact ITS contact ITS - Research Services at research-computing@uiowa.edu.