Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Text values
Variables
Functions
23. Comments
Summary

Instruction

Great job! Now, let's take a look a short piece of a code that uses several of the functions we've learned:

 #These functions take text values as arguments
 
 #substr returns first 8 characters from string
 first_eight <- substr("comments are useful", 1, 8)

 #nchar takes a string and returns a number
 name <- "Mary"
 name_num_letters <- nchar(name)
You probably noticed that several lines in the block of code above start with the pound symbol, #. These are comments in R. Anything that follows a # on one line is considered a comment.

When R sees #, it simply skips the rest of the line and moves on to the next one. Nothing happens when you write a comment in your code. These are just used for the purpose of documentation or clarification.

Exercise

Have R display the number of characters in your name. Before you do so, write your name in a comment. Don't forget that comments start with #.