Using conda to help install R packages


Conda

Conda is a software which could help you to govern your software programming environment. However, if you are not so familiar with conda environment, you could make it a mess for your environment. Here I would like to give some tips and advise to help you use conda.

conda usage

🙌

For most of the beginners, create a new environment in the first place and name would be suggested. And keep in minds that, using conda activate [env-name] to activate the environment.

conda create -n my-env python=x.x
conda activate [env-name]
conda install -c r r-base # install the r packages that is not easily installed through conda

Using jupyter kernel

When you create a new conda environment, you could install ipykernel and IRkernel using the packages in this environments through

python -m ipykernel install --user --name ${name/of/your/kernel}
# install the python kernel in conda env
# use --display-name to set the name of the kernel
# i.e.
python -m ipykernel install --user --name pytorch --display-name "pytorch

and in R
install.packages("IRkernel")
IRkernel::install_spec()

The conda install would install the packages in any environment

conda install r-packages

If you find some packages could not install from CRAN through install.packages() in R, and the warning log says that there is some missing lib you may not install. You could easily fix that if you have sudo authority, however, the install of missing support could not easily if you are not root. So, I encourage to use packages manager tools like conda to achieve that.

When you are encountering some trouble in installation, you could firstly google conda install $packages_name. Usually, the conda channel r could have the packages in repository. And you could easily install it through conda install. And if there are more problems, you may have to search for configuring it through source, but some development support could also be installed through conda. So that, conda could save your life, if you are not roor user.

When you encounter other problems, try install the missing support packages through this way.

conda channels

# unable to execute 'x86_64-conda_cos6-linux-gnu-gcc': No such file or directory 
conda install gxx_linux-64
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

# 以上两条是Anaconda官方库的镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

# 以上是Anaconda第三方库 Conda Forge的镜像

conda config --set show_channel_urls yes

Storage control

After a long period using conda, you may would install too many packages in the default directory. In case you run out of the disk storage, you could move your .conda directory to some where you own enough dist.

# Get the size of current directory
du -sh
# Check the 
/DATA/User/{user}/.conda
# move the directory to antoher directory
mv /DATA/User/{user}/.conda /where/has/enough/dist
ln -s /where/has/enough/dist /DATA/User/{user}/.conda

Then you will not have to change the setting of conda.

Some other problems you can solve using conda

install spateo

fbgbp is a cpython library for belief propagation, and it is very hard to download due to some g++ problems. You may need to upgrade your g++ version and then add the soft link of the g++ in the lib64 directory in your machine or server.

conda install -c conda-forge gcc libgcc
conda install -c conda-forge gxx_linux-64


cd /.../anaconda3/envs/.../bin
ln -s /.../anaconda3/envs/.../bin/x86_64-conda_cos6-linux-gnu-g++ g++

Author: Wulilichao
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Wulilichao !
  TOC