12 Even more on Stack Overflow

Written by Annie Collins and last updated on 7 October 2021.

12.1 Introduction

Founded in 2008, Stack Overflow’s public platform is used by nearly everyone who codes to learn, share their knowledge, collaborate, and build their careers.

Are you having an issue (or many issues) with your R code? Need some help, but nothing in your learning materials seems to be working? Stack Overflow may be your new best friend.

Stack Overflow serves a few purposes, but your main interactions with the site will likely be in searching for help when you come across problems in your coding process.

12.2 Use cases

When someone posts a question to Stack Overflow, they can receive answers from a community of developers and other R users. These answers can then be up or down voted by the community, and ultimately the person who originally posted the question can decide to “accept” a single answer as the most correct or most useful.

Below are some ways you might use Stack Overflow to help overcome issues while you are coding. It is always a good idea to search through others’ posts before making your own — if you are struggling with something, it is likely someone has had a similar issue in the past!

  • Ambiguous errors: R is known for its ambiguous error messages, and if you have questions about an error you are receiving, there are questions and answers covering a large variety of messages.
  • Unexpected output: Sometimes you expect one outcome and get another. Stack Overflow users can often help explain function inputs and outputs in greater depth or a more user-friendly manner than original R documentation, or provide an extra set of eyes to look over the structure of your code for inconsistencies. If you make a post with your code, make sure it is comprehensive and reproducible (see Tips for Asking & Searching).
  • “What function/code will help me do ________?”: R Documentation in the RStudio Help tab can only get you so far, especially when you don’t know which function(s) to start with. Searching for keywords or functions that are similar to your desired outcome, or posting a description of your task and some code you’ve already tried can be a great way to fill in knowledge gaps or make your code more efficient.

Feel free to refer back to the lesson on Using Google and Stack Overflow for details on the specific features of a Stack Overflow question.

12.3 Tips for asking and searching

  • Descriptive titles: “ggplot problem” doesn’t tell users anything about what your issue might be. “How can I change the colour of my geom_point() plot?” immediately lets a reader know the function you are using and what your desired outcome is.
  • Example code and/or data: If you are asking for help in fixing an error in your code, it is important to let other users know what you have so far instead of just describing your issue. Similarly, an issue might be caused by the type or structure of your data, and it is important to indicate this when you ask for help (include simple, example data sets instead of large data sets that require a lot of explanation and may contain private information). Make sure all your examples are reproducible (see below).
  • Avoid asking subjective or broad questions: Stack Overflow is not a discussion board; it is a place for you to ask a direct question and (hopefully) get a direct answer. Make sure you’re asking questions that would ideally lead to a singular explanation or suggestion. Similarly, don’t post 100 lines of code that won’t run and expect an appropriate response. Reduce your questions to a specific few lines or functions.
  • Make sure you’re looking at R code: This will get easier as you gain experience in R and/or other coding languages, but there are some names, concepts, and functions that R shares with other languages and it can sometimes be hard to determine what exactly you’re looking at if you’re new to coding. If you find search results relating to your question, make sure the responses apply to R and RStudio. If you’re unsure, you can check the tags at the bottom of the question for r or rstudio, or include [r] or [rstudio] in your search.
  • Refine your search: Try the following criteria when searching within Stack Overflow:

As a member of the Stack Overflow community, you can build a reputation through asking good questions and engaging with others on the site, so these tips are not just important for getting your own questions answered.

12.3.1 Reproducible examples

A reproducible example is a snippet of code that is self-contained—it includes all necessary libraries, data, functions, and outputs that will allow another individual to look at your code, run it themselves, and understand any questions you have. R has a package called reprex that will help make this task easy (reprex also part of the tidyverse, so if you already have the tidyverse installed you’re good to go!). The reprex package allows you to copy some code, run the command reprex() , and then paste a formatted, reproducible example into a site like Stack Overflow. For more details on creating a reproducible resource in R, see the reprex documentation or view Jenny Bryan’s webinar on the topic.

12.4 Next steps

  • Once you’ve gotten the hang of coding in R, you can apply your new skills by helping others in the Stack Overflow community. Be sure to adhere to the same standards as above: be direct, use provided code and data, or provide your own where appropriate. Remember, your answer can be up or down voted by the community which will impact your credibility and reputation on the site.
  • If you’re ready to take your coding skills to the next level, Stack Overflow also hosts a job board advertising software, data science, and programming-related positions around the world.
  • For any more specific questions, see the Help Center maintained by Stack Overflow or look at their introductory tour.

12.5 Exercises

12.5.1 Question 1

12.5.2 Question 2

12.5.3 Question 3

12.5.4 Question 4

12.5.5 Question 5

12.5.6 Question 6

12.5.7 Question 7

12.5.8 Question 8

12.5.9 Question 9

12.5.10 Question 10