1.7 Notation throughout this book
When mentioned in the text, the names of R packages are in bold font, e.g., ggplot2, whereas functions, objects, and variables are printed with mono-spaced font, e.g filter()
, mean()
, lifeExp
. Functions are always followed by brackets: ()
, whereas data objects or variables are not.
Otherwise, R code lives in the grey areas known as ‘code chunks’. Lines of R output start with a double ## - this will be the numbers or text that R gives us after executing code. R also adds a counter at the beginning of every new line; look at the numbers in the square brackets [] below:
## [1] 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
## [16] 1016 1017
Remember, lines of R code that start with # are called comments. We already introduced comments as notes about the R code earlier in this chapter (Section 1.1 “Help, what’s a script?”), however, there is a second use case for comments.
When you make R code a comment, by adding a # in front of it, it gets ‘commented out’. For example, let’s say your R script does two things, prints numbers from 1 to 4, and then numbers from 1001 to 1004:
## [1] 1 2 3 4
## [1] 1001 1002 1003 1004
If you decide to ‘comment out’ the printing of big numbers, the code will look like this:
## [1] 1 2 3 4
You may even want to add another real comment to explain why the latter was commented out:
You could of course delete the line altogether, but commenting out is useful as you might want to include the lines later by removing the # from the beginning of the line.
Keyboard Shortcut for commenting out/commenting in multiple lines at a time: Control+Shift+C
(On a Mac, both Control or Command work)