Re: [Rd] deparse operators in expressions
On 11-04-09 9:43 PM, Yihui Xie wrote: Hi, I observed a slight problem in deparse(): it will add spaces around most operators except /. I wonder if this is easy to fix. I know this is quite trivial, but I will appreciate if / is not treated as an exception. Examples: It's easy to change: take a look at src/main/deparse.c. The operators that are labelled as PP_BINARY2 get no spaces. Looking in src/main/names.c, we see those are /, ^, %%, %/% and :. But clearly this is by design, and I think it's unlikely to change. Duncan Murdoch deparse(expression(1/1)) [1] expression(1/1) deparse(expression(1+1)) [1] expression(1 + 1) deparse(expression(1%in%1)) [1] expression(1 %in% 1) sessionInfo() R version 2.12.2 (2011-02-25) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base Regards, Yihui -- Yihui Xiexieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] deparse operators in expressions
Thanks for pointing out the direction. Since this is unlikely to change in base R, is it possible to change from an add-on package? I think it is reasonable to eliminate spaces around ^ and :, but I don't understand why /, %% and %/% should be different with other arithmetic operators like +, - and *. Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Sun, Apr 10, 2011 at 8:20 AM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 11-04-09 9:43 PM, Yihui Xie wrote: Hi, I observed a slight problem in deparse(): it will add spaces around most operators except /. I wonder if this is easy to fix. I know this is quite trivial, but I will appreciate if / is not treated as an exception. Examples: It's easy to change: take a look at src/main/deparse.c. The operators that are labelled as PP_BINARY2 get no spaces. Looking in src/main/names.c, we see those are /, ^, %%, %/% and :. But clearly this is by design, and I think it's unlikely to change. Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] deparse operators in expressions
On 10/04/2011 2:08 PM, Yihui Xie wrote: Thanks for pointing out the direction. Since this is unlikely to change in base R, is it possible to change from an add-on package? Of course. Just write your own deparse function. You can start with the code from the standard one, and make any changes you like. Alternatively, just type your code the way you like it, and use keep.source to have it displayed as you entered it. I think it is reasonable to eliminate spaces around ^ and :, but I don't understand why /, %% and %/% should be different with other arithmetic operators like +, - and *. I looked it up, and it has been like that since revision 2 when this code was first committed to our repository in 1997. I imagine whoever wrote it was following the pattern of some other language (maybe S), or maybe just their own personal taste. Duncan Murdoch Regards, Yihui -- Yihui Xiexieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Sun, Apr 10, 2011 at 8:20 AM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 11-04-09 9:43 PM, Yihui Xie wrote: Hi, I observed a slight problem in deparse(): it will add spaces around most operators except /. I wonder if this is easy to fix. I know this is quite trivial, but I will appreciate if / is not treated as an exception. Examples: It's easy to change: take a look at src/main/deparse.c. The operators that are labelled as PP_BINARY2 get no spaces. Looking in src/main/names.c, we see those are /, ^, %%, %/% and :. But clearly this is by design, and I think it's unlikely to change. Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] deparse operators in expressions
Hi, I observed a slight problem in deparse(): it will add spaces around most operators except /. I wonder if this is easy to fix. I know this is quite trivial, but I will appreciate if / is not treated as an exception. Examples: deparse(expression(1/1)) [1] expression(1/1) deparse(expression(1+1)) [1] expression(1 + 1) deparse(expression(1%in%1)) [1] expression(1 %in% 1) sessionInfo() R version 2.12.2 (2011-02-25) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel