# This is how you type a comment. The following is code:
2 + 2[1] 4
To use R you need to pass a series of commands to the console that will perform the analyses you want. Instead of just remembering everything you’ve done and typing the commands directly on the console, it is useful to use a text editor and create a script, in which you can keep track of what you want to do. RStudio has a built-in text editor that highlights the different elements used in R language, so it can be very useful. With it you can type all the functions and commands you need and save them in a .R script format. But you can also use any other text editors you like and have your script saved as a .txt file instead. As long as you pass the commands to the console, everything is fine. From now one, we will be using the RStudio text editor.
Everything you type in the script can be interpreted either as code, unless you tag it as code:
# This is how you type a comment. The following is code:
2 + 2[1] 4
Code should be thought and written in a self-explanatory manner. But, at least when you are learning, commenting your code will be very helpfult to remember what (and how) you did before. It is also very useful to keep a cohesive and clean code. Use for example a series of hashtags (#) to create section breakers with titles, and also try to avoid very long lines, breaking the code when possible.
################################################################################
# This is a new section
# Instead of writing like this:
plot(x = SCL, y = SCm, log = "xy", main = "Skull vs. carapace length in Chelidae", xlab = "Carapace length (SCL)", ylab = "Skull lenght (SCm)", bty = "l", cex = 0)
# Try like this
plot(x = SCL,
y = SCm,
log = "xy",
main = "Skull vs. carapace length in Chelidae",
xlab = "Carapace length (SCL)",
ylab = "Skull lenght (SCm)",
bty = "l",
cex = 0)