| Title: | Helps Grade Assignment Submissions in Common R Formats |
| Version: | 2.0.1 |
| Description: | After being given the location of your students' submissions and a test file, the function runs each file that is an R script, R Markdown file, or Quarto document, and evaluates the results from all the given tests. Results are neatly returned in a data frame that has a row for each student, and a column for each test. |
| Depends: | R (≥ 3.4) |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | testthat, methods, callr, jsonlite |
| Suggests: | knitr, rmarkdown |
| VignetteBuilder: | knitr |
| NeedsCompilation: | no |
| Packaged: | 2026-01-19 19:49:27 UTC; taylor |
| Author: | Taylor Brown |
| Maintainer: | Taylor Brown <trb5me@virginia.edu> |
| Repository: | CRAN |
| Date/Publication: | 2026-01-19 20:00:08 UTC |
gradeR: Helps Grade Assignment Submissions in Common R Formats
Description
After being given the location of your students' submissions and a test file, the function runs each file that is an R script, R Markdown file, or Quarto document, and evaluates the results from all the given tests. Results are neatly returned in a data frame that has a row for each student, and a column for each test.
Author(s)
Maintainer: Taylor Brown trb5me@virginia.edu (ORCID) (tbrown122387)
Other contributors:
Pete Benbow pebenbow@davidson.edu (ORCID) (pebenbow) [contributor]
The grading function.
Description
This function grades a bunch of R script assignments
Usage
calcGrades(
submission_dir,
your_test_file,
suppress_warnings = TRUE,
verbose = FALSE
)
Arguments
submission_dir |
where the assignments are located |
your_test_file |
the path to your testthat test file (e.g. grade_hw1.R) |
suppress_warnings |
warning handlers prevent code from being run after they catch something. Suppress this behavior by setting this argument to TRUE. |
verbose |
set to true if you want to print the name of the file as it's being ran |
Value
a data.frame of all the scores for each student
Examples
# change paths to *your* paths
submissions <- "extdata/example/assignment1_submissions/"
my_test_file <- system.file("extdata/example", "grade_hw1.R", package = "gradeR")
results <- calcGrades(submissions, my_test_file)
The grading function for Gradescope.
Description
This function grades one R script assignment submission and writes results out to a properly-formatted json file for Gradescope. Supports R scripts (.r, .R) as well as R Markdown (.Rmd) and Quarto (.qmd) documents.
Usage
calcGradesForGradescope(
submission_file,
test_file,
which_results = "gradescope",
suppress_warnings = TRUE
)
Arguments
submission_file |
the path to the assignment submission file (e.g. "hw1.r", "hw1.Rmd", or "hw1.qmd"). For Rmd/Qmd files, R code will be automatically extracted. |
test_file |
the path to the .r file with test_that tests (e.g. "hw1_tests.R") |
which_results |
Choose either "testing" or "gradescope". If equal to "gradescope", the json file is written to /autograder/results/results.json. Otherwise, results.json is written to your current working directory. |
suppress_warnings |
If FALSE, warnings are fatal; if set to TRUE, warnings will not prematurely terminate running of student submission scripts. |
Value
Invisibly returns NULL. The function's primary purpose is the side effect of writing a JSON results file.
Examples
## Not run:
# For local testing
calcGradesForGradescope("student_hw1.r", "hw1_tests.R", which_results = "testing")
# For Gradescope autograder (inside Gradescope environment)
# calcGradesForGradescope("hw1.r", "hw1_tests.R", which_results = "gradescope")
# Works with R Markdown files too
# calcGradesForGradescope("student_hw1.Rmd", "hw1_tests.R", which_results = "testing")
## End(Not run)
Extract criterion label from assertion.
Description
Internal helper function that extracts custom labels from test expectations.
Usage
extractCriterionLabel(assertion, default_label)
Arguments
assertion |
the expectation assertion object |
default_label |
fallback label if none found |
Value
A string with the criterion label
Extract point value from criterion message.
Description
Internal helper function that extracts point values from criterion labels formatted as "[2pts]" or "(2pts)".
Usage
extractPointValue(criterion_msg)
Arguments
criterion_msg |
the criterion message that may contain point specification |
Value
A list with components: pts (numeric) and cleaned_msg (string without point spec)
This function finds unreadable files.
Description
A function that finds student submissions with poorly encoded characters
Usage
findBadEncodingFiles(submission_dir)
Arguments
submission_dir |
where the assignments are located |
Examples
# change paths to *your* paths
submissions <- "extdata/assignment1_submissions/"
findBadEncodingFiles(submissions) # perhaps ask these students to resubmit
This function finds files with global file paths.
Description
A function that finds student submissions that refer to machine-specific file paths
Usage
findGlobalPaths(submission_dir)
Arguments
submission_dir |
where the assignments are located |
Examples
# change paths to *your* paths
submissions <- "extdata/assignment1_submissions/"
findGlobalPaths(submissions) # perhaps ask these students to resubmit
The function prints a formatted test script analysis.
Description
This function is used inside the getTestScriptReport function to produce a formatted report as output.
Usage
getPrettyReport(report, script_path)
Arguments
report |
a list object that is produced from the getTestScriptReport function |
script_path |
a string representing the relative path to the test script |
The function for analyzing and summarizing R test scripts.
Description
This function scans a given test script and summarizes the number of tests and test criteria in the script, as well as point values.
Usage
getTestScriptReport(script_path)
Arguments
script_path |
the name of the .r file containing tests tests (e.g. "hw1_tests.R") |
Determine test visibility from test name.
Description
Internal helper function that extracts visibility setting from test names based on Gradescope conventions.
Usage
getTestVisibility(test_name)
Arguments
test_name |
the name of the test |
Value
A string: "visible", "hidden", "after_due_date", or "after_published"
Parse test results for a single student.
Description
Internal helper function that evaluates test results and returns scores.
Usage
parseTestResults(test_results, number_questions)
Arguments
test_results |
the ListReporter results object |
number_questions |
the number of questions/tests |
Value
A numeric vector of scores (0 or 1 for each question)
Process assertions for a single test.
Description
Internal helper function that processes all assertions for a test and computes scores and messages.
Usage
processTestAssertions(assertion_results)
Arguments
assertion_results |
list of assertion results from testthat |
Value
A list with components: score, max_score, and output
Run a student script in an isolated environment.
Description
Internal helper function that runs a student's R script in a separate process with its own environment to avoid contaminating the current session.
Usage
runStudentScript(script_path, suppress_warnings = TRUE)
Arguments
script_path |
the full path to the student's R script |
suppress_warnings |
logical; if TRUE, warnings are suppressed |
Value
The environment created by the script, or NULL if execution failed