Skip to content
Prev 25127 / 63424 Next

Quoting (was: inline C/C++ in R: question and suggestion

On 22/05/2007 4:01 PM, Vladimir Dergachev wrote:
That wouldn't work in R, because the parser couldn't tell whether

{ a }

was a block of code or a quoted string.
When your data doesn't contain quote marks, you can just use regular 
quotes to do that.  I don't know of a scan.string function, but this works:

A <- read.table(textConnection("#
Id Value Mark
1 a 3
2 b 4
#"), head = TRUE)

I think DTL's suggestion would be most useful when putting a lot of code 
in a string, where the escapes make the code harder to read.  For 
example, just about any function using a complicated regular expression.

Duncan Murdoch