So, you have a problem with programming or data analysis? Take heart! There is help to be had.
Click the tab above which best describes your problem. I’m rooting for you!
And why do we fall, Bruce? So we can learn to pick ourselves up.
Batman Begins, 2005
Watch until 00:38. But then you should get back to describing your problem ☝
Describe and recreate your problem using the template below. or download Rmd template.
Fill in the points as explained below and send to your helper. Make a copy of your code before you turn it into a reproducible example. This may take a bit of work. This is perfectly normal, and you learn a lot in the process.
I have a problem with R code, markdown or knitting. (Mouse over the dotted words for explanations.)
This is what I’m trying to achieve: Explain the overall purpose of what you’re doing. If you’re working from an exercise or tutorial, copy its URL from your browser’s address bar. It you’re working from an R help entry, cite it as e.g. ?plot
This is how far I’ve got on my own: Make it easy for your helper to retrace your steps up to where you need help. Explain briefly what you do, and attach executable code as a .R or .Rmd file. This should be runnable from a fresh R session, perform everything that precedes your problem, and then exhibit the problem.
In many cases, you will already have an R or Rmd file exhibiting your problem. If not, you’ll have to create a new file. Insert the R commands which led to your problem. Load the packages you used. If you’re working with a dataset, read the data from a file or make simplified dummy data by using R code. To help in recalling exactly what you tried, the command history in the Console and History tabs are helpful.
This is where things go wrong: Once you’ve gathered your problematic code in a file, verify that the file does indeed reproduce the problem, that is, it gives the same error again when you run it from a fresh R session. The quickest check for this is knitting: 🧶 Knit
(for .Rmd files) or 📓 Compile Report
(for .R files).
Click ▶ for the outcome you observe:
Knitting completes, and the report shows the wrong result that you want help with. Yay!
Great! Move on to explaining what outcome you were expecting or what you want instead.
(If you have some coding experience, you can make helping you easier by removing text and code chunks situated below your current problem. Anything after the problem is usually not relevant.)
Knitting completes, the report looks just like it’s supposed to, and your problem is gone! Yay! (But…huh?)
It’s not uncommon for problems to go away when you try to debug them systematically. Smile, try restarting R (RStudio > Session > Restart R), and check if you’re rid of the problem.
Problems which go away on restarting R, are often caused by something you did inadvertently in the Console, e.g. redefining and existing function or variable in R.
Knitting crashes with the same error message as the one you require help with. Yay!
If knitting does not complete, RStudio keeps the “R Markdown” tab open. Check that the sub-tab Issues
shows the same error you’re asking about. If so, you have a reproducible problem and can move on in your error description.
(If you have some coding experience, you can make helping you easier by removing text and code chunks situated below your current problem. Anything after the problem is usually not relevant.)
Knitting crashes with a different error message than the one you require help with. That sucks!
This is very common, also for experienced programmers.
If knitting does not complete, RStudio keeps the “R Markdown” tab open. Okay, so the sub-tab Issues
shows a different error than you’re asking about. Luckily, chances are good you will understand why.
Maybe you failed to include in your program something you did in the Console, such as loading a library
or defining a variable. Look through your History tab and include any missing setup code in your program file, then try again.
Or maybe you’re trying to read a file which your program does not find. In that case, see the “Know where you are” section of File management for the aspiring programmer.
Try to fix these stumbling blocks so you can recreate the problem you’re really struggling with. If you can’t figure out how, ask for help about the first stumbling block you cannot get past. Feel free to mention your original problem too.
This is how things go wrong: Exactly what happens on your computer when you run the code you made? Copy and paste any error messages or incorrect output: As text if possible, or as a picture if your problem is with a figure.
What were you expecting to happen? Describe in words. Sometimes you can also create an R object illustrating the desired result of your code. This clarifies your objective to your helper and makes it easy to verify whether a suggested solution works as desired.
This is what I’ve tried thus far: State to your helper exactly what you have searched for, and explain if any of the hits were some help, or why not.
❤️ CONGRATULATIONS! ❤️ You now have a clearly formulated, reproducible problem. Send it to your helper!
Attach the .R or .Rmd file demonstrating the problem. If your code is less than about ten lines, feel free to paste it directly into the message – as text, not a picture. Then your helper can paste the code right into their own Console, and hopefully experience the same problem as you.
Helping you will now be quick and efficient. And you’ve probably learned a lot along the way already!
Describe and recreate your problem using the template below. (Download Rmd template.)
Fill in the points as explained below and send to your helper. Make a copy of your code before you turn it into a reproducible example. This may take a bit of work. This is perfectly normal, and you learn a lot in the process.
I’m unsure about the next step in my coding. (Mouse over the dotted words for explanations.)
This is what I’m trying to achieve: Explain the overall purpose of what you’re doing. If you’re working from an exercise or tutorial, copy its URL from your browser’s address bar. Briefly describe which next step or improvement you need help with.
This is how far I’ve got on my own: Make it easy for your helper to retrace your steps up to where you need help. Explain briefly what you do, and attach executable code as a .R or .Rmd file. You already have a file where you’re writing your code. Now you need only ensure that it can be run without errors in a new, fresh R session.
If your example code won’t knit, click here.
This is very common, also for experienced programmers.
Visit the guide “My R code is not working”, but skip right to “This is where things go wrong” and its last item, “Knitting crashes with a different error message than the one you require help with”. The advice there helps you get past any minor annoyances to recreate the problem you’re really struggling with. If you can’t figure out how, ask for help about the first stumbling block you cannot get past. Feel free to mention your original problem too.
This is my best attempt so far: Show how you try to carry out your plan. Specify exactly what happens on your computer when you run the code you’ve written: As text if possible, or as a picture if your problem is with a figure.
This is the next step I want: Describe in words and perhaps a pen-and-paper sketch what you wish would happen. Sometimes you can also create an R object illustrating the desired result of your code. This clarifies your objective to your helper and makes it easy to verify whether a suggested solution works as desired.
This is how I’ve tried to find a solution:
library(vembedr)
for a package, or ?strsplit
for a function, and your helper will find the documentation on their own.)❤️ CONGRATULATIONS! ❤️ You now have a clearly formulated, reproducible problem. Send it to your helper!
Helping you will now be quick and efficient. And you’ve probably learned a lot along the way already!
The first step towards solving a totally uncool problem is making it happen again! , Fill in the points as explained below and send to your helper. It is perfectly normal that a reproducible description of a problem requires some effort. Take comfort in the fact that it is essential for anybody to be able to help you.
❤️CONGRATULATIONS! ❤️ You now have a clearly formulated, reproducible problem. Send it to your helper!
Helping you will now be quick and efficient. And you’ve probably learned a lot along the way already!