So, you have a problem with programming or data analysis? Take heart! There is help to be had.

Guide to asking effective questions

Find the right guide!

Click the tab above which best describes your problem. I’m rooting for you!

Jon Olav Vik. Photographer: Håkon Sparre
Jon Olav Vik, responsible for
STIN100 Biologisk data-analyse and
STIN300 Statistical programming in R.

Words of wisdom

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 ☝

My R code is not working

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.

    • If your problem is about an error message: Google the error message by copying it from RStudio to the search/address bar of your browser.
    • If your problem is about an R function: Use the function’s help text and make sure you understand what data type it expects as input. Work through some of the code examples at the bottom of the help page, familiarizing yourself with how the function behaves when it’s working as intended.
    • If the error message and help text do not help, try other search terms describing what you’re trying to achieve.

❤️ 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!

I’m unsure about the next step in my coding

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.

    • Load the packages you’re using.
    • If you’re working with a dataset, read the data from a file or make simplified dummy data by using R code.
    • …and insert R code to let your helper retrace your steps up to where you need help.

    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:

    • Google it. State exactly which terms you used (it’s right there in your browser; copy and paste) and explain if any of the hits (paste URL) look promising. If you’ve found someone’s solution to a similar problem and are struggling to transfer that solution to your own case – that’s a great start! Make sure to provide the URL and clarify “This is what I’m trying to achieve” as best you can.
    • Also state if you looked in help texts (which ones?), textbooks (URL or title) or R package documentation (which package?) Provide hyperlinks (you already have them, remember) to save your helper’s time. (For R functions, links are not needed. Just specify e.g. 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!

I have a problem outside of R

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.

  • I have a problem outside of R. This could be, for instance, error messages or strange behaviour in your web browser, file manager, Windows or macOS.

  • This is what I’m trying to achieve: Explain the overall aim of what you’re doing. If you’re working from an exercise, tutorial or help text, copy its URL from your browser to your problem description.
  • This is what I do that is not working: Make it easy for your helper to retrace your steps and experience what you experienced. Explain exactly what you do that leads up to the error or problem. What menus, buttons or similar do you click, and exactly what do any error messages say? Copy error messages as text if you can; screenshot or mobile photo or video if necessary. Feel free to include a screenshot in addition to an error message if you think it may help.
  • This is how things go wrong: Exactly what happens on your machine? What were you expecting instead?
  • This is how I’ve tried to find a solution: Google it. State exactly which terms you used (it’s right there in your browser; copy and paste) and explain if any of the hits (paste URL) look promising.
  • My operating system is: E.g. “Windows 10” or “macOS 11.4”. This is important information because screen layouts and such often vary between systems and versions.
  • My web browser is: E.g. Chrome, Firefox, Safari, Edge.
  • My problem behaves the same/different in another browser: If your problem is with a web page, and you have installed another browser, try to recreate your problem in the other browser. If the problem goes away, yay! Feel free to alert your helper anyway, so we can share your solution with others.
  • My problem behaves the same/different on my friend’s computer: If possible, check if the problem seems specific to you. Inform your helper whether you have tried your reproducible problem description on a friend’s computer. State whether they had no problems, the same problem, or a different problem.

❤️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!