Reputation: 3075
I have been trying all day to find a way to run this line (which works in bash) in R, and I keep getting errors about the round brackets... I understand that the paste command gets confused when dealing with brackets, but I have tried escaping the brackets, putting them in double quotes like this "')'" but nothing works so I am out of resources. Does anybody have any idea how this could work in R?
system(paste("sortBed -i <(awk -v a=1 -v b=2 -v c=3 -v d=4 '{OFS=FS=\"\t\"} {if ($d < 0.5) print \"value\"$a, $b-\"'$d'\", $c+\"'$d'\"}' file.in > file.out", sep=""))
sh: -c: line 0: syntax error near unexpected token `('
Upvotes: 2
Views: 1024
Reputation: 81
The reason seems to be that the R system() command calls the bourne shell (sh) instead of the bourne again shell (bash). For example, the command
> system("paste <(echo 'Hi')")
will fail, mentioning the bourne shell in the process:
sh: -c: line 0: syntax error near unexpected token `('
One solution is to print the command in the bourne shell and pipe the output into bash:
> system("echo \"paste <(echo 'Hi')\" | bash")
Hi
Upvotes: 3
Reputation: 6171
I get the same error as you when running the line from R. As far as I can see there's missing a final parenthesis for the output process substitution in the bash script but adding that doesn't prevent the error. Also the tabulator should be double-escaped to make sure the backslash is passed onto the awk
script.
One solution that we found out works in this case is to pipe the output from awk
directly into sortBed
.
system(paste("awk -v a=1 -v b=2 -v c=3 -v d=4 '{OFS=FS=\"\\t\"} {if ($d < 0.5) print \"value\"$a, $b-\"'$d'\", $c+\"'$d'\"}' file.in | sortBed -i", sep=""))
We didn't really get the output process substitution to work, so if anyone has any suggestions for that it would be nice to hear.
Upvotes: 0