Skip to content

Latest commit

 

History

History
159 lines (116 loc) · 4.35 KB

File metadata and controls

159 lines (116 loc) · 4.35 KB

Installing miniconda

We recommend using conda to manage the dependencies. Miniconda is a light-weight version of Anaconda. First we show how to install Miniconda if you don't have it already. More details here

You can skip this step if you already have conda available in your path.

Miniconda for Linux:

curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash ./Miniconda3-latest-Linux-x86_64.sh
rm ./Miniconda3-latest-Linux-x86_64.sh

Miniconda for macOS:

curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
bash Miniconda3-latest-MacOSX-x86_64.sh
rm Miniconda3-latest-MacOSX-x86_64.sh

Miniconda for Windows:

You can follow the instructions (download the exe file) from here: https://docs.conda.io/projects/conda/en/latest/user-guide/install/windows.html

Mamba!

mamba is a very efficient dependency solver. If you don't have it, you can substitute all mamba commands with conda, and it will do the same but slower. You can install it in the base environment with:

conda install mamba -n base -c conda-forge

Working with conda environments

Once we have installed conda/miniconda we are in the base environment. Now, we can create our environment for our first project.

mamba create --name repro36 python=3.6
conda activate repro36
python --version

We can check everything that is installed in the environment with:

conda list

After this command we can see:

# packages in environment at /home/jmoldon/miniconda3/envs/repro36:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main  
_openmp_mutex             4.5                       1_gnu  
ca-certificates           2022.3.29            h06a4308_0  
certifi                   2020.6.20          pyhd3eb1b0_3  
ld_impl_linux-64          2.35.1               h7274673_9  
libffi                    3.3                  he6710b0_2  
libgcc-ng                 9.3.0               h5101ec6_17  
libgomp                   9.3.0               h5101ec6_17  
libstdcxx-ng              9.3.0               hd4cf53a_17  
ncurses                   6.3                  h7f8727e_2  
openssl                   1.1.1n               h7f8727e_0  
pip                       21.2.2           py36h06a4308_0  
python                    3.6.13               h12debd9_1  
readline                  8.1.2                h7f8727e_1  
setuptools                58.0.4           py36h06a4308_0  
sqlite                    3.38.2               hc218d9a_0  
tk                        8.6.11               h1ccaba5_0  
wheel                     0.37.1             pyhd3eb1b0_0  
xz                        5.2.5                h7b6447c_0  
zlib                      1.2.12               h7f8727e_1  

We can install any software available in anaconda.org with a simple command. For example:

mamba install matplotlib

When we need to work on a different project, we can create new environments with their specific requirements

mamba create --name r_3.5 --channel r r=3.5.1 r-essentials
conda activate r_3.5

Remember that some packages come from specific channels like conda-forge, r, bioconda, etc.

We can even install the pip package manager:

mamba install pip

Using environments

The best practice is to store all the main dependencies in an environment file:

Contents of file environment.yml:

name: r-env
  
channels:
- conda-forge
- bioconda
- defaults

dependencies:
- r-base=4.1.3
- r-reshape2=1.4.4
- r-ggplot2=3.3.5
mamba env create -f environment.yml

Now we can access the environment with:

conda activate r-env

We can now execute a script with R:

Rscript script.r

Automatically created environment file

If you want to see what you installed manually, you can do:

conda activate repro36
conda env export --from-history

If you want the full details of all the dependencies:

conda env export

Remove environment

We can easily remove any environment created (you may need to deactivate it first).

conda env remove -n r_3.5

Let's save our analysis in Github

  • Create repository
  • Add environment.yml, script.r, ouput.png, README with instruction