5 Tips for Success
1. Write your code from scratch.
If you write your own code from the beginning, once you finally get it working, you’ll probably understand how every single line of it works, and you’ll be able to use this wisdom later when you’re trying to solve new problems. If you just copy and paste code from the tutorials and try to edit it until it works, you’ll make lots of avoidable mistakes and this will prolong your work process. In the long run, your programming instincts will be much weaker and this will make you less productive and less sucessful as a programmer.
2. Write your code a few lines at a time.
Start by writing just enough to get some of your code working, regardless of what you’re trying to do. Then keep adding to it until the next part works, and so on and so forth until your task is complete.
3. Write your code in R scripts instead of just using the console.
This makes it easier to keep track of your code as you modify it. It is much easier to scroll through an R script than it is your console history. Also, R only saves console history for one session at a time. This means that if you don’t save your code somewhere and then you close RStudio, your code will be lost forever.
If you write code down in a script, RStudio will also save it as part of your project so you won’t lose it if RStudio freezes or crashes for some reason. This will happen even if the script itself is not saved.
This means that while you’re working on your code for a lab, you should open a new R script together with your RMarkdown document. Copy code from your R script into your RMarkdown document when you think it’s ready for submission.
R scripts will not be evaluated. But using them will make it easier for you to do your work.
3. Don’t copy and paste other people’s code into your own programs.
It’s pretty much never a good idea to copy and paste somebody else’s code into your own program. The other person’s code may have things in it that you think will be useful for your own program. But blindly copying and pasting somebody else’s code into your own program and hoping that this will make your program start to work will only disappoint and frustrate you.
And of course there’s also the issue of plagiarism. Coding is hard work, and no one likes it when something they’ve worked hard on gets stolen.
4. Try to learn from other people’s code.
Sometimes you’ll come across code which will make you say, “I wish I knew how to do that!” Bookmark the page where you found it. Copy and paste the code into a script to study later. Try to think of ways that you can incorporate those cool tricks into your own work. And never stop doing this.
5. Search the internet for coding tips when you get stuck.
If you’re thinking about a career that involves data analysis or writing computer code in some way, you will have to do this a lot no matter how good you get. Adapting tips that you find on the internet into solutions to problems you face as a programmer will be very hard at first, but you’ll get better and better at it with practice.
6. Search the internet if you don’t understand an error message that R returns.
Sometimes error messages are impossible to interpret on their own because their wording is too vague or too technincal. But if you copy and paste these messages into Google, you can find discussions that people have had about them. By reading these discussions, you can find out what these messages mean in plain English. Hopefully this will help you figure out how to stop getting that error message.
7. Read the help files for functions you’re having trouble using.
Make sure you’re entering values for all the mandatory arguments for a given function. Also make sure you read about what the optional arguments are used for. You may want to modify some of those optional arguments later. And you may have to modify some of them to get your code working in exactly the way you want.
8. Tinker, experiment, explore! Never stop learning!
It takes a lot of practice to become good at programming, so try to look for opportunities to do it. This could be as simple as making up extra questions for yourself to extend a lab assignment on your own. It could be as complex as learning how to perform something called web scraping so that you can collect your own data from websites that contain information that interests you but is not yet in a readily analyzable format. You can also read books like Data Science with R by Hadley Wickham for a much broader overview of what’s possible with this language.
Just remember that regardless of how good you get at any type of programming, this is a field that is always rapidly advancing and you will always have to keep learning new things in order to keep up with trends.