Yihui Xie
2013-Jul-05 07:31 UTC
[Rd] should the text for RIGHT_ASSIGN be -> in getParseData()?
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?> sessionInfo()R version 3.0.1 (2013-05-16) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base Regards, Yihui -- Yihui Xie <xieyihui at gmail.com> Phone: 206-667-4385 Web: http://yihui.name Fred Hutchinson Cancer Research Center, Seattle
Duncan Murdoch
2013-Jul-05 11:29 UTC
[Rd] should the text for RIGHT_ASSIGN be -> in getParseData()?
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. Duncan Murdoch> >> sessionInfo() > R version 3.0.1 (2013-05-16) > Platform: x86_64-pc-linux-gnu (64-bit) > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=C LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > Regards, > Yihui > -- > Yihui Xie <xieyihui at gmail.com> > Phone: 206-667-4385 Web: http://yihui.name > Fred Hutchinson Cancer Research Center, Seattle > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Barry Rowlingson
2013-Jul-05 16:29 UTC
[Rd] should the text for RIGHT_ASSIGN be -> in getParseData()?
On Fri, Jul 5, 2013 at 12:57 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:> R itself doesn't make use of the text column, it's for display of code > by highlighters etc. So if anyone does assume text is a function name, > it's their bug, not ours. In fact, the bug is already there, because > there is actually one other example which was being parsed properly, > "**" is translated to "^". There's no `**` function, but 2**3 works.Is there any reason right-assign with "->" still exists? How much code on CRAN uses it, and how trivially could it be excised? Can we also have 'up assign' and "down assign" so I can do: > 3 > x -^ > x -v > 4 - they make just as much sense. Okay, lets see all the edge cases..... Barry
Barry Rowlingson
2013-Jul-05 22:55 UTC
[Rd] should the text for RIGHT_ASSIGN be -> in getParseData()?
On Fri, Jul 5, 2013 at 7:24 PM, peter dalgaard <pdalgd at gmail.com> wrote:> I have used in with multi-line input, occasionally, though. As in > > replicate(10000, { > ysim <- rbinom(length(p), n, p) > glm(cbind(ysim, n - ysim) ~ x, binomial)$deviance > }) > > ... and then you realize that you probably don't want to look at 10000 simulated deviances and add "-> simDev". >Yes, that's kinda cute, but then you realise you don't want to have to type all that again and it would really be better off in a function. Can you do something like: replicate(10000,{ ysim <- rbinom(length(p), n, p) glm(cbind(ysim, n - ysim) ~ x, binomial)$deviance }) -> function()... - I don't think so. Once you've started typing, the only way to get it into a function is going to involve sticking function() at the start, at which point you can add the foo <- I guess this is the point where Dirk gets upset and calls me a troll. I'll shut up. You've convinced me its mostly harmless. Barry