From ggrothendieck at gmail.com  Mon Jan 24 20:30:29 2011
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Mon, 24 Jan 2011 14:30:29 -0500
Subject: [Rd] "+" operator on characters revisited
In-Reply-To: <6C93669D-6B58-45B6-86DC-2A77984C7CC3@stat.ubc.ca>
References: <878vycd7ld.fsf@gmail.com>
	<AANLkTin_=MtMYZOjprLme53-H4XVOD7y_d9DpH+OiEb_@mail.gmail.com>
	<cpnei83q1dp.fsf@gmail.com>
	<AANLkTikZ8M38vX1eGs76EK-FwMoOFJBuJHbF2_Jdj0St@mail.gmail.com>
	<6C93669D-6B58-45B6-86DC-2A77984C7CC3@stat.ubc.ca>
Message-ID: <AANLkTikrk29EpzreB-QZ5a+z-kvW_5sWp+pq1ASA7jyR@mail.gmail.com>

On Mon, Jan 24, 2011 at 2:15 PM, Davor Cubranic <cubranic at stat.ubc.ca> wrote:
> On 2011-01-23, at 4:34 AM, Gabor Grothendieck wrote:
>
>> On Sun, Jan 23, 2011 at 6:56 AM, Vitalie S. <spinuvit.list at gmail.com> wrote:
>>> Gabor Grothendieck <ggrothendieck at gmail.com> writes:
>>>
>>>> Also the gsubfn supports quasi perl style string interpolation that
>>>> can sometimes be used to avoid the use of paste in the first place.
>>>> Just preface the function in question by fn$ like this:
>>>>
>>>> library(gsubfn)
>>>> fn$cat("pi = $pi\n")
>>>
>>> Thanks for the tip. Not bad indeed.
>>> Almost as readable as
>>>
>>> cat("pi = " + pi + "\n")
>>
>> To me the + can be substantially less readable. ?The need to
>> repeatedly quote everything makes it just as bad as paste. ?Compare
>> the following and try to figure out if there is an error in quoting in
>> the + and paste solutions. ?Trying to distinguish the single and
>> double quotes is pretty difficult but simple in the fn$ and sprintf
>> solutions. ?Even if there were no quotes the constant need to
>> interpose quotes makes it hard to read.
>
> That may be a matter of taste, but FWIW it seems that shell-style string interpolation (using the dollar prefix) has going out of style in recent scripting languages. Ruby uses the expression substitution construct ("#{expr}"), while Python has "str.format", both allowing arbitrary expressions.
>

fn$ supports that too using `...`

> library(sqldf)
> fn$sqldf("select * from BOD where demand > `mean(BOD$demand)` limit 2")
  Time demand
1    3     19
2    4     16


> And most editors have syntax highlighting that distinguishes strings from other program elements. This makes quoting errors pretty obvious.
>

That only makes it slightly easier to handle the mess.  Its better to
get rid of the quotes in the first place.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



[Rd] "+" operator on characters revisited
Gabor Grothendieck