## loading ALL tidyverse packages at once because we'll be using many of them, normaly required
#library(tidyverse)
## filtering for Chinstrap AND Gentoo penguins from the species column of penguins
penguin_chin_gent <-filter(penguins, species == "Chinstrap" & species == "Gentoo")
head(penguin_chin_gent)
## filtering for Chinstrap OR Gentoo penguins from the species column of penguins
penguin_chin_gent <- filter(penguins, species == "Chinstrap" | species == "Gentoo")
# print the first couple rows
head(penguin_chin_gent)
And then when I get to this code chunk:
## what are the column names of our dataset again? Let's check
colnames(penguin_chin_gent)
head(penguin_chin_gent)
## OK, so body weight is found under column "body_mass_g". Let's select body_mass_g and species so that we
## can calculate the mean body weight of each species.
head(penguin_chin_gent_bw)
tail(penguin_chin_gent_bw)
## what does this function do?
count(penguin_chin_gent_bw, species)
The users encounter the error: object 'penguin_chin_gent' not found.
This might be a beginner R markdown issue but I can't seem to figure out the problem here. Other data persists between code chunks, just not this one object.
learnR by default creates a new R session for each chunk.
In one respect it means if the student makes a complete mess of chunk1 they don't break the whole thing.
But they relatively recently added the ability to chain chunks together, effectively you can rerun chunk1 (let's hope there is no massive code there) as a setup using exercise.setup
So in {r chunk name, exercise.setup="PreviousChunk"}
However, you have also brought my attention to the very reason this is not a default option... So, I've added code chunks with {r, echo=F } that include the correct required objects throughout the tutorial to make it run smoothly and to prevent any breaking by the student!
This is working 100% on my local machine, but then when I deploy on shinyapps.io I'm hit with the same issue.
The weird part is that it was working last night on shinyapps.io (even confirmed by a student!). I just reverted back to the working version and...not working anymore.
Have you had any issues with this? Here is the code now... sorry for the formatting.
First chunk: {r filter, exercise=TRUE} penguin_chin_gent <- filter(penguins, species == "Chinstrap" | species == "Gentoo")
Second chunk: {r subsetfallback, echo=F, exercise.setup="select"} penguin_chin_gent <- filter(penguins, species == "Chinstrap" | species == "Gentoo")
Third chunk (Does not work on shinyapps.io... I get the object not found error.): {r select, exercise=T} penguin_chin_gent_bw <- select(penguin_chin_gent, species, body_mass_g)