OK, I admit that the title is a bit misleading. I’m braindead currently, so I may be missing something obvious here.
I’m working on R-powered webapp, and I’d like to pass certain parameters to read.table function – sep among others. Everything works like a charm if I’m passing single-byte characters as sep argument: ,, ;, |… but if I try to pass \t, I get an error:
invalid 'sep' value: must be one byte
of course, this happens because \t is actually escaped (\\t). Is there any chance that I can escape escapes, and pass it “as is” – i.e. a single byte string?
You need to write
sep="\t"as the parameter toread.table.In the case of a tab, it is the
tthat gets escaped. In other words, you are telling R thattdoesn’t really meant, buttab. If you escape the\, by using\\then you are telling R that the\doesn’t really meanescapebut a literal\.Here is some code illustrating the correct usage of
sep="\t"inread.table. And just for the fun of it, I usetextConnectionto use a connection to write to and read from, rather than using a file on disk:This produces the following output: