是否可以在R中有多行注释? [英] Is it possible to have a multi-line comments in R?
问题描述
我发现这个旧主题</a>(来自一年多以前),这解释了R如何不支持多行注释(例如/ PHP的/ *注释* /)。
I found this old thread (from over a year ago), which explains how come R doesn't support a multi-line comments (like /* comment */ of PHP, for example).
我想知道这是否已在过去一年中解决,或者如果有其他替代品? (例如,在notepad ++和npptor中,你可以标记一行,并按ctrl + q将它们标记为注释,是否有其他IDE类似的解决方案?)
I am wondering if this has been resolved in the past year, or if there are other alternatives? (For example, in notepad++ with npptor, you can mark a bunch of lines and press ctrl+q to mark them all as comments, are there similar solutions for other IDE's ?)
推荐答案
如果你愿意,你可以使用独立的字符串多行注释—我一直认为比 if(FALSE){}
更漂亮。该字符串将被评估,然后被丢弃,因此只要它不是一个函数的最后一行,就不会发生任何事情。
You can, if you want, use standalone strings for multi-line comments — I've always thought that prettier than if (FALSE) { }
blocks. The string will get evaluated and then discarded, so as long as it's not the last line in a function nothing will happen.
"This function takes a value x, and does things and returns things that
take several lines to explain"
doEverythingOften <- function(x) {
# Non! Comment it out! We'll just do it once for now.
"if (x %in% 1:9) {
doTenEverythings()
}"
doEverythingOnce()
...
return(list(
everythingDone = TRUE,
howOftenDone = 1
))
}
b $ b
主要的限制是,当你注释的东西,你必须看你的引号:如果你有一种内部,你必须使用另一种类的评论;如果你有一些东西像字符串与'postrophes在块内,那么没有办法这种方法是一个好主意。但是仍然有 if(FALSE)
阻塞。
两种方法都有的另一个限制是,只能在表达式在语法上有效的地方使用这样的块 - 没有注释掉部分列表,
The other limitation, one that both methods have, is that you can only use such blocks in places where an expression would be syntactically valid - no commenting out parts of lists, say.
关于在IDE中做什么:我是Vim用户,我找到
NERD评论员一个完美的工具,快速评论或取消注释多行。
Regarding what do in which IDE: I'm a Vim user, and I find NERD Commenter an utterly excellent tool for quickly commenting or uncommenting multiple lines. Very user-friendly, very well-documented.
最后,在R提示符下(至少在Linux下),有一个可爱的 Alt Shift - #可注释当前行。非常高兴把一条线搁置,如果你正在一个单线,然后意识到你需要一个准备步骤先。
Lastly, at the R prompt (at least under Linux), there's the lovely Alt-Shift-# to comment the current line. Very nice to put a line 'on hold', if you're working on a one-liner and then realise you need a prep step first.
这篇关于是否可以在R中有多行注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!