    Thanks to Brian & David!  For some reason, I'd thought to use "{", but
not "(".  I guess I can chalk that up to a slow brain.  Interestingly (and I
didn't bother to figure out why), the "{" didn't work for me.  But I tried a
few cases, and "(" always seems to work, so far.

                              Regards,
                                       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


On Wed, Jan 12, 2011 at 6:08 PM, Brian Diggs <diggsb@ohsu.edu> wrote:

> On 1/12/2011 2: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:
>>
>>         numericColumns<- names(listOfDataFrames[[myDF]][,columnsOI])
>>                     [sapply(listOfDataFrames[[myDF]][,columnsOI],
>> is.numeric) ]
>>
>
> You can put the right hand side of the assignment in parentheses. Then even
> with the same breaks, the first line is not complete, so R will continue
> parsing.  An emacs still indents reasonably. (I added a second line break to
> try and avoid email wrapping affecting things).
>
>
> 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.
>>
>
> Putting the right hand side in curly braces might work too.  That would
> turn it into a code block, which should evaluate to whatever the last
> statement in the code block is (which in this case is the only statement).
>  I wouldn't be surprised if there is some case where curly braces might lead
> to a different result; parentheses shouldn't (but I may be wrong).
>
>                                             Thanks!
>>                                                    Mike
>>
>
> --
> Brian S. Diggs, PhD
> Senior Research Associate, Department of Surgery
> Oregon Health & Science University
>

	[[alternative HTML version deleted]]

