Run a bash script from an R script Run a bash script from an R script bash bash

Run a bash script from an R script


The way to debug this is to use cat to test whether your character string has been escaped correctly. So:

  1. Create an object x with your string
  2. Carefully escape all the special characters, in this case quotes and backslashes
  3. Use cat(x) to inspect the resulting string.

For example:

x <- 'samtools view filename.bam | awk \'{OFS="\\t"; print ">"$1"\\n"$10}\' - > filename.fasta'cat(x)samtools view filename.bam | awk '{OFS="\t"; print ">"$1"\n"$10}' - > filename.fasta

If this gives the correct string, then you should be able to use

system(x)