多行评论解决方法? [英] Multiline Comment Workarounds?

查看:123
本文介绍了多行评论解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我(类)已经知道这个问题的答案。但我认为这是一个被频繁地问R用户列表,应该有一个坚实的好回答。 据我所知,R中没有多行注释功能。所以,有没有任何好的解决方法?

I (sort of) already know the answer to this question. But I figured it is one that gets asked so frequently on the R Users list, that there should be one solid good answer. To the best of my knowledge there is no multiline comment functionality in R. So, does anyone have any good workarounds?

在R中的工作通常涉及交互式会话(这引起了对多行评论的需要的怀疑),有时我不得不向同事和同学发送脚本,其中大部分涉及非重要的代码块。对于来自其他语言的人来说,这是一个相当自然的问题。

While quite a bit of work in R usually involves interactive sessions (which casts doubt on the need for multiline comments), there are times when I've had to send scripts to colleagues and classmates, much of which involves nontrivial blocks of code. And for people coming from other languages it is a fairly natural question.

在过去,我使用了引号。因为字符串支持换行符,用

In the past I've used quotes. Since strings support linebreaks, running an R script with

"
Here's my multiline comment.

"
a <- 10
rocknroll.lm <- lm(blah blah blah)
 ...

工作正常。有没有人有更好的解决方案?

works fine. Does anyone have a better solution?

推荐答案

相当定期出现在邮件列表,请参阅例如这个最近的线程在r帮助。共识的答案通常是上面显示的一样:鉴于语言没有直接支持,你必须

This does come up on the mailing list fairly regularly, see for example this recent thread on r-help. The consensus answer usually is the one shown above: that given that the language has no direct support, you have to either


  • 使用编辑器具有区域到注释命令,并且大多数高级R编辑器

  • 使用之前建议的 if(FALSE)仍然需要完整的解析,因此必须在语法上正确。

  • work with an editor that has region-to-comment commands, and most advanced R editors do
  • use the if (FALSE) constructs suggested earlier but note that it still requires complete parsing and must hence be syntactically correct

这篇关于多行评论解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆