Re: [Rd] Quoting (was: inline C/C++ in R: question and suggestion

From: Vladimir Dergachev <vdergachev_at_rcgardis.com>
Date: Tue, 22 May 2007 17:42:13 -0400

On Tuesday 22 May 2007 4:58 pm, Duncan Murdoch wrote:
> On 22/05/2007 4:01 PM, Vladimir Dergachev wrote:
> > On Tuesday 22 May 2007 3:52 pm, Duncan Murdoch wrote:
> >> On 5/22/2007 1:59 PM, Oleg Sklyar wrote:
> >
> > I second that. My favorite implementation of this is in Tcl, where curly
> > braces {} mean that the text they enclose is unmodified. Since language
> > constructs using them are normally balanced this is not an impediment.
>
> That wouldn't work in R, because the parser couldn't tell whether
>
> { a }

One easy workaround is to have string{ ... } construct - it should be very easy to parse string{ differently from { alone.

>
> was a block of code or a quoted string.
>
> > One extremely useful application of this (aside from long strings) is
> > specifying inline data frames - I don't know how to do this otherwise.
> >
> > I.e. something like:
> >
> > A<- scan.string({#
> > Id Value Mark
> > 1 a 3
> > 2 b 4
> > # })
>
> 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)

Cool, thank you !

>
> 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.

Also anything using .Tcl(). Quotes in data frame definition are useful because they could be employed to delimit text fields with spaces in them.

                     best

                        Vladimir Dergachev

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 22 May 2007 - 21:46:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 May 2007 - 23:34:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.