library(learnr)
library(tidyverse)
library(tutorialExtras)
library(gradethis)

gradethis_setup()
knitr::opts_chunk$set(echo = FALSE)
grade_server("grade", exclude = c("Ex4"))
# student name
question_text("Name:",
              answer_fn(function(value){
                              if(length(value) >= 1 ) {
                                return(mark_as(TRUE))
                                }
                              return(mark_as(FALSE) )
                              }),
              correct = "submitted",
              allow_retry = FALSE )
grade_button_ui(id = "grade")

Instructions

Complete this tutorial while reading the Preface and Chapter 1 of the textbook. Each question allows 3 'free' attempts. After the third attempt a 10% deduction occurs per attempt.

You can click the "View Grade" button as many times as you would like to see your current grade and the number of attempts you are on. Before submitting make sure your grade is as expected.

Goals

Exercises

Exercise 1:

A code chunk can be used as a calculator. Try typing 2+2 into the code chunk and running the code.


2 + 2
grade_this_code()

Exercise 2:

You can store output/results into a variable. Storing output allows you to access the variable later on. When working in Posit, these variables will appear in your Environment tab.

Fill in the blanks to store the result of 20*40 into the variable x. Note that * is the notation for multiply.

x ___ 20*___
The assignment operator is `<-`
x <- 20*40
grade_this_code()

Exercise 3:

A boolean statement evaluates to TRUE or FALSE. Type any equation that evaluates to TRUE.


3 != 2
grade_this({
  # custom checking code appears here
  if (identical(.result, .solution)) {
    pass("Great work!")
  }
  fail("Try again!")
})

Exercise 4:

The mpg dataset is included in the ggplot2 package. Print the dataset to answer the following questions. You can "print" output by typing the name of the dataset or variable in a code chunk. Try typing mpg in the code chunk and clicking run.


quiz(caption = NULL,
    # Ex4Q1
  question("Ex4Q1) Which of the following are names of variables in the mpg data frame?",
           answer("audi"),
           answer("manufacturer", correct = TRUE),
           answer("dplyr"),
           answer("year", correct = TRUE),
           answer("drv", correct = TRUE),
           answer("glimpse"),
           answer("chr"),
           allow_retry = TRUE,
           random_answer_order = TRUE), 
  # Ex4Q2
  question("Ex4Q2) What's the city miles per gallon for the first observation in the mpg dataframe?",
           answer("29"),
           answer("18", correct = TRUE),
           answer("21"),
           answer("0"),
           answer("NA"),
           answer("4"), 
           allow_retry = TRUE,
           random_answer_order = TRUE) )

Reading Quiz

quiz(caption = NULL,
     question("Q1) Which of the following help ensure research is reproducible? Select all that apply.",
           answer("Copying and pasting results into a word processor"),
           answer("Using a workflow tool such as RMarkdown", correct = TRUE),
           answer("Literate programming (i.e. code that is readable)", correct = TRUE),
           answer("Well-documented data cleaning and analyses", correct = TRUE),
           allow_retry = TRUE,
           random_answer_order = TRUE),
  question("Q2) ___ is a programming language (like a car's engine); and ___ is an inintegrated development environment (like a car dashboard)",
           answer("R; RStudio", correct = TRUE),
           answer("RStudio; R"),
           allow_retry = TRUE,
           random_answer_order = TRUE),
  question("Q3) Which of the following applications do you need to install on your computer for this course?",
           answer("R only"),
           answer("Both R and RStudio"),
           answer("RStudio only"),
           answer("None. Posit Cloud uses your web browser.", correct = TRUE),
           allow_retry = TRUE,
           random_answer_order = TRUE),
  # Q4
  question("Q4) Which of the following is a good analogy for R packages?",
           answer("iOS software"),
           answer("iPhone accessories"),
           answer("apps you can download", correct = TRUE),
           answer("a new iPhone"),
           allow_retry = TRUE,
           random_answer_order = TRUE),
  # Q5
  question("Q5) Which of the following lines of code will store the value 30 in the object x? Select all that apply.",
           answer("x <- 15 + 15", correct = TRUE),
           answer("x = 30", correct = TRUE),
           answer("x <- 6*5", correct = TRUE),
           answer("x == 30"),
           allow_retry = TRUE,
           random_answer_order = TRUE), 
    # Q6
     question_wordbank("Q6) Seeing red text in your console is not always bad. Drag and drop the three different types of feedback R givew with how they should be interpreted.",
        choices = c("something is wrong! (red traffic light)","everything is working fine, but watch out/pay attention (yellow traffic light)", "everything is working fine (green traffic light)"),
        wordbank = c("Error", "Warning", "Message"),
        answer(c("Error", "Warning", "Message"), 
               correct = TRUE), 
        allow_retry = TRUE ),
  # Q7
    question_wordbank("Q7) Drag and drop the packages to match their primary purpose",
        choices = c("accompanies this book","data wrangling",  "data visualization"),
        wordbank = c("moderndive", "dplyr", "ggplot2"),
        answer(c("moderndive", "dplyr", "ggplot2"), correct = TRUE), 
        allow_retry = TRUE)
)

Submit

Once you are finished:

grade_print_ui("grade")


NUstat/ISDStutorials documentation built on April 17, 2025, 6:15 p.m.