I wanted to comment out 20 lines that I'm moving to a function but
didn't want to delete them. Is there no defined way to get around
using a # on each of the 20 lines?
Thanks,
Mark
______________________________________________
R-h...@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.
This issue has come up before, and as far as I know there is no
multiline comment. However, there are a few ways of commenting out
larges pieces of code.
- Use a good text editor, Kate (KDE) allows you to select the 20 lines
and press Ctrl-D to comment them all at once.
- Use a setup like:
if(FALSE) {
line1
...
line20
}
And set FALSE to TRUE if you want to let the code be executed.
These are probably not the only ones, but this is what I could think of
right now.
cheers and good luck,
Paul
--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone: +3130 274 3113 Mon-Tue
Phone: +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul
> I wanted to comment out 20 lines that I'm moving to a function but
> didn't want to delete them. Is there no defined way to get around
> using a # on each of the 20 lines?
Just like you, I have been longing for that myself. It seems that the
answer is negative, so I have ended up using
if (1==0)
{
# code goes here
}
although is not really nice to look at.
--
Michael Knudsen
mickn...@gmail.com
http://lifeofknudsen.blogspot.com/
Hmmm I think this might be a FAQ... Usual suggestions are:
1. use an editor that can do un/commenting of regions.
2. Stick it in an if(FALSE){ ... } block, but that's only good if
it's syntactically correct.
I prefer:
3. Manage your code under a decent SCM and don't fear the delete.
Barry
This topic has come up before and the answer seems to be no, although
you can do tricky things like defining a function containing the
comment as a quoted string (beginning and ending with quote marks), or
putting a quoted string after an if() for a condition that isn't met.
It helps that line breaks are allowed in quoted strings.
However
With (x)emacs and ESS, you can say
M-x comment-region
after defining a region with point and mark.
I got tired of typing this, so I defined the following in my
.xemacs/init.el and .emacs files:
(global-set-key "\M-r" 'comment-region)
So now I do it with "alt-R". That key may have had some other
purpose, but not one I ever used.
I think the alt key is something else on a Mac. And I have no idea
whether this will work on Windows.
Jon
--
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron
> What editor are you all using to write R code? Many will have ways of doing what you want, e.g., comment-region (bound by default to M-; through comment-dwim) in Emacs.
Cool! I'm using Xcode, and I have just realized that cmd+/ will make a
block comment. By default it adds '//' instead of '#', but I guess
that it can be fixed somehow.
However, this is somewhat dated, and you may find others not here just by
googling on "R Editor", "R IDE", etc.
Bert Gunter
Genentech Nonclinical Biostatistics
-----Original Message-----
From: r-help-...@r-project.org [mailto:r-help-...@r-project.org] On
Behalf Of Michael Knudsen
Sent: Wednesday, July 22, 2009 8:35 AM
To: Erik Iverson
Cc: r-help
Subject: Re: [R] Multi-line comments?
On Wed, Jul 22, 2009 at 6:25 PM, Bert Gunter<gunter...@gene.com> wrote:
> You can find a list of IDE's/R code editors for R here:
> http://www.sciviews.org/_rgui/projects/Editors.html
>
> However, this is somewhat dated, and you may find others not here just by
> googling on "R Editor", "R IDE", etc.
>
Missing from the list are the cross-platform: Geany, SciViews-K, JGR.
A future addition will be the promising jEditR [1].
Another such list is on Wikipedia. It is also worth searching the ML
archives, since similar discussions popped-up several times.
Liviu
[1] http://romainfrancois.blog.free.fr/index.php?post/2009/07/08/useR!-slides
______________________________________________
Thanks for the free marketing... at the moment we are dealing with
installation procedures, so I would not say it is ready for prime time
just yet.
The old list of R editors (and guis) should really be moved away in the
R wiki or something so that people can update it more often, and also
perhaps people could then review/rank their preferred tool.
Romain
--
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/tlNb : RGG#155, 156 and 157
|- http://tr.im/rw0p : useR! slides
`- http://tr.im/rw0b : RGG#154: demo of atomic functions