The past few weeks I have been writing R scripts for some of the research that I have been doing. In the process I have been looking at code from published studies that have been put into GitHub repositories and I have also been speaking with a friend of mine who codes (not R).
In conversations with my friend, I noticed that there are a lot of differences in how we as researchers write our code compared to within the actual coding industry. And I understand that we are ecologists and not coders, and so either we haven't been taught correct formatting or certain practices, or that some of the industry standards for "coders" might be excessive for us to follow.
For example, my friend asked me about writing multiple scripts. In many of the repositories that I have seen, there are multiple R scripts used, however as my friend pointed out it is a common for small scripts to be put together as a single script. Is there any sort of standard for this when it comes to using R for research, or does this just come down the researcher's personal preference?
Another example I recently saw in a repository (containing the code from a published study), was the use of the function `write.csv()` within a for loop. When my friend saw this, he suggested that I immediately remove that line of code as that is a quick way to shorten the life of your SSD. He pointed out that that is a very poor coding practice. Since I have not been trained as a coder, but rather trained to use a R as a tool for statistical analysis, this is something that I did not know, and probably wouldn't have easily learnt had he not pointed this out to me.
Considering the increase in the use R for ecological research (Article A comprehensive analysis of R's application in ecological re...
), do we need to set some sort of industry standards when it comes to writing code? Do we need to start teaching undergraduate students not only how to write code to do their analysis, but to also teach them how to code efficiently and with good practices?I am curious to hear any other opinions on this matter!