I’d like to run PICRUST2 in R so I don’t need to run it from a terminal by myself. I’ve installed the PICRUST2 environment via conda the first time, but due to my stupidness, I installed it inside another environment! The second time I tried to install it, for some reason the same steps for conda environment did not work. Therefore I installed mamba and then an environemtn for PICRUST2.
However when I tried to activate my PICRUST2 environment via mamba by mamba activate picrust2
, it complains that
Run 'mamba init' to be able to run mamba activate/deactivate and start a new shell session. Or use conda to activate/deactivate.
Therefore I added mamba init
to the command but the complain persists as if the mamba initiated does not work for the next command. This must be something I do not understand about the shell that a command is run via system
or system2
in R.
I looked up how to activate conda environment in R. This post is perticularly helpful.
Firstly I tried to activate my env in R, which was successful.
# activate PICRUST2
if ('picrust2' %in% conda_list()[[1]]){
use_condaenv('picrust2', required = TRUE)
}else{
print('no picrust2 environment')
}
However, when I tried to run picrust2_pipeline.py
via system
, R acted like I’ve never activated picrust2
.
Someone else suggested indicating the python in the picrust2 env:
path2python <- '/home/user/mambaforge/envs/picrust2/bin/python'
use_python(path2python, required = TRUE)
This also did not work.
Then I tried to indicate the full path to picrust2_pipeline.py
in the system call. This works until picrust2_pipeline.py
needs further excutables from the picrust2
environment, including place_seq.py
, epa-ng
,gappa
, hsp.py
,metagenome_pipeline.py
,pathway_pipeline.py
(don’t ask why I know!) They are all in the same path as picrust2_pipeline.py
and soft-linking them to one of my current paths worked (totally cheating). Specifically for picrust2, you need to install the castor
package in R. Oh my, runing R inside python inside R!
Of course a more reasonable solution would be adding the path to picrust2 (/home/user/mambaforge/envs/picrust2/bin/) to the $PATH via:
export PATH=$PATH:/path-to-picrust2/bin
So, my current answer to the title of this article is, no, you cannot enter a conda environment in R console. However one realization I had was that you can activate your mamba environment via conda. So conda activate picrust2
also works.