In this page:
Table of Contents |
---|
...
This article outlines Below are some basic ways to install packages in Python, R, and Juliadetails about installing R packages in IDAS. We also strongly recommend using tools like conda and Python virtual environments in IDAS to manage your projects.
Installing R Packages in IDAS - The Basics
To install R packages in IDAS, use the install.packages()
function. For example, you can run the following code in the Console tab in RStudio, in an R script file, or in a Jupyter Notebook:
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 the newer version of R that you are 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:
...
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:
...
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:
...
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. The In the screenshot below, the user library path has been changed to the 4.2 folder. The system library path has not been changed:
...
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 system library contains packages that are installed by IDAS systems administrators. These packages are available to all IDAS users. In most cases, IDAS users will do not have permissions to install R packages to the system library.
For Class Instructors - Installing R Packages for All Students in the Class
The instructor of a class may request to have permissions to install R packages to the global library for their class. Packages installed in the global library for that class will be available to all students enrolled in the class.
...
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 pull use dependencies from the instructor's personal library. In that case, the students might have trouble loading the package even though it looks like it’s 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 in available there for students.
You can check which packages are installed in the global library by typing the following in the Terminal (next to the Console tab in RStudio):
...
Code Block |
---|
ls -a ~/R/x86_64-pc-linux-gnu-library/4.2 |
Contact
If you have any questions or comments, please
...
contact ITS - Research Services at research-computing@uiowa.edu.