[R] single quotes and double quotes in a system() command. What to do?

Duncan Murdoch murdoch at stats.uwo.ca
Mon Mar 29 23:39:20 CEST 2010

On 29/03/2010 5:14 PM, Matthew Keller wrote:
> Hi all,
> I would like to run the following from within R:
> awk '{$3=$4="";gsub("  ","");print}' myfile > outfile
> However, this obviously won't work:
> system("awk '{$3=$4="";gsub("  ","");print}' myfile > outfile")
> and this won't either:
> system("awk '{$3=$4='';gsub('  ','');print}' myfile > outfile")
> Can anyone help me out? I'm sure there's an obvious solution. Thanks,

Escape the quotes that match the ones you use in R:

system("awk '{$3=$4=\"\";gsub(\"  \",\"\");print}' myfile > outfile")


system('awk \'{$3=$4="";gsub("  ","");print}\' myfile > outfile')

Duncan Murdoch

More information about the R-help mailing list