r – How to Set external variable or program for Rstudio

I know that this question is available in this page, but I have tried most of them, and I just can’t make it works. How can I set an external program as blast permanently using Sys.setenv for my personal functions in R

I’m using a MacOS with R4.1.1 and RStudio 2021.09.0.

The common way that I usually call an external program, in this case BLAST (ncbi-blast-2.2.29+) is just copy and paste the line in RStudio console, something like:

Sys.setenv(PATH = paste(Sys.getenv("PATH"), "/Users/myname/myprograms/ncbi-blast-2.2.29+/bin/", sep= .Platform$path.sep))

And then I just run my personal functions that use blast, and I have no problem with that. But I just want to set blast permanently in RStudio, and don’t need to copy and paste that line every time that I start RStudio. So I tried to paste that line in .Renviron, and then start up Rstudio and tried to run blast functions, and it didn’t work !!!

So I tried different, add the path in .zshrc (I’m using /bin/zsh), using nano or sublime text:

nano ~/.zshrc
export BLAST_PATH=$PATH:~/genetools/ncbi-blast-2.2.29+/bin/

And then just add the BLAST_PATH to Sys.setenv in .Renviron

nano .Renviron

Sys.setenv(PATH = paste(Sys.getenv("PATH"), "BLAST_PATH", sep= .Platform$path.sep))

or

Sys.setenv(PATH = paste(Sys.getenv("PATH"), BLAST_PATH, sep= .Platform$path.sep))

And restart RStudio and just it didn’t work when I use my personal functions !!!

Any way to set it permanently in RStudio ?

By the way, My .Renviron is located at home (~/.Renviron) and my working directory (R sessions ) in RStudio is located in ~/R !!!

Thanks

Read more here: Source link