Re: [ESS] Ever consider changing indentation on #?
There is also the new styler package (a Google Summer of Code Project), not sure if the style is at the parser level either. https://github.com/krlmlr/styler https://github.com/lorenzwalthert/styler On Mon, May 8, 2017 at 9:01 AM, Stephen Eglenwrote: > > > That's not a style from the parser but from the printer, e.g. the third > letter > > of REPL rather than the first. > > > > Unlike gofmt, the R printer has been designed to print rather than > format. > > thanks for the clarification. But is it the closest we've got to a > formatting tool in R? > > __ > ESS-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/ess-help > -- Ahmadou H. DICKO, PhD Data Lab Manager Humanitarian Data Exchange (HDX) - humdata.org OCHA ROWCA regional office VDN Sacre Coeur III, Villa 9364 BP 16 922 Fann Dakar, Senegal Phone: (+221) 33 869 85 36 Mobile: (+221) 77 123 81 69 Email: dic...@un.org Skype: dicko.ahmadou.h Twitter : @dickoah Gitlab: gitlab/dickoa Github: github/dickoa [[alternative HTML version deleted]] __ ESS-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/ess-help
Re: [ESS] Ever consider changing indentation on #?
> That's not a style from the parser but from the printer, e.g. the third letter > of REPL rather than the first. > > Unlike gofmt, the R printer has been designed to print rather than format. thanks for the clarification. But is it the closest we've got to a formatting tool in R? __ ESS-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/ess-help
Re: [ESS] Ever consider changing indentation on #?
> On 8 mai 2017, at 09:07, Stephen Eglenwrote: > >> Let's say that following the R engine indentation style has been coldly >> received. > > Oh dear! I personally think supporting the style from the R parser (if > that is intended, perhaps it is not?) would be good. That's not a style from the parser but from the printer, e.g. the third letter of REPL rather than the first. Unlike gofmt, the R printer has been designed to print rather than format. Lionel __ ESS-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/ess-help
Re: [ESS] Ever consider changing indentation on #?
+1 for the current ESS style, I'm with Vincent on this. Since Stephen also mentioned 'formatR', let's say here that formatR aligns any comment line starting with any number of #s (1, 2, 3, more…) to the current indentation level, and does not affect in-line comments. For once, Hadley Wickham does not seem to have a very developed opinion on comment indentation: http://adv-r.had.co.nz/Style.html (at the very bottom) Mathieu. On 05/06/2017 10:30 AM, Vincent Goulet wrote: >> Le 4 mai 2017 à 22:49, Paul Johnson <pauljoh...@gmail.com> a écrit : >> >> Please raise your hand if you have EVER used # to document R code in >> the way mentioned on the LISP coding standards page. > > I do, all the time ever since I (more or less by accident) discovered the > functionality. Actually, all the code I distribute to my students is > commented this way; see e.g. > > > https://github.com/vigou3/introduction-programmation-r/blob/master/bases.R > > It should be noted that this commenting style also works in LaTeX mode > (granted, a single % somewhere on the right being less useful with text). For > me, it just makes more sense that the higher the number of comment markers, > the stronger the emphasis (or vice versa). > > Call me an old timer ;-), but I would vote against a change to the *default* > behaviour. I see this commenting style as pure Emacsism and would expect any > programming mode (Markdown excepted for obvious reasons) to respect it by > default. Furthermore, I think ESS does not have to play catch up or to adapt > to RStudio. > > Now, that said, I'm all in favour to have an easy to toggle ESS option to > change Emacs/lisp commenting style to Markdown style (since that's what we're > talking about) if someone wants to provide the patch. > > v. > >> pj >> >> On Thu, May 4, 2017 at 10:52 AM, Brahm, David >> <david.br...@geodecapital.com> wrote: >>> Since we're on the topic, is there a style to make the # comments >>> right-justified against >>> "fill-column" (which is 97 for me, as that makes printouts look good) >>> and/or the window >>> width? So as you type the comment, it marches leftward. E.g.: >>> >>> x <- y + z # This >>> comment ends on column 97 >>> 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 >>> >>> -- David Brahm (br...@alum.mit.edu) >>> >>> >>> -Original Message- >>> From: ESS-help [mailto:ess-help-boun...@r-project.org] On Behalf Of Charles >>> C. Berry >>> Sent: Thursday, May 04, 2017 11:38 AM >>> To: Ista Zahn >>> Cc: Stephen Eglen; ess-help >>> Subject: Re: [ESS] Ever consider changing indentation on #? >>> >>> On Thu, 4 May 2017, Ista Zahn wrote: >>> >>> >>> And there are a bunch of styles from which to choose a personal default. >>> See below. >>> >>> >>> There are `off-the-shelf' styles like `Rstudio' that might satisfy Paul's >>> student. >>> >>> Setting `ess-default-style' to `Rstudio' gives these settings: >>> >>> (RStudio >>> (ess-indent-offset . 2) >>> (ess-offset-arguments . open-delim) >>> (ess-offset-arguments-newline . prev-line) >>> (ess-offset-block . prev-line) >>> (ess-offset-continued . straight) >>> (ess-align-nested-calls) >>> (ess-align-arguments-in-calls "function[ ]*(") >>> (ess-align-continuations-in-calls) >>> (ess-align-blocks) >>> (ess-indent-from-lhs arguments) >>> (ess-indent-from-chain-start . t) >>> (ess-indent-with-fancy-comments)) >>> >>> >>> Or one can customize the `OWN' style and select it. See the >>> `ess-style-alist' docstring for more details. >>> >>> HTH, >>> >>> Chuck >>> >>> __ >>> ESS-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/ess-help >>> >>> __ >>> ESS-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/ess-help >> >> >> >> -- >> Paul E. Johnson http://pj.freefaculty.org >> Director, Center for Research Methods and Data Analysis http://crmda.ku.edu >> >> To write to me directly, please address me at pauljohn at ku.edu. >> >> __ >
Re: [ESS] Ever consider changing indentation on #?
since we are throwing ideas out there... perhaps what the R universe could do with is something similar to "gofmt" for the go language. All Go code looks the same, because there is a formatting tool, and everyone uses it. How about something similar for R...?!? Stephen __ ESS-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/ess-help
Re: [ESS] Ever consider changing indentation on #?
Richard M. Heiberger writes: > When people send me code with consistent use of #, I can't read it > because all the comments fly off to the right and are nowhere near > what they are talking about. Does ESS do this automatically, or do you need to explicitly ask it to reindent the code for this to happen? Most code I receive is very poorly and inconsistently formatted to begin with, so applying any conventions usually makes it better, or at least easier to tweak into a sensible structure. > On Thu, May 4, 2017 at 10:49 PM, Paul Johnsonwrote: >> Please raise your hand if you have EVER used # to document R code in >> the way mentioned on the LISP coding standards page. I learned R and ESS concurrently starting ca. 2004, so this convention is normal for me. I find it handy to be able to append short noted with #, and the distinction between ## and ### is intuitively useful. Once code gets complex enough to warrant sectioning and folding, I usually switch to Rmd and wrap it in markdown code blocks. Or org-mode, if I'm going to be mixing multiple code languages. On Thu, May 4, 2017 at 10:25 AM, Lionel Henry wrote: > > Emacs is for people willing to put the effort into customisation. > Your students are probably better off with RStudio. That said I > agree that good defaults are important. Yes, RStudio has been a boon for teaching. I can demonstrate on Linux without my students on Mac or Windows noticing the difference, and the interface is intuitive enough as to not add to the cognitive load of learning R. That said, it's kind of entertaining to watch the development of RStudio: every few months there's another whiz-bang feature added on to great fanfare, that reproduces, partially, something we've had in ESS for years. Brings to mind the old quote about reimplmenting Lisp. It's really too bad that markdown didn't happen before org-mode came into it's own. If org-mode had built off the markdown syntax, the potential for cross-pollination between Emacs/Org/ESS and RStudio/Rmarkdown would have been much stronger. At this point it looks like RMarkdown will slowly accumulate a subset of org-mode features. Best, Tyler __ ESS-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/ess-help
Re: [ESS] Ever consider changing indentation on #?
I agree the default is worthwhile changing, especially Paul's nice suggestion of letting # be flush left ## indentation level which would not affect my memory typing (since I never use `#`) and solve irritating indentation issues when I work with other peoples code. Best, Kasper On Sat, May 6, 2017 at 6:30 AM, Lionel Henry <lionel@gmail.com> wrote: > I don't use it either (though I tried at some point). > Any objection to change the default Martin? > > Lionel > > > > On 6 mai 2017, at 11:44, Vitalie Spinu <spinu...@gmail.com> wrote: > > > > > > I would add here that other modes in emacs except lisp don't usually > respect > > this convention. > > > > Vitalie > > > >>> On Fri, May 05 2017 23:52, Steven McKinney wrote: > > > >> As an old lisp programmer I use # and ## and ### in all my code. > > > >> ### > >> ### for code block and function headers > >> ### (this was actually functional in > >> ### SPLUS for auto-generating help) > >> ### > > > >>## for inline comments in code, and # brief margin notes > > > >> I find it useful, but all things change over time. > > > >> Steven McKinney > > > >>> -Original Message- > >>> From: ESS-help [mailto:ess-help-boun...@r-project.org] On Behalf Of > Paul > >>> Johnson > >>> Sent: May-04-17 7:50 PM > >>> To: ess-help > >>> Subject: Re: [ESS] Ever consider changing indentation on #? > >>> > >>> Please raise your hand if you have EVER used # to document R code in > >>> the way mentioned on the LISP coding standards page. > >>> > >>> pj > >>> > >>> On Thu, May 4, 2017 at 10:52 AM, Brahm, David > >>> <david.br...@geodecapital.com> wrote: > >>>> Since we're on the topic, is there a style to make the # comments > right- > >>> justified against > >>>> "fill-column" (which is 97 for me, as that makes printouts look good) > >>> and/or the window > >>>> width? So as you type the comment, it marches leftward. E.g.: > >>>> > >>>> x <- y + z # > This > >>> comment ends on column 97 > >>>> > >>> 123456789012345678901234567890123456789012345678901234567890 > 123456789012345 > >>> 6789012345678901234567 > >>>> > >>>> -- David Brahm (br...@alum.mit.edu) > >>>> > >>>> > >>>> -Original Message- > >>>> From: ESS-help [mailto:ess-help-boun...@r-project.org] On Behalf Of > >>> Charles C. Berry > >>>> Sent: Thursday, May 04, 2017 11:38 AM > >>>> To: Ista Zahn > >>>> Cc: Stephen Eglen; ess-help > >>>> Subject: Re: [ESS] Ever consider changing indentation on #? > >>>> > >>>> On Thu, 4 May 2017, Ista Zahn wrote: > >>>> > >>>>> On Thu, May 4, 2017 at 10:25 AM, Lionel Henry <lionel@gmail.com> > >>> wrote: > >>>>>> > >>>>>>> On 4 mai 2017, at 16:22, Paul Johnson <pauljoh...@gmail.com> > wrote: > >>>>>>> > >>>>>>> I understand I can fix my init.el go avoid this, but it would be > nicer > >>>>>>> for my purpose > >>>>>>> if this were in ESS itself, because I keep telling students to use > it > >>>>>>> and they are put off/discouraged > >>>>>>> by this. > >>>>>> > >>>>>> Emacs is for people willing to put the effort into customisation. > >>>>>> Your students are probably better off with RStudio. That said > >>>>>> I agree that good defaults are important. > >>>>> > >>>> > >>>> And there are a bunch of styles from which to choose a personal > default. > >>>> See below. > >>>> > >>>>> Yes, IMO Emacs/ESS isn't going to compete with Rstudio on > >>>>> out-of-the-box convenience. But we can compete on features! Put this > >>>>> in your config file > >>>>> > >>>>> (add-hook 'ess-mode-hook > >>>>> (lambda() > >>>>> ;; don't indent comments > &g
Re: [ESS] Ever consider changing indentation on #?
I would add here that other modes in emacs except lisp don't usually respect this convention. Vitalie >> On Fri, May 05 2017 23:52, Steven McKinney wrote: > As an old lisp programmer I use # and ## and ### in all my code. > ### > ### for code block and function headers > ### (this was actually functional in > ### SPLUS for auto-generating help) > ### > ## for inline comments in code, and # brief margin notes > I find it useful, but all things change over time. > Steven McKinney >> -Original Message- >> From: ESS-help [mailto:ess-help-boun...@r-project.org] On Behalf Of Paul >> Johnson >> Sent: May-04-17 7:50 PM >> To: ess-help >> Subject: Re: [ESS] Ever consider changing indentation on #? >> >> Please raise your hand if you have EVER used # to document R code in >> the way mentioned on the LISP coding standards page. >> >> pj >> >> On Thu, May 4, 2017 at 10:52 AM, Brahm, David >> <david.br...@geodecapital.com> wrote: >> > Since we're on the topic, is there a style to make the # comments right- >> justified against >> > "fill-column" (which is 97 for me, as that makes printouts look good) >> and/or the window >> > width? So as you type the comment, it marches leftward. E.g.: >> > >> > x <- y + z # This >> comment ends on column 97 >> > >> 123456789012345678901234567890123456789012345678901234567890123456789012345 >> 6789012345678901234567 >> > >> > -- David Brahm (br...@alum.mit.edu) >> > >> > >> > -Original Message- >> > From: ESS-help [mailto:ess-help-boun...@r-project.org] On Behalf Of >> Charles C. Berry >> > Sent: Thursday, May 04, 2017 11:38 AM >> > To: Ista Zahn >> > Cc: Stephen Eglen; ess-help >> > Subject: Re: [ESS] Ever consider changing indentation on #? >> > >> > On Thu, 4 May 2017, Ista Zahn wrote: >> > >> >> On Thu, May 4, 2017 at 10:25 AM, Lionel Henry <lionel@gmail.com> >> wrote: >> >>> >> >>>> On 4 mai 2017, at 16:22, Paul Johnson <pauljoh...@gmail.com> wrote: >> >>>> >> >>>> I understand I can fix my init.el go avoid this, but it would be nicer >> >>>> for my purpose >> >>>> if this were in ESS itself, because I keep telling students to use it >> >>>> and they are put off/discouraged >> >>>> by this. >> >>> >> >>> Emacs is for people willing to put the effort into customisation. >> >>> Your students are probably better off with RStudio. That said >> >>> I agree that good defaults are important. >> >> >> > >> > And there are a bunch of styles from which to choose a personal default. >> > See below. >> > >> >> Yes, IMO Emacs/ESS isn't going to compete with Rstudio on >> >> out-of-the-box convenience. But we can compete on features! Put this >> >> in your config file >> >> >> >> (add-hook 'ess-mode-hook >> >> (lambda() >> >>;; don't indent comments >> >>(setq ess-indent-with-fancy-comments nil) >> >>;; turn on outline mode >> >>(setq-local outline-regexp "[# ]+") >> >>(outline-minor-mode t))) >> >> >> >> and not only will single # comments not be aligned at comment-column, >> >> but code folder will work too! >> >> >> >> >> > >> > There are `off-the-shelf' styles like `Rstudio' that might satisfy Paul's >> > student. >> > >> > Setting `ess-default-style' to `Rstudio' gives these settings: >> > >> > (RStudio >> >(ess-indent-offset . 2) >> >(ess-offset-arguments . open-delim) >> >(ess-offset-arguments-newline . prev-line) >> >(ess-offset-block . prev-line) >> >(ess-offset-continued . straight) >> >(ess-align-nested-calls) >> >(ess-align-arguments-in-calls "function[ ]*(") >> >(ess-align-continuations-in-calls) >> >(ess-align-blocks) >> >(ess-indent-from-lhs arguments) >> >(ess-indent-from-chain-start . t) >> >(ess-indent-with-fancy-comments)) >> > >> > >> > Or one can customize the `OW
Re: [ESS] Ever consider changing indentation on #?
As an old lisp programmer I use # and ## and ### in all my code. ### ### for code block and function headers ### (this was actually functional in ### SPLUS for auto-generating help) ### ## for inline comments in code, and # brief margin notes I find it useful, but all things change over time. Steven McKinney > -Original Message- > From: ESS-help [mailto:ess-help-boun...@r-project.org] On Behalf Of Paul > Johnson > Sent: May-04-17 7:50 PM > To: ess-help > Subject: Re: [ESS] Ever consider changing indentation on #? > > Please raise your hand if you have EVER used # to document R code in > the way mentioned on the LISP coding standards page. > > pj > > On Thu, May 4, 2017 at 10:52 AM, Brahm, David > <david.br...@geodecapital.com> wrote: > > Since we're on the topic, is there a style to make the # comments right- > justified against > > "fill-column" (which is 97 for me, as that makes printouts look good) > and/or the window > > width? So as you type the comment, it marches leftward. E.g.: > > > > x <- y + z # This > comment ends on column 97 > > > 123456789012345678901234567890123456789012345678901234567890123456789012345 > 6789012345678901234567 > > > > -- David Brahm (br...@alum.mit.edu) > > > > > > -Original Message- > > From: ESS-help [mailto:ess-help-boun...@r-project.org] On Behalf Of > Charles C. Berry > > Sent: Thursday, May 04, 2017 11:38 AM > > To: Ista Zahn > > Cc: Stephen Eglen; ess-help > > Subject: Re: [ESS] Ever consider changing indentation on #? > > > > On Thu, 4 May 2017, Ista Zahn wrote: > > > >> On Thu, May 4, 2017 at 10:25 AM, Lionel Henry <lionel@gmail.com> > wrote: > >>> > >>>> On 4 mai 2017, at 16:22, Paul Johnson <pauljoh...@gmail.com> wrote: > >>>> > >>>> I understand I can fix my init.el go avoid this, but it would be nicer > >>>> for my purpose > >>>> if this were in ESS itself, because I keep telling students to use it > >>>> and they are put off/discouraged > >>>> by this. > >>> > >>> Emacs is for people willing to put the effort into customisation. > >>> Your students are probably better off with RStudio. That said > >>> I agree that good defaults are important. > >> > > > > And there are a bunch of styles from which to choose a personal default. > > See below. > > > >> Yes, IMO Emacs/ESS isn't going to compete with Rstudio on > >> out-of-the-box convenience. But we can compete on features! Put this > >> in your config file > >> > >> (add-hook 'ess-mode-hook > >> (lambda() > >>;; don't indent comments > >>(setq ess-indent-with-fancy-comments nil) > >>;; turn on outline mode > >>(setq-local outline-regexp "[# ]+") > >>(outline-minor-mode t))) > >> > >> and not only will single # comments not be aligned at comment-column, > >> but code folder will work too! > >> > >> > > > > There are `off-the-shelf' styles like `Rstudio' that might satisfy Paul's > > student. > > > > Setting `ess-default-style' to `Rstudio' gives these settings: > > > > (RStudio > >(ess-indent-offset . 2) > >(ess-offset-arguments . open-delim) > >(ess-offset-arguments-newline . prev-line) > >(ess-offset-block . prev-line) > >(ess-offset-continued . straight) > >(ess-align-nested-calls) > >(ess-align-arguments-in-calls "function[ ]*(") > >(ess-align-continuations-in-calls) > >(ess-align-blocks) > >(ess-indent-from-lhs arguments) > >(ess-indent-from-chain-start . t) > >(ess-indent-with-fancy-comments)) > > > > > > Or one can customize the `OWN' style and select it. See the > > `ess-style-alist' docstring for more details. > > > > HTH, > > > > Chuck > > > > __ > > ESS-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/ess-help > > > > __ > > ESS-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/ess-help > > > > -- > Paul E. Johnson http://pj.freefaculty.org > Director, Center for Research Methods and Data Analysis http://crmda.ku.edu > > To write to me directly, please address me at pauljohn at ku.edu. > > __ > ESS-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/ess-help __ ESS-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/ess-help
Re: [ESS] Ever consider changing indentation on #?
On Thu, May 4, 2017 at 3:51 AM, Stephen Eglenwrote: > > hi Paul, > >> "what the Hell, the folding is borked!". This is more and more common >> with the adoption of markdown-style commentary within R files. > > can you give an example of the markdown-style commentary? > > Here is an R file that has "Rstudio sections" that begin with #. I just tested with their gui and the magic recipe for howto is written below. It is something like Emacs org mode, I suppose. Code folding. This is an example of a file that gets "destroyed" by Emacs/ESS indentation ## Paul Johnson ## 20170504 ## Open this file in Rstudio, you'll see what I mean # Here is a section from Code-> insert section x <- rnorm(100) y <- rnorm(100) ## The effect of "Code -> Insert section" is to create a left aligned single #. ## Apparently, it follows with dots out to right edge. # Here is a second section from Code -> insert section z <- function(a, b, c){ y <-3 y + 7 } ## After this, in editor Rstudio, then the sections can be folded (hidden) # Third section ## How to create a section without using Rstudio menu? ## TO create this section, I did not use Rstudio menu. I insert ## 1. one # ## 2. a space ## 3. some words ## 4. Four dashes ## the # at begin and dashes at end is signal to R studio this is a section. I understand I can fix my init.el go avoid this, but it would be nicer for my purpose if this were in ESS itself, because I keep telling students to use it and they are put off/discouraged by this. I'm not an Rstudio user, but try to cooperate with some of them :) pj >> Until now, I've said "too bad" when they complain about their code, >> but now I'm thinking we ought to consider changing the behavior of >> Emacs/ESS. Does it really really need to do # indentation that way? >> Why? I've always thought it is odd. And counterintuitive. In what >> backwards world would one suppose # gets the most indent, while ### >> gets none?. I don't see any benefit in that # indentation that way. I >> do see a big benefit in the ## indent at the code level. I'm only >> quibbling about #. > > just for background context, ESS follows the Emacs convention for > comments (### for column 0, ## for same level, # for col 32 or more), that is > used widely in elisp. It is probably fair to say though that these > conventions are not widely known outside of Emacs. > >> Would you ever consider changing the ESS default for R files so # is >> flush left? Could I offer you some cash to consider it? >> >> I understand I *could* learn code for my emacs.init to do that, but it >> seems like a change that would be broadly beneficial to new Emacs & >> ESS users. I preach the message about Emacs to the students here, but >> little quirks like this seem like an unnecessary hassle. > > Its likely to be fixable, but first it might be worth hearing Martin's > views on this, as he may deal with differing commenting styles a lot in > R-core. > > Stephen -- Paul E. Johnson http://pj.freefaculty.org Director, Center for Research Methods and Data Analysis http://crmda.ku.edu To write to me directly, please address me at pauljohn at ku.edu. __ ESS-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/ess-help
Re: [ESS] Ever consider changing indentation on #?
hi Paul, > "what the Hell, the folding is borked!". This is more and more common > with the adoption of markdown-style commentary within R files. can you give an example of the markdown-style commentary? > Until now, I've said "too bad" when they complain about their code, > but now I'm thinking we ought to consider changing the behavior of > Emacs/ESS. Does it really really need to do # indentation that way? > Why? I've always thought it is odd. And counterintuitive. In what > backwards world would one suppose # gets the most indent, while ### > gets none?. I don't see any benefit in that # indentation that way. I > do see a big benefit in the ## indent at the code level. I'm only > quibbling about #. just for background context, ESS follows the Emacs convention for comments (### for column 0, ## for same level, # for col 32 or more), that is used widely in elisp. It is probably fair to say though that these conventions are not widely known outside of Emacs. > Would you ever consider changing the ESS default for R files so # is > flush left? Could I offer you some cash to consider it? > > I understand I *could* learn code for my emacs.init to do that, but it > seems like a change that would be broadly beneficial to new Emacs & > ESS users. I preach the message about Emacs to the students here, but > little quirks like this seem like an unnecessary hassle. Its likely to be fixable, but first it might be worth hearing Martin's views on this, as he may deal with differing commenting styles a lot in R-core. Stephen __ ESS-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/ess-help