rmdgrader 使用說明

Installation

devtools::install_github("tpemartin/rmdgrader", force=T)

Usage

library(rmdgrader)

rmdgrader is a package that works with Google classroom and Google drive. It consists of:

  1. Exam Rmd template: The template to follow for rmdgrader to work.

  2. Download: Download student’s Rmd file submission from a Google Drive folder

  3. Process: Extract Rmd code lines and restructure them according to questions

  4. Evaluate: Generate answer value objects for grading purpose.

  5. Grading: The stage of comparing students’ answer value with correct answer value, and assigning grade by grouped comparing results.

  6. Sythesize: Adding student’s grading result to his Rmd file for returning.

Exam design

File > New File > R Markdown…

Click From Template, select Exam Rmd, click OK.

Design your exam with answers and save the file as XXXX - ans.Rmd. Then from Addins > extract exercise Rmd from ans Rmd, it will generate an XXXX.Rmd that has the same Rmd content as ans.Rmd but with all the content inside ansXXX code chunk cleaned. XXXX.Rmd will be the file instructor distribute to students during the exam.

Download

library(rmdgrader)
library(dplyr)
# the google drive url with students' submissions
gd_url <- "https://drive.google.com/drive/u/0/folders/1lO5s1qeGacUVE4y0hCDaHAr0-n0n6lljKEpDTsKsI9S90jNXRBvRZOV4jHgVtqhGBzy4u3Kn"
# the title of the Google classroom assignment
title= "midterm"
# local path to save the downloads
path= "MIDTERM/submissions"

# import class roster: Must contain "學號" column and a column represents student's Google classroom login email.
roster <- readRDS("/Users/martinl/Github/110-1-r4ds-management/rosterComplete.rds")
# specify the column that can identify students google classroom login email
colname_googleClassLogin="Google classroom login email (Primary one only)"

roster[[colname_googleClassLogin]] |>
  tolower() -> roster[[colname_googleClassLogin]]

download <- rmdgrader::Download(title, path)
download$get_courseWork(gd_url, roster, colname_googleClassLogin)
# download all
download$courseWork$download(overwrite = T)
# download one
download$courseWork$download(validSchoolIds=410872134, overwrite = T)
download$courseWork$download(validSchoolIds=411073129, overwrite = T)
#
download$courseWork$download(validSchoolIds=411073126, overwrite = T)

Process

library(rmdgrader)
library(purrr)
library(dplyr)
process <- rmdgrader::Process2(
  ansRmd="/Users/martinl/Github/110-1-r4ds-management/midterm-ans.Rmd",
  path_studentRmds = "MIDTERM/submissions"
)
process$correctAnsFilename$tryGet_list_codeChunks()
process$inBatch_studentsRmds$tryGet_list_codeChunks()

# saved the process stage result
process$export(path="MIDTERM")

Evaluate

library(rmdgrader)
processed <- readRDS("MIDTERM/processed.Rds")
ev <- rmdgrader::Evaluate(processed)
# For each part of the ans.Rmd, you can resolve for answer objects for grading later
ev$answerValues$batch$resolve$part1()
# save the evaluation stage result
ev$save("MIDTERM/evaluated.Rdata")

Grading

load("MIDTERM/evaluated.Rdata")
library(rmdgrader)
library(purrr)
library(dplyr)
process = readRDS("MIDTERM/processed.Rds")
ae <- allequalService2(process, path="MIDTERM/submissions")
# For ans11, check Group 1 comparison result
ae$ans11$check_messageGroups$G1()
# if given 5 points
ae$ans11$check_messageGroups$G1grade$grade(5)
ae$ans11$check_messageGroups$G1grade$comment("your comment")

If want ot bring out some student’s code in a group:

ae$ans11$code$`midterm-410872134.Rmd`()

After settling down with ans11 grading, save the grade by:

ae$save_grade$ans11()
ae$grades$ans11

The above process needs to be done for all ans.

Synthesize

This is a stage to add student grade to student’s Rmd file for returning purpose.

library(rmdgrader)
df_grades = readRDS("/Users/martinl/Github/110-1-r4ds-management/MIDTERM/grades.Rds")
# define the mapping between each ansXXX and its Rmd header.
list(ans11="## 1.1", ans12="## 1.2", ans13="## 1.3", ans14="## 1.4", ans15="## 1.5") -> mapping

path="MIDTERM/submissions"
syn <- rmdgrader::Synthesize(df_grades, mapping, path)
# synthesize all Rmds
syn$all()
# synthesize one Rmd
syn$individual$`midterm-410872134.Rmd`()