Skip to content
Prev 50859 / 63421 Next

Multi-line comments in R

On Wed, Aug 19, 2015 at 5:16 AM, Nathan Esau <nesau at sfu.ca> wrote:
Python doesn't have a multi-line comment.

 You can use triple-quoted strings in Python to quote a large chunk of
text, which won't generate any bytecode and so has no executable
effect:

def foo(x)
 y = x * 2
 """
 well what now
 lets have a comment
 """
 return(y)

A similar thing is possible in R:

 foo = function(x){
    "this is a test.
where
you can comment"
    return(x*2)
}

However I don't know if this causes any executable effect - its
possible R evaluates the string in some way.... Anyone want to test.

Yes, you have to escape any string quote marks in your comment, but in
python you have to escape any triple-quote marks.

Barry