[R] syntax for extending a line in a script??
David Winsemius
dwinsemius at comcast.net
Thu Jan 13 00:16:37 CET 2011
On Jan 12, 2011, at 5:46 PM, Mike Williamson wrote:
> Hello,
>
> A hopefully simple question. I use 'R' through emacs, but I
> suspect the
> following would occur with any manner of text editor:
>
> - my editor has a normally quite handy feature where it will
> automatically indent to the appropriate level when I start a new
> line.
> However, this occasionally creates cases where there is no
> friendly way to
> break a long line of code into two lines which still function as one
> command. Therefore, I need a nice way to be able to flag 'R' to
> know that
> the code is continuing on the next line. Let me explain via
> example:
My practice is to use the opening of a paired code delimiter like "["
or "(" at the end of a line as I have modified your code to show:
>
> numericColumns <- names(listOfDataFrames[[myDF]][,columnsOI])[
> sapply(listOfDataFrames[[myDF]]
> [,columnsOI],
> is.numeric) ]
>
> As you can see in this case, I would *like* for these 2 lines of
> code to
> be read as 1 line, but since the "names(<blah>)" command is
> sufficiently a
> command on its own, 'R' see this as a completed line of code. I
> could try
> to break it up at different points, but emacs (and other text
> editors) takes
> a guess as to the most intelligent way to indent, so that if I were
> to write
> something like:
>
> numericColumns <- names(listOfDataFrames[[myDF]][,columnsOI])
> [sapply(
> listOfDataFrames[[myDF]][,columnsOI],
> is.numeric) ]
>
>
> it would actually indent something more like this:
>
> numericColumns <- names(listOfDataFrames[[myDF]][,columnsOI])
> [sapply(
>
> listOfDataFrames[[myDF]][,columnsOI], is.numeric) ]
>
>
> and as you can see, that doesn't help the issue of preventing the
> code from
> wrapping around (and therefore doesn't help readability). Is there
> some
> simple way to flag that the next line is continuing? Something like
> python's "\" at the end of a line? I tried wrapping the whole thing
> around
> curly braces { } but that didn't work, either.
>
> Thanks!
> Mike
>
>
> "Telescopes and bathyscaphes and sonar probes of Scottish lakes,
> Tacoma Narrows bridge collapse explained with abstract phase-space
> maps,
> Some x-ray slides, a music score, Minard's Napoleanic war:
> The most exciting frontier is charting what's already here."
> -- xkcd
>
> --
> Help protect Wikipedia. Donate now:
> http://wikimediafoundation.org/wiki/Support_Wikipedia/en
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list