2.2 Best practise and variable naming conventions
Some quick best practice tips:
- Best practice suggests that you should not assign meaningless names to variables; give a variable a succinct but meaningful name that will be of value to understand which information you have saved.
df
may be an obvious name for a data.frame, butphenotypeDf
orphenotype.df
may be more memorable later on in your analysis.- you can use camelCase (or camelNotation), underscore (_) or fullstop (.) for variable names in R.
You can create thousands of variables in your R workspace but are they all necessary? It is worthwhile performing housekeeping on your data collection if you are creating many variables.
If you have many variables in your R workspace then you may not be using the most ideal method to store your data. Consider data structures like
data.frame
andlists
to better structure your data.RStudio allows you to remove all objects from your workspace by using the Clear button in the Environment tab as an alternative to the command:
rm(list=ls())
. (You can follow this with thegc()
function for garbage collection to further ensure that memory has been freed up.)