4.1: Using Comments

Learning Statistics with R - A tutorial for Psychology Students and other Beginners · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-SA 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    4.1: Using Comments

    Before discussing any of the more complicated stuff, I want to introduce the comment character, #. It has a simple meaning: it tells R to ignore everything else you’ve written on this line. You won’t have much need of the # character immediately, but it’s very useful later on when writing scripts (see Chapter 8). However, while you don’t need to use it, I want to be able to include comments in my R extracts. For instance, if you read this:41

    seeker <- 3.1415           # create the first variable
    lover <- 2.7183            # create the second variable
    keeper <- seeker * lover   # now multiply them to create a third one
    print( keeper )            # print out the value of 'keeper'
    ## [1] 8.539539

    it’s a lot easier to understand what I’m doing than if I just write this:

    seeker <- 3.1415
    lover <- 2.7183
    keeper <- seeker * lover
    print( keeper ) 
    ## [1] 8.539539

    You might have already noticed that the code extracts in Chapter 3 included the # character, but from now on, you’ll start seeing # characters appearing in the extracts, with some human-readable explanatory remarks next to them. These are still perfectly legitimate commands, since R knows that it should ignore the # character and everything after it. But hopefully they’ll help make things a little easier to understand.


    This page titled 4.1: Using Comments was last modified on Mon, 08 Jan 2024 09:04:19 GMT and is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Danielle Navarro via source content that was edited to the style and standards of the LibreTexts platform.