Skip to content

Instantly share code, notes, and snippets.

@Naeemkh
Last active March 25, 2022 14:55
Show Gist options
  • Save Naeemkh/2101be800f9ea51771be979118a00c86 to your computer and use it in GitHub Desktop.
Save Naeemkh/2101be800f9ea51771be979118a00c86 to your computer and use it in GitHub Desktop.
R conda env on RCE including lme4 package

Steps for setting up R environment including nloptr and lme4 packages

  • Step 1: Request for a powershell terminal.

Using nomachine:

  • Select Applications tab
  • Select RCE Powered Applications
  • Select Anaconda Shell (Python 3.6) 5.2.0
  • Select required number of cores and RAM

This will open a terminal.

  • Step 2: Make sure that conda is installed. Run:
which conda

If conda is installed, the command should return a path. For example:

/nfs/tools/lib/anaconda/3-5.2.0/bin/conda
  • Step 3: Under your user account, create .conda folder. For example, my account name is nak443 and my .conda folder is located in the following path:
nfs/home/N/nak443/shared_space/ci3_nak443/.conda
  • Step 4: Under the .conda folder, create pkgs and envs folders.
  • Step 5: Export the path of these folders. In my case, it will be:
export CONDA_PKGS_DIRS=/nfs/home/N/nak443/shared_space/ci3_nak443/.conda/pkgs
export CONDA_ENVS_PATH=/nfs/home/N/nak443/shared_space/ci3_nak443/.conda/envs
  • Step 6: Take a look at the current environment:
conda env list

If your environment is already exist, move to step xyz.

  • Step 7: Create a recipe for environment. For example this is r_env.yaml file content. You can put the library version infront of the library name and make the environment more customized.
name: r_env
channels:
  - conda-forge
  - anaconda
dependencies:
  - r-base=4.1
  - r-tidyverse
  - r-devtools
  - r-xgboost
  - r-superlearner
  - r-earth
  - r-ranger
  - r-gam
  - r-kernsmooth
  - r-gnm
  - r-polycor
  - r-wcorr
  - r-rlang
  - r-glue
  - r-logger
  - r-cli
  - python
  - cmake
  - jupyterlab
  - jupyter_client
  • Step 8: Create your environment.
conda env create -n r_env -f r_env.yaml
  • Step 9: Activate your environment.
conda activate r_env
  • Step 10: Start an R session.
R
  • Step 11: Install IRkernel and register kernel in jupyter lab
# In R
library('devtools')
devtools::install_github("IRkernel/IRkernel")
IRkernel::installspec()
  • Step 12: Install other packages. For example, I want to install nloptr and lme4 packages.
install.packages('nloptr')
install.packages('lme4')
  • Step 13: Now you can either use interactive R or start a Jupyter lab. If you decided to go with jupyter lab, type:
jupyter lab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment