# Install R and Python packages from the local Sandbox repository

Users can install R and Python packages from the local Sandbox repository.&#x20;

{% hint style="info" %}
Users can request new packages to be added to the local Sandbox repository ([please see policy](https://finngen.gitbook.io/finngen-handbook/working-in-the-sandbox/quirks-and-features/sandbox-ivm-tool-request-handling-policy)).
{% endhint %}

## R packages

### List R packages available in the local Sandbox CRAN repository using R

The Sandbox IVM has been pre-configured to use the local Sandbox CRAN repository. The `available.packages()` R command can be used to list the available packages in the local Sandbox CRAN repository.

Use the following command to list all available packages and their versions:

```
available.packages()[,c("Package","Version")]
```

You can search available packages by name. For example, use the following command to list all packages that start with 'Bi':

```
p <- available.packages()[,c("Package", "Version")] 
c <- grepl("^Bi", p[,c("Package")], ignore.case=TRUE) 
p[c,]
```

The `available.packages()`command returns other columns as well. You can list them all using the `colnames` command:

```
colnames(available.packages())
```

### List R packages available in the local Sandbox CRAN repository using the terminal

You can list packages using the `R` command line program with the `-e` option following other instructions in the previous section.

List all packages:

```
R -e 'available.packages()[,c("Package","Version")]'
```

Search packages by name:

```
R -e 'p <- available.packages()[,c("Package", "Version")];c <- grepl("^Bi", p[,c("Package")], ignore.case=TRUE);p[c,]'
```

You can also directly list the packages in the local Sandbox CRAN repository:

```
ls /usr/finngen-repos/cran/source/src/contrib
```

### Install R packages from the local Sandbox CRAN repository

The Sandbox IVM has been pre-configured to use the local Sandbox CRAN repository. Use the `install.packages("package name")` R command to install packages from the local Sandbox CRAN repository.

For example, the following command installs the Biobase package:

```
install.packages("Biobase")
```

{% hint style="info" %}
Packages are installed in your Sandbox IVM persistent disk. The exact location depends on the R version, for example, /home/ivm/Rx86\_64-pc-linux-gnu-library/4.3. Installed packages are automatically detected by R only from this location. When using a different version of R, you may need to use the .libPaths() variable to define the location of the package (more information is available [here).](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/libPaths) You can also install the same package for different R versions.
{% endhint %}

### List available R packages in the local Sandbox CRAN repository outside the Sandbox

It is possible to list the available R packages outside Sandbox by using buckets.

R packages are available in the following bucket:

```
gs://fg-production-master_cran/source/src/contrib
```

You can see the contents of the bucket using the cloud console:

<https://console.cloud.google.com/storage/browser/fg-production-master_cran/source/src/contrib;tab=objects?project=fg-production-master>

or the `gsutil` command line program:

```
gsutil ls gs://fg-production-master_cran/source/src/contrib
```

## Python packages

### List Python packages available in the local Sandbox PyPI repository using the terminal

The Sandbox IVM has been pre-configured to use the Sandbox PyPI repository on GCP Artifact Registry: <https://europe-west1-python.pkg.dev/finngen-sandbox-v3-containers/pypi/simple/>. It contains packages for Python 3. FinnGen uses the `pip` program to install Python packages in the Sandbox.

Use the following command to list available Python 3 packages:

```
python3 -m pip list --index-url https://europe-west1-python.pkg.dev/finngen-sandbox-v3-containers/pypi/simple/
```

### Install Python packages from the local Sandbox PyPI repository using the terminal

Use the following command to install a Python 3 package:

```
python3 -m pip install <packagename>
```

{% hint style="info" %}
You can also install Python packages in virtual environments. Instructions on how to create a virtual environment are available [here](https://finngen.gitbook.io/finngen-handbook/working-in-the-sandbox/quirks-and-features/python-virtual-environment-in-sandbox).
{% endhint %}

{% hint style="info" %}
Python lmod modules with preinstalled scientific python packages are available in the sandbox. You can read about them [here](/working-in-the-sandbox/which-tools-are-available/anaconda-python-module-with-ready-set-of-scientific-packages.md).
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.finngen.fi/working-in-the-sandbox/quirks-and-features/r-and-python-local-repositories-in-finngen-sandbox.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
