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:
- Create an object
x
with your string - Carefully escape all the special characters, in this case quotes and backslashes
- 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)