Hi, 

I am using RMarkdown in Rstudio and I want to execute commands from a program using  a bash chunk 

    ````{bash} 
    ```

I have a program called samtools on my computer so when I execute it in the chunk, it works. 

    ```{bash}
    samtools 
    ```

When I type :

    ```{bash}
    which samtools 
    ```

The output is that it tells me samtools is located in the  usr/local/bin  directory. 

However, when I execute a program with vcftools , I get an error because Rstudio, does not know where the program is: 
I have it in another directory on my computer.

How do I get Rstudio or Rmarkdown to execute vcftools from the bash chunk? 
Is there a way that I can tell RMarkdown which directory to look  in to find the program? 

For example (something like) :

    ```{bash}
    $vcftools = /Users/m.o.l.s/Programs_For_Bioinformatics/vcftools
    
    ```

or would I have to move all of the programs to usr/bin/local? 

Outside of  Rstudio, I have made aliases to the programs so they work fine on the terminal. 

I made the alias by writing in my .bash_profile

 `alias bcftools=/Users/paths/to/where/the/program/is/installed`

but I added the path to vcftools to my export PATH in the bash profile completely. 

In an RMarkdown file in Rstudio the following can be applied:

For jar files, I haven't figured out how to do it with a short command, but as h.mon says I can use the full path to the program and it will work. 
for example:

    ```{bash}
    # The beagle program 
     java -jar /Users/m.o.l.s/Programs_For_Bioinformatics/beagle.19.jar
    ```
The aliases above work only for the execution of the command in the Terminal , not in the bash chunk. So this is great for working in the Terminal. 

For example on Mac inside the Terminal:

    open .bash_profile
    alias bcftools=/Users/paths/to/where/the/program/is/installed
    File  > Save >  click the red x 
    hold down command and N together (to open a New terminal)
    bcftools 


These comands work to show the settings of the program when the RMarkdown file is inside the directory where the programs are installed.
They show the commands of the program without using the ./ argument. 
 

    ```{bash}
    # The BCFtools program
    $BCFTOOLS bcftools/bcftools
    ```
    
    ```{bash}
    $PSIBLAST =blast_folder/bin/psiblast -h
    ```

... but they dont do anything after that. I though the $ held some great significance, but it doesn't seem to. 


What does work however, as i.sudbery mentioned is putting all of the files in the .bashrc or .bash profile. 

The first step in doing this is to go to the Terminal:

find the home directory 

    echo $HOME

The home direcotry is then the start of where these programs can be found

    open .bashrc 
    

Paste this into the bash_rc ( but change the home directory to the actual name of your home directory) 

     exportPATH=§PATH:/bin:/usr/bin/:/usr/local/bin:/usr/sbin:/sbin:/Users/home/Programs_For_Bioinformatics/vcftools/bin:/Users/home/Programs_For_Bioinformatics/bowtie:/Users/home/Programs_For_Bioinformatics/Kalign:

The pattern above is to list the path where the program is found on the computer relative to the home directory and separate each path with a semicolon. 

    File > save > click the x

Then it will be possible to use the program in Rmarkdown using a one word command. 

    ```{bash}
    source ~/.bash_profile
    cufflinks
    ```

or 

    ```{bash}
    source ~/.bashrc
    blastp -h
    ```

 in the start of the  code chunk.

Of course, commands like this work but as the path gets longer the code gets longer

    ./angsd_folder/angsd

And it also works if the programs are located in the usr/local/bin






