3

In the block below, TSF_process is available from any directory (is in the PATH env). However, when I run this chunk:

{bash process, echo=TRUE}
TSF_process ./raw_data/settings.set 1

I get the error msg:

/tmp/RtmpK4MjsR/chunk-code1c4af3bc4f8b8.: line 2: TSF_process: command not found

However, if I copy the TSF_process file into my working directory and do this chunk:

{bash process, echo=TRUE}
./TSF_process ./raw_data/settings.set 1

...everything works ok.

Is there any way to avoid the step of copying the binary file into my working directory?

Will Barnwell
  • 4,049
  • 21
  • 34
  • Are you possibly looking for the `root.dir` option? Check out: https://stackoverflow.com/questions/20060518/in-rstudio-rmarkdown-how-to-setwd. – D.sen Sep 11 '17 at 22:06
  • 1
    Are you sure `TSF_process` is on the PATH within this execution? Your PATH may not be the same as the program's – Will Barnwell Sep 11 '17 at 22:07
  • Well, if I login into my account and do whatever `cd /any/folder/` and then run `TSF_process` it works. – Guillermo E Ponce-Campos Sep 11 '17 at 22:29
  • @D.sen I don't like to set the root.dir, if you put the script in another computer that kind of setup can break things up, right? – Guillermo E Ponce-Campos Sep 11 '17 at 22:33
  • 1
    You need to double check `Sys.which("TSF_process")` and `Sys.getenv("PATH")` inside the R Markdown document. The R process that compiles your R Markdown document may not have inherited the PATH variable you saw in a terminal (e.g. R won't read your `.bash_profile` or any config files related to `bash`.) – Yihui Xie Sep 11 '17 at 22:44
  • It looks ok... `> Sys.getenv("PATH") [1] "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" > Sys.which("TSF_process") TSF_process "/usr/bin/TSF_process" ` – Guillermo E Ponce-Campos Sep 11 '17 at 23:03
  • But is it the same from within the `bash` chunk? If you don't want to mess with `root.dir` (I agree), you might want to at least use the full path for `TSF_process` or explicitly include its directory in `PATH` during script-knitting. – r2evans Sep 11 '17 at 23:42
  • The problem with using the full path is similar to mess with root.dir. If I send the notebook to someone else, they likely won't have that program in the same directory. The idea is, "install 'TSF_process' anywhere you want, by default, the users of this program always have it available through the PATH env., the installation process does it. – Guillermo E Ponce-Campos Sep 11 '17 at 23:58

0 Answers0