ETC3250: Tutorial 1 Help Sheet

Exercise 1

Part A

The following code generates an error, can you work out why?

library(dplyr)
library(MASS)
library(palmerpenguins)
p_sub <- penguins |>
  select(species, flipper_length_mm) |>
  filter(species == "Adelie")

I suggest googling “how to debug code” if you dont know where to start. A good first step is to run the code and google your error, or run the code line by line to work out where the error is coming from. Getting good at debugging is getting good at coding, its 90% of the pain.

Run the code ?select which should produce the help sheet for the function causing the error.

You can specify which package a function should come from using :: , i.e. ggplot2::ggplot() will specify that you want to use the ggplot() function that comes from the ggplot2 package. An example of where this is useful is when you are only using one function and don’t want to load the entire package, but there are other uses for this…

Part B

Use the reprex package to create a text where the code and error are visible (for the code block in part A), and can be shared with someone that might be able to help.

Make sure you have the reprex package installed. If you are not familiar with the package, Google it. The first thing that should come up is the package vignette. Read the example on the first page and try to copy it.

Run the code ?reprex to get the help sheet on this function. The examples at the bottom usually help.

Exercise 2

Your turn to write some code that generates an error. Create a reprex, and share with your tutor or neighbour, to see if they can fix the error.

Harriet’s Comment

Not every question will have hints. For this question it is because this is a creative exercise that follows naturally from the previous question. In these cases I might have a comment (or a heads up) which I will put here.

Exercise 3

Follow the guidelines here to setup python and tensorflow on your computer. Then test your installation by following the beginner tutorial.

Harriet’s Comment

The other tutorials have found this to be a nightmare. Try with those guidelines but try to avoid other student’s pitfalls.

To start, make sure you have the latest versions of R and r studio.

Mac users typically have a lot of issues with installing tensorflow, especially if you have previously installed Python. If you have a Mac you should follow the Apple specific instructions here. After successfully installing it, select the correct Python environment or interpreter in RStudio. You will do this by selecting the correct interpreter in RStudio under the “Tools -> Global Options”. Also install R packages “tensorflow” and “keras” using install.packages("keras", "tensorflow"), don’t run install_tensorflow or install_keras. Hopefully this works. If this works for you we can all thank patrick for these instructions.

Additionally, the labs section of the ED discussions might also already have your question, you can find it here

Exercise 4

Part A

Download the slides.qmd file for week 1 lecture. Use knitr::purl() to extract the R code for the class.

The qmd link from the week 1 section of the iml website should let you download it

Run ?knitr::purl() and check what you need for the function to run.

As a rule of thumb, it is generally easier to move a file to your project’s working directory than to change your working directory to a specific file location. If you don’t know what an R project is, please wave me down.

I would also set the output option because otherwise that slides.R file will be sent somewhere you might not want.

Part B

Open the resulting slides.R file in your RStudio file browser. What code is in the setup.R file that is sourced at the top?

Part C

Run the rest of the code in small chunks. Does it all work for you? Do you get any errors? Do you have any suggestions on making it easier to run or understand the code?

Harriet’s Comment

I think this is a genuine question from Di. If you have any suggestions let me know (it could even be something that another one of your units did). If your suggestions is feasible for Di to do time wise she might implement it.