Hi, I am using the server version of RStudio and I have a script where I want to activate the conda environment that I set up for a bioinformatic tool called MinVar. For that I use in my script the command: system("source /home/ubuntu/miniconda3/bin/activate minvar"). I provide the path to activate because the tool is installed under my second user name in the server I use. And the error message is : sh: 1: source: not found error in running command I tried to look for solution in any possible forum but did not find anything. I was wondering if a solution for such issue was already discussed? and an answer found? Thanks a lot. [[alternative HTML version deleted]]
On Wed, 20 Mar 2019 09:59:21 +0100 Sandra Elisabeth Chaudron <sandra.chaudron at gmail.com> wrote:> I am using the server version of RStudio and I have a script where I > want to activate the conda environment that I set up for a > bioinformatic tool called MinVar. > For that I use in my script the command: system("source > /home/ubuntu/miniconda3/bin/activate minvar").Unfortunately, this is probably not going to work as is. In *nix-like systems, child processes cannot alter the environment variables of their parents, so when one wants a shell script to alter environment variables in the current session, they use "source". The reason your command returns an error message is probably because "source" is a command specific to /bin/bash, while R calls /bin/sh, which might be symlinked to /bin/dash instead of /bin/bash on Ubuntu. The POSIX-correct form would be ". /home/ubuntu/miniconda3/bin/activate minvar", that is, just a dot instead of the word "source". But the underlying issue would stay the same: R system() function launches a subprocess /bin/sh; the "source" or "." command causes the environment of the *child* shell process to be changed; environment of the *parent* R process stays unchanged. Your best bet would be to read the activate script, understand the changes to the environment it causes and use Sys.getenv() / Sys.setenv() to make equivalent changes in R environment variables. -- Best regards, Ivan
R is *not* RStudio. Please go to the RStudio site, not here, for help with that software. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Mar 20, 2019 at 6:30 AM Sandra Elisabeth Chaudron < sandra.chaudron at gmail.com> wrote:> Hi, > I am using the server version of RStudio and I have a script where I want > to activate the conda environment that I set up for a bioinformatic tool > called MinVar. > For that I use in my script the command: system("source > /home/ubuntu/miniconda3/bin/activate minvar"). I provide the path to > activate because the tool is installed under my second user name in the > server I use. > And the error message is : sh: 1: source: not found error in running > command > I tried to look for solution in any possible forum but did not find > anything. > I was wondering if a solution for such issue was already discussed? and an > answer found? > Thanks a lot. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]