This tutorial is all about manipulating spreadsheets/data.frames/tables.
Comments are little notes that you can put inside your code chunks to remind yourself what you are doing.
The confusing part about comments is that they also use the # (hash) symbol:
Look at your script. You should now know that in the TEXT AREA, the # symbol means “new heading”. (See Tutorial 4 for a reminder)
However, INSIDE A CODE CHUNK, the # symbol tells R to “ignore” anything after it. This means you can add in notes to yourself about the commands you are running. You need a new # for every line you want to be a commenrt
For example, without the #, R would give an error. But as soon as it’s there, R will ignore the text:
I like to put my comments in little boxes to make things easier to read:
#--------------------------------------
# Calculate the sum 1+1 & assign to x
#--------------------------------------
x <- 1+1
Comments are GREAT. You can put notes to yourself in there, explain the programming bit (allowing your text to focus more on analysis), or leave “how-to” guides.
Website created and maintained by Helen Greatrex. Website template by Noli Brazil