From pdalgd at gmail.com  Fri Jul  5 13:40:31 2013
From: pdalgd at gmail.com (peter dalgaard)
Date: Fri, 5 Jul 2013 13:40:31 +0200
Subject: [Rd] should the text for RIGHT_ASSIGN be -> in getParseData()?
In-Reply-To: <51D6AE2B.1060500@gmail.com>
References: <CANROs4eVNfPjs_D5wb4Hqgy3Axb=88PZ_eGHVAFhTbi-3uT3Tw@mail.gmail.com>
	<51D6AE2B.1060500@gmail.com>
Message-ID: <93D66B0A-0F6C-4D4B-AA78-F9379C390C2F@gmail.com>


On Jul 5, 2013, at 13:29 , Duncan Murdoch wrote:

> On 13-07-05 3:31 AM, Yihui Xie wrote:
>> Hi,
>> 
>> The text column for '->' becomes '<-' in the data frame returned by
>> getParseData():
>> 
>>> getParseData(parse(text='1->x'))
>>   line1 col1 line2 col2 id parent        token terminal text
>> 7     1    1     1    4  7      0         expr    FALSE
>> 1     1    1     1    1  1      2    NUM_CONST     TRUE    1
>> 2     1    1     1    1  2      7         expr    FALSE
>> 3     1    2     1    3  3      7 RIGHT_ASSIGN     TRUE   <-
>> 4     1    4     1    4  4      6       SYMBOL     TRUE    x
>> 6     1    4     1    4  6      7         expr    FALSE
>> 
>> Is that expected?
> 
> It's by design, but I agree it's not ideal.  The reason for it is that "1 -> x" is parsed as `<-`(x, 1).  I think the parser only does translations like this for -> and ->>.  Currently the parser shows the name of the binary operator as the text.
> 
> I'll look into adding special handling for translations like this.  We will still parse the assignment in the same way, but the getParseData text could be the true text.

Just watch out for potential complications, e.g.

> `->`(x,1)
Error: could not find function "->"

so one needs to be sure that nothing will assume that the text column is a function name.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] should the text for RIGHT_ASSIGN be -> in getParseData()?
peter dalgaard