DAL tutorial - Week 9

Troubleshooting

1 Troubleshooting

Go to https://bookdown.org/yih_huynh/Guide-to-R-Book/trouble.html and read about common errors and how to fix them.

Terminology

The linked page talks about “loading libraries” and “loading packages”, but you know very well by now that we attach packages and we don’t “load libraries”.

For a technical explanation about loading vs attaching and packages vs libraries see: https://r-pkgs.org/dependencies-mindset-background.html#sec-dependencies-namespace and following sections.

2 Fix me!

The following code chunks have code that throws errors or generate mistakes (without throwing errors). Try to run them in R, study the error and fix the code!

Example 1:

a <- "2"
a + 1

Example 2:

Note: The goal of the following code chunk is to produce a tibble/data frame.

iris |>
  group_by(species) |>
  summary(
    mean = mean(Petal.Lengths)
  )

Example 3:

library(dplyr)
library(MASS)

iris |> 
  select(Species, Petal.Length, Petal.Width)

Example 4:

lirbary(tidyvrese)

starwars
  mutate(
    sex = fatcor(sex, level = c("female", "hermaphrodite", "male", "none"))
  ) |> 
  count(Sex)

Do all of the levels of the variable sex show up in your tibble/data frame of counts?

Example 4:

iris |> 
  ggplot(x = Species, y = Petal.Length) |> 
  geom_jiter()

Example 5:

bat <- tibble(
  id = c(A, B, C),
  response = rbinom(10, 1, 0.5)
)

cat(bat.response)

Example 6:

starwars %>% 
  filter(sex != is.na(sex)) %>% 
  ggplot(aes(x = mass, y = height, colour = sex, shape = sex) +
  geom_point() +
  scale_x_log10()
  labs(
    x = "Mass"
    y = "Height"
    colour = "Sex"
    shape = "Sex
  )

Example 7:

tucker2019 <- read_csv("data/tucker2019/mald_1_1.rds")

tucker2019 %>% 
  ggplot(aes(x = isword, y = RT, colour = ACC, fill = ACC)) +
  geom_jitter(
    alpha = 0.3,
    position_jitterdodge(),
  ) +
  scale_colour_manual(values = c("#dc050c", "#196b50", ))

3 Where to ask for help online

There are a few places you can ask for help online:

  • StackOverflow is always a good place to start. You should first check if your question or a similar one has been answered already (in most cases, it has!) and if not you can post your question. Make sure you include a Minimal Working Example.

  • Another place is the Posit Community. It’s similar to StackOverflow, but it is specific to R and RStudio related things.

  • You can also ask ChatGPT for help. It is usually good for programming/coding stuff, but not so much for statistics.

  • If you have issues with specific R packages, you could open an issue on GitHub on the respective package repository to let the developer know about the issue.

  • In most cases, even just searching for your question using any web search engine will take you to the right places.

Disclosing help in assessments

Note that if you ask for help online as part of your assessment and you receive an answer (either by a human or by AI), you are obliged to disclose it in your assessment.

Asking for help won’t impact your mark, but make sure that proper attribution is given in the assessment (for example, if somebody shared some code with you, you should acknowledge the author of the code).