Skip to content

Multi-line comments in R

2 messages · Barry Rowlingson, Gabriel Becker

#
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
#
On Thu, Aug 20, 2015 at 8:23 AM, Barry Rowlingson <
b.rowlingson at lancaster.ac.uk> wrote:

            
Well, my guess is that the string, when created, would be interned in the
global string cache. That's unlikely to have any real bearing on anything R
is doing, but it is technically an effect.

Also, in the script case/top-level-expression it would affect .Last.value,
I think, though not in the particular case you posted.

~G