Skip to content

Commit

Permalink
Merge pull request #318 from csc-training/r-lists-fix
Browse files Browse the repository at this point in the history
fix list numbering in r installing tutorial
  • Loading branch information
rkronberg authored Feb 6, 2024
2 parents 627d9d8 + 4c34962 commit ffefb82
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions part-2/installing/r.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,71 +13,71 @@ permalink: /hands-on/installing/installing_hands-on_r.html

💬 A pre-installed R environment is available on Puhti.

1. To check available module versions, run:
1. To check available module versions, run:

``` bash
module spider r-env
```
``` bash
module spider r-env
```

2. There are several ways to use R in `r-env` on Puhti:

- Interactive jobs on a compute node, using either the R console or RStudio\
💡 The easiest way to launch RStudio is to use the Puhti web interface at [www.puhti.csc.fi](https://www.puhti.csc.fi/)
- Non-interactive batch jobs
- Interactively on the login node, using the R console (**only** for moving data, checking package availability, installing packages)
- Interactive jobs on a compute node, using either the R console or RStudio
💡 The easiest way to launch RStudio is to use the Puhti web interface at [www.puhti.csc.fi](https://www.puhti.csc.fi/)
- Non-interactive batch jobs
- Interactively on the login node, using the R console (**only** for moving data, checking package availability, installing packages)

For example, to launch the R console in an interactive job, open a shell with `sinteractive` and then
For example, to launch the R console in an interactive job, open a shell with `sinteractive` and then

``` bash
module load r-env
start-r
```
``` bash
module load r-env
start-r
```

💡 See the [r-env documentation](https://docs.csc.fi/apps/r-env/) for further instructions on different ways to launch R on Puhti.

💬 It is also possible to [install R packages yourself](https://docs.csc.fi/apps/r-env/#r-package-installations).

- However, check first if what you need is already available in `r-env`. The module contains more than 1300 R packages! The easiest way to check if a package is available is trying to load it with the command `library(packagename)`.
☝🏻 However, check first if what you need is already available in `r-env`. The module contains more than 1300 R packages! The easiest way to check if a package is available is trying to load it with the command `library(packagename)`.

#### How to install an R package on Puhti
## How to install an R package on Puhti

- Note that your own package installations are:
- project specific
- R version specific
- located in the `/projappl` directory of your project
- Note that your own package installations are:
- project specific
- R version specific
- located in the `/projappl` directory of your project

1. Create a folder for your R packages in `/projappl` (open a login node shell in the [Puhti web interface](https://www.puhti.csc.fi/) or log in to Puhti with SSH):

``` bash
# First navigate to /projappl/<project>, then
mkdir project_rpackages_<rversion>
```
``` bash
# First navigate to /projappl/<project>, then
mkdir project_rpackages_<rversion>
```

2. Start an R session (launch RStudio in the [Puhti web interface](https://www.puhti.csc.fi/) or launch the R console in an interactive shell session: start the job with `sinteractive` -\> `module load r-env` -\> `start-r`). In R, add the folder you created above to the list of directories where R will look for packages:

``` r
.libPaths(c("/projappl/<project>/project_rpackages_<rversion>", .libPaths()))
```
``` r
.libPaths(c("/projappl/<project>/project_rpackages_<rversion>", .libPaths()))
```
Assign `libpath` to point to this directory (not strictly necessary but can make life easier):
Assign `libpath` to point to this directory (not strictly necessary but can make life easier):
``` r
libpath <- .libPaths()[1]
```
``` r
libpath <- .libPaths()[1]
```
3. Install the package (again, defining `lib = libpath` to specify the installation location is not strictly necessary but recommended)
``` r
install.packages("packagename", lib = libpath)
```
``` r
install.packages("packagename", lib = libpath)
```
For example, you can try installing a package called `beepr` with
For example, you can try installing a package called `beepr` with
``` r
install.packages("beepr", lib = libpath)
```
``` r
install.packages("beepr", lib = libpath)
```
Finished! The R package is now ready to be loaded and used. Try loading `beepr` with `library(beepr)`.
Finished! The R package is now ready to be loaded and used. Try loading `beepr` with `library(beepr)`.
💡 The package location is defined only for the current R session! R has to be reminded of the location at the start of every R session or script where you want to use the project-specific package by running this command again:
Expand All @@ -87,6 +87,6 @@ Finished! The R package is now ready to be loaded and used. Try loading `beepr`
💡 Instead of installing a missing package for your own project, you can ask for a module-wide installation for all users by contacting [CSC Service Desk](mailto:[email protected])
#### More information
## More information
💡 Read more about using R on Puhti in [r-env documentation](https://docs.csc.fi/apps/r-env/) in Docs CSC.

0 comments on commit ffefb82

Please sign in to comment.