diff --git a/.gitignore b/.gitignore index 628ab4a1..e8fa31d2 100644 --- a/.gitignore +++ b/.gitignore @@ -24,7 +24,6 @@ vignettes/*.pdf *.knit.md .Rproj.user .DS_Store -grader.Rproj scratch.R NEXT_STEPS.Rmd tmp diff --git a/.lintr b/.lintr new file mode 100644 index 00000000..4428cf9b --- /dev/null +++ b/.lintr @@ -0,0 +1,4 @@ +linters: with_defaults( + object_usage_linter = NULL, + line_length_linter = line_length_linter(100) + ) diff --git a/.travis.yml b/.travis.yml index 2a07ab28..2899a01d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,3 +49,11 @@ jobs: github-token: secure: "BuNSl2Tp1GGS2ikn0zTzqUXu9bC6KaQBOYV6G8y8msidJAj/1M1sjhLO8BmP4moQ7XsoxAG1Zd+pvuE+vWVIQ/A7oMZU/WXQiymLtUXajSM4lj6+RwK9OS4/BiXia0B1rEUUmUJbX4C+yRBKHU9prNcuyZhG7RO6DTJPwodspL2ABPf4yap1Dfptj3O0ZheziC4NqPqndSGdjZos6sgvIGjEUNfjXQmBv9irpSfpZmzMzWNQvnkF9aCnsgxNcjLwClY73EfJTq3z9FN9EGpk8gRw+M2mhIKwT3N2P6XB4BCHtlIgXCw2TwwJpmuj1qLm2JvUdWx3LfBidxcv5pd9PKQffoYkdaOsX00kImEZtxH4xMCAzsKALLa4B8JyMls7lwEZsEAyU6JYDBraWIXM7s1GOu2lTcqQBpRk6bFU46FGaFfNglPgYbynP3PwGo12W+UsXK6LvuvnbfQKsNzXE2t7WEuMDOQraBU3NoZSQUwX37bAL28Iq5Vyx6XpgwHcayY+vRkNTZXGd7HK/refdhecpAAWi5SRx8I2ExEZ+9qFpw0KijWA2yJ/ksCfSX85EcIZka8PfvSgYYZWzcnD1iuHB+sLb6074h5ePJ+YIQRjZJAeXrOiyHHvmXRfKXUvPymX99VkSiqbVEFMfIendeMw6AcYynP+6WI+pqRf6EQ=" + +r_github_packages: + - jimhester/lintr + - r-lib/covr + +after_success: + - Rscript -e 'covr::codecov()' + - Rscript -e 'lintr::lint_package()' diff --git a/R/check_code.R b/R/check_code.R index 6bf585ee..e4fe725a 100644 --- a/R/check_code.R +++ b/R/check_code.R @@ -26,10 +26,13 @@ #' #' @param correct A character string to display if the student answer matches #' the solution code. -#' This character string will be run through \code{glue::\link[glue]{glue_data}} with \code{list(correct = TRUE, message = NULL)}. +#' This character string will be run through \code{glue::\link[glue]{glue_data}} with +#' \code{list(correct = TRUE, message = NULL)}. #' @param incorrect A character string to display if the student answer matches #' the solution code. -#' This character string will be run through \code{glue::\link[glue]{glue_data}} with \code{list(correct = FALSE, message = "")} where message is the error found while comparing the user solution to the known solution. +#' This character string will be run through \code{glue::\link[glue]{glue_data}} with +#' \code{list(correct = FALSE, message = "")} +#' where message is the error found while comparing the user solution to the known solution. #' @template grader_args #' @template learnr_args #' diff --git a/R/check_result.R b/R/check_result.R index b2f014ed..22ee7806 100644 --- a/R/check_result.R +++ b/R/check_result.R @@ -8,12 +8,16 @@ #' @template correct #' @param incorrect A character string to display if the student answer matches #' a known answer. -#' This character string will be run through \code{glue::\link[glue]{glue_data}} with \code{list(correct = FALSE, message = "")}. where message is the matched result message. +#' This character string will be run through +#' \code{glue::\link[glue]{glue_data}} with +#' \code{list(correct = FALSE, message = "")}. +#' where message is the matched result message. #' @template grader_args #' @template learnr_args #' @param ... ignored #' -#' @return a \code{grader_graded} structure from \code{\link{result}} containing a formatted \code{correct} or \code{incorrect} message and whether or not a match was found. +#' @return a \code{grader_graded} structure from \code{\link{result}} containing a formatted +#' \code{correct} or \code{incorrect} message and whether or not a match was found. #' #' @export #' @examples @@ -53,7 +57,7 @@ check_result <- function( correct = final_result$correct, message = final_result$message ), - {if (final_result$correct) correct else incorrect} + {if (final_result$correct) correct else incorrect} # nolint ) return(graded( diff --git a/R/detect_mistakes.R b/R/detect_mistakes.R index 80a5e759..b2388c72 100644 --- a/R/detect_mistakes.R +++ b/R/detect_mistakes.R @@ -15,7 +15,7 @@ detect_mistakes <- function(user, # Did the user miss something? if (i > length(user)) { - return(missing_argument(this_call = user[[i-1]], + return(missing_argument(this_call = user[[i - 1]], that = solution[[i]], that_name = names(solution[i]))) } diff --git a/R/grade_learnr.R b/R/grade_learnr.R index 380370ea..fb380ac6 100644 --- a/R/grade_learnr.R +++ b/R/grade_learnr.R @@ -82,7 +82,7 @@ grade_learnr <- function(label = NULL, had_error_checking <- FALSE checked_result <- tryCatch( - { + { # nolint # Run checking code to get feedback parsed_check_code <- parse(text = check_code) if (length(parsed_check_code) > 1) { @@ -91,21 +91,17 @@ grade_learnr <- function(label = NULL, eval(parsed_check_code[[i]], envir_prep) } } - grading_code <- pryr::standardise_call(parsed_check_code[[length(parsed_check_code)]], envir_prep) + grading_code <- pryr::standardise_call(parsed_check_code[[length(parsed_check_code)]], + envir_prep) - ## TODO - barret try to no force check fn to be last part of code - - # # set args to . args for the environment - # envir_prep$.grader_args <- grader_args - # envir_prep$.learnr_args <- learnr_args - - # get all grader_args + # get all grader args grader_args <- list( user_quo = rlang::as_quosure(user_code[[length(user_code)]], envir_result) ) if (!is.null(solution_code)) { - grader_args$solution_quo <- rlang::as_quosure(solution_code[[length(solution_code)]], envir_prep) + grader_args$solution_quo <- rlang::as_quosure(solution_code[[length(solution_code)]], + envir_prep) } # copy in all learnr arguments @@ -169,7 +165,9 @@ grade_learnr <- function(label = NULL, #' Get Code #' -#' Helper methods around \code{rlang::\link[rlang]{eval_tidy}} to extract user code and solution code. +#' Helper methods around \code{rlang::\link[rlang]{eval_tidy}} +#' to extract user code and solution code. +#' #' @seealso \code{\link{check_result}}, \code{\link{test_result}}, and \code{\link{check_code}} #' @export #' @rdname get_code diff --git a/R/grading_demo.R b/R/grading_demo.R index 23f7628f..7abb1baa 100644 --- a/R/grading_demo.R +++ b/R/grading_demo.R @@ -5,13 +5,16 @@ #' #' The tutorial sets the learnr exercise. checker option to #' \code{grade_learnr()} in the document's setup chunk. -#' It then uses three different exercise checking methods: \code{\link{check_result}}, \code{\link{test_result}}, and \code{\link{check_code}}. +#' It then uses three different exercise checking methods: +#' \code{\link{check_result}}, \code{\link{test_result}}, and \code{\link{check_code}}. #' To use a checking method, follow the exercise chunk with a chunk whose label #' matches the label of the exercise chunk (ex: \code{myexercise}) but includes the suffix -#' \code{-check} (ex: \code{myexercise-check}). Call any checking method in that chunk. To ensure that -#' checking method can provide informative feedback, you may provide custom \code{correct} and \code{incorrect} messages. +#' \code{-check} (ex: \code{myexercise-check}). Call any checking method in that chunk. +#' To ensure that checking method can provide informative feedback, +#' you may provide custom \code{correct} and \code{incorrect} messages. #' -#' If you are not using RStudio IDE, you can access the demo file at \code{system.file("extdata", "grading-demo/grading-demo.Rmd", package = "grader")}. +#' If you are not using RStudio IDE, you can access the demo file at +#' \code{system.file("extdata", "grading-demo/grading-demo.Rmd", package = "grader")}. #' #' @export #' @importFrom utils browseURL @@ -20,6 +23,6 @@ grading_demo <- function() { if (rstudioapi::isAvailable()) { rstudioapi::navigateToFile(grading_demo_path) } else { - browseURL(paste0('file://', grading_demo_path)) + browseURL(paste0("file://", grading_demo_path)) } } diff --git a/R/order_calls.R b/R/order_calls.R index c390d5e2..fbb3b5a1 100644 --- a/R/order_calls.R +++ b/R/order_calls.R @@ -41,7 +41,7 @@ repipe <- function(lst, .call = FALSE) { text <- purrr::reduce(text, paste, sep = " %>% ") text <- gsub("\\(NULL\\)", "()", text) - if(.call) parse(text = text)[[1]] + if (.call) parse(text = text)[[1]] else text } diff --git a/R/praise.R b/R/praise.R index 16088d38..367cb2ae 100644 --- a/R/praise.R +++ b/R/praise.R @@ -1,58 +1,64 @@ # Praise messages -.praise <- c("Absolutely fabulous!", - "Amazing!", - "Awesome!", - "Beautiful!", - "Bravo!", - "Cool job!", - "Delightful!", - "Excellent!", - "Fantastic!", - "Great work!", - "I couldn't have done it better myself.", - "Impressive work!", - "Lovely job!", - "Magnificent!", - "Nice job!", - "Out of this world!", - "Resplendent!", - "Smashing!", - "Someone knows what they're doing :)", - "Spectacular job!", - "Splendid!", - "Success!", - "Super job!", - "Superb work!", - "Swell job!", - "Terrific!", - "That's a first-class answer!", - "That's glorious!", - "That's marvelous!", - "Very good!", - "Well done!", - "What first-rate work!", - "Wicked smaht!", - "Wonderful!", - "You aced it!", - "You rock!", - "You should be proud.", - ":)") +.praise <- c( + "Absolutely fabulous!", + "Amazing!", + "Awesome!", + "Beautiful!", + "Bravo!", + "Cool job!", + "Delightful!", + "Excellent!", + "Fantastic!", + "Great work!", + "I couldn't have done it better myself.", + "Impressive work!", + "Lovely job!", + "Magnificent!", + "Nice job!", + "Out of this world!", + "Resplendent!", + "Smashing!", + "Someone knows what they're doing :)", + "Spectacular job!", + "Splendid!", + "Success!", + "Super job!", + "Superb work!", + "Swell job!", + "Terrific!", + "That's a first-class answer!", + "That's glorious!", + "That's marvelous!", + "Very good!", + "Well done!", + "What first-rate work!", + "Wicked smaht!", + "Wonderful!", + "You aced it!", + "You rock!", + "You should be proud.", + ":)" +) # Encouragement messages -.encourage <- c("Please try again.", - "Give it another try.", - "Let's try it again.", - "Try it again; next time's the charm!", - "Don't give up now, try it one more time.", - "But no need to fret, try it again.", - "Try it again. I have a good feeling about this.", - "Try it again. You get better each time.", - "Try it again. Perseverence is the key to success.", - "That's okay: you learn more from mistakes than successes. Let's do it one more time.") +.encourage <- c( + "Please try again.", + "Give it another try.", + "Let's try it again.", + "Try it again; next time's the charm!", + "Don't give up now, try it one more time.", + "But no need to fret, try it again.", + "Try it again. I have a good feeling about this.", + "Try it again. You get better each time.", + "Try it again. Perseverence is the key to success.", + "That's okay: you learn more from mistakes than successes. Let's do it one more time." +) #' Random praise and encouragement #' -#' Generate a random praise or encouragement phrase. This can be used in conjunction with \code{glue::\link[glue]{glue}} to generate praise or encouragement within feedback to users. +#' Generate a random praise or encouragement phrase. +#' This can be used in conjunction with +#' \code{glue::\link[glue]{glue}} to generate praise or encouragement within feedback to users. #' #' @examples #' replicate(5, glue::glue("Random praise: {random_praise()}")) diff --git a/R/result.R b/R/result.R index e11be312..2ca70dd2 100644 --- a/R/result.R +++ b/R/result.R @@ -1,6 +1,8 @@ #' Result #' -#' The \code{result} method returns an object containing information about what has been graded or what could be graded against. +#' The \code{result} method returns an object containing information about what has been graded +#' or what could be graded against. +#' #' @param x object graded or being compared against #' @param message possible message value to be displayed #' @param correct a boolean that determines if the result is a correct result @@ -25,7 +27,8 @@ result <- function(x, message = NULL, correct = FALSE) { #' Graded submission value #' -#'The return value from \code{graded} should be returned by every \code{*-check} chunk when used with \code{link{grade_learnr}}. +#'The return value from \code{graded} should be returned by every +#'\code{*-check} chunk when used with \code{link{grade_learnr}}. #' #' @param message A character string of the message to be displayed. #' @param correct A boolean value of whether or not the checked code is correct. diff --git a/R/test_result.R b/R/test_result.R index e0cf729c..4a0e68a4 100644 --- a/R/test_result.R +++ b/R/test_result.R @@ -21,7 +21,8 @@ #' @template learnr_args #' @param ... ignored #' -#' @return a \code{grader_graded} structure from \code{\link{result}} containing a formatted \code{correct} or \code{incorrect} message. +#' @return a \code{grader_graded} structure from \code{\link{result}} containing +#' a formatted \code{correct} or \code{incorrect} message. #' @seealso \code{test} #' @export #' @examples @@ -46,7 +47,7 @@ test_result <- function( results <- lapply(tests$fns, function(test_fn) { tryCatch( - { + { # nolint test_fn(user_answer) graded( correct = TRUE, @@ -74,7 +75,7 @@ test_result <- function( if (!resu$correct) resu$message else NULL })) ), - {if (is_correct) correct else incorrect} + {if (is_correct) correct else incorrect} # nolint ) return(graded( @@ -87,7 +88,8 @@ test_result <- function( #' Tests to check #' #' Collect a set of test to execute against a user's result value -#' @param ... a set of functions that will accept the evaluated user solution. If the test fails, it should throw an error with the message to display. +#' @param ... a set of functions that will accept the evaluated user solution. +#' If the test fails, it should throw an error with the message to display. #' @noRd #' @rdname test #' @examples @@ -131,11 +133,12 @@ grader_tests <- function(...) { #' @export #' @rdname test #' @param message Message to report back if the test throws an error. -#' @param fn function to execute against the user solution. If the test fails, it should throw an error to display the \code{message} provided. +#' @param fn function to execute against the user solution. +#' If the test fails, it should throw an error to display the \code{message} provided. test <- function(message, fn) { function(x) { tryCatch( - { + { # nolint fn(x) }, error = function(e) { diff --git a/R/test_solutions.R b/R/test_solutions.R index 10fac966..a4c59fec 100644 --- a/R/test_solutions.R +++ b/R/test_solutions.R @@ -4,17 +4,17 @@ yoink <- function(pkg, fn) { # get all of the chunks with extract_chunks <- function(file) { - knitr__knit_code <- yoink("knitr", "knit_code") - knitr__split_file <- yoink("knitr", "split_file") + knitr_knit_code <- yoink("knitr", "knit_code") + knitr_split_file <- yoink("knitr", "split_file") knitr::pat_md() knitr::render_markdown() on.exit({ knitr::knit_patterns$restore() knitr::knit_hooks$restore() - knitr__knit_code$restore() - }, add = TRUE) - knitr__split_file(readLines(file, encoding = "UTF-8")) - knitr__knit_code$get() + knitr_knit_code$restore() + }, add = TRUE) # nolint + knitr_split_file(readLines(file, encoding = "UTF-8")) + knitr_knit_code$get() } #' Test Solutions @@ -31,7 +31,7 @@ extract_chunks <- function(file) { #' @param file The filepath to a learnr tutorial. If a file path is not provided #' and only a single .Rmd file exists in the current directory, #' \code{test_solutions} will test that .Rmd file. -#' @param show.answers TRUE or FALSE. Should solution results be printed in the +#' @param show_answers TRUE or FALSE. Should solution results be printed in the #' output? # ' @param .params A list of parameters to use when evauating code in a # ' parameterized R Markdown document. This should be identical to the list @@ -49,16 +49,18 @@ extract_chunks <- function(file) { #' #' @export test_solutions <- function(file = NULL, - show.answers = FALSE + show_answers = FALSE ) { if (is.null(file)) { files <- dir() rmds <- files[grepl("(.Rmd|.rmd)$", files)] if (length(rmds) == 0) { - stop("No .Rmd file found in the current directory. Please provide a file path.", call. = FALSE) + stop("No .Rmd file found in the current directory. Please provide a file path.", + call. = FALSE) } else if (length(rmds) > 1) { - stop("Multiple .Rmd files found in the current directory. Please provide a file path.", call. = FALSE) + stop("Multiple .Rmd files found in the current directory. Please provide a file path.", + call. = FALSE) } else { file <- rmds } @@ -72,7 +74,7 @@ test_solutions <- function(file = NULL, safe_eval(parse(text = chunks[[label]]), envir = parent.frame(1)) } - test_solution <- function(label, chunks, show.answer = FALSE) { + test_solution <- function(label, chunks, show_answer = FALSE) { exercise <- sub("-solution", "", label) if (grepl("-solution$", label) && !(exercise %in% names(chunks))) { stop(paste(label, "not associated with an exercise chunk."), call. = FALSE) @@ -96,19 +98,19 @@ test_solutions <- function(file = NULL, setup <- safe_test(setup_option, chunks = chunks) print_result(setup_option, setup, - show.answers = show.answer) + show_answers = show_answer) } } else if (setup_suffix %in% names(chunks)) { setup <- safe_test(setup_suffix, chunks = chunks) print_result(setup_suffix, setup, - show.answers = show.answer) + show_answers = show_answer) } result <- safe_test(label, chunks = chunks) print_result(label, result, - show.answers = show.answer) + show_answers = show_answer) } chunks <- extract_chunks(file) @@ -120,7 +122,7 @@ test_solutions <- function(file = NULL, setup_result <- safe_test("setup", chunks = chunks) print_result("setup", setup_result, - show.answers = show.answers) + show_answers = show_answers) } solutions <- grep("-solution$", labels, value = TRUE) @@ -128,10 +130,10 @@ test_solutions <- function(file = NULL, purrr::walk(solutions, test_solution, chunks = chunks, - show.answer = show.answers) + show_answer = show_answers) } -print_result <- function(label, result, show.answers = FALSE) { +print_result <- function(label, result, show_answers = FALSE) { cat(label, crayon::silver(": "), sep = "") if (!is.null(result$error)) { cat( @@ -143,10 +145,10 @@ print_result <- function(label, result, show.answers = FALSE) { crayon::yellow(clisymbols::symbol$tick), crayon::yellow(result$result$warnings), "\n" ) - if (show.answers) print(result$result$result) + if (show_answers) print(result$result$result) } else { cat(crayon::green(clisymbols::symbol$tick), "\n") - if (show.answers) print(result$result$result) + if (show_answers) print(result$result$result) } } diff --git a/R/unpipe.R b/R/unpipe.R index c29530f4..36ed9248 100644 --- a/R/unpipe.R +++ b/R/unpipe.R @@ -8,19 +8,19 @@ #' #' @param code a quoted piece of code unpipe <- function(code) { - + # Ceci n'est pas une pipe if (!is_pipe(code)) return(code) - + # une pipe lhs <- code[[2]] rhs <- code[[3]] - + if (length(rhs) == 1) { rhs[[2]] <- lhs return(rhs) } - + dot <- purrr::map_lgl(as.list(rhs), is_dot) if (any(dot)) { rhs[[which(dot)]] <- lhs diff --git a/R/view_tutorial.R b/R/view_tutorial.R index 3cf4dfe1..71e9f9cf 100644 --- a/R/view_tutorial.R +++ b/R/view_tutorial.R @@ -30,14 +30,6 @@ view_tutorial <- function(name, package) { args = list(name = name, package = package) ) - # Failed attempt to bypass IDE console scrolling - # error by using terminal instead of callr (does - # not avoid the bug) - # termID <- rstudioapi::terminalExecute( - # 'R -e \'learnr::run_tutorial("solutions-demo", package = "grader", shiny_args = list(launch.browser = FALSE, port = 8000, host = "127.0.0.1"))\'', - # show = TRUE) - # rstudioapi::terminalKill(termID) - # If you open the viewer before the app loads, it will # display a blank screen until you click refresh status <- r2$read_error() @@ -93,7 +85,7 @@ view_tutorial <- function(name, package) { #' #' @export add_tutorial <- function(name, package) { - rprofile <- paste0(getwd(), "/.Rprofile") + rprofile <- paste0(getwd(), "/.Rprofile") # nolint # load packages @@ -126,7 +118,7 @@ add_tutorial <- function(name, package) { remove_tutorial <- function(dir = NULL) { if (!is.null(dir)) dir <- getwd() - rprofile <- paste0(dir, "/.Rprofile") + rprofile <- paste0(dir, "/.Rprofile") # nolint if (file.exists(rprofile)) { text <- readr::read_lines(rprofile) diff --git a/grader.Rproj b/grader.Rproj new file mode 100644 index 00000000..1788e686 --- /dev/null +++ b/grader.Rproj @@ -0,0 +1,18 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace,vignette diff --git a/man/check_code.Rd b/man/check_code.Rd index 8668df35..a3842a3a 100644 --- a/man/check_code.Rd +++ b/man/check_code.Rd @@ -11,11 +11,14 @@ check_code(correct = "{random_praise()} Correct!", \arguments{ \item{correct}{A character string to display if the student answer matches the solution code. -This character string will be run through \code{glue::\link[glue]{glue_data}} with \code{list(correct = TRUE, message = NULL)}.} +This character string will be run through \code{glue::\link[glue]{glue_data}} with +\code{list(correct = TRUE, message = NULL)}.} \item{incorrect}{A character string to display if the student answer matches the solution code. -This character string will be run through \code{glue::\link[glue]{glue_data}} with \code{list(correct = FALSE, message = "")} where message is the error found while comparing the user solution to the known solution.} +This character string will be run through \code{glue::\link[glue]{glue_data}} with +\code{list(correct = FALSE, message = "")} +where message is the error found while comparing the user solution to the known solution.} \item{grader_args}{A list of parameters passed to \code{grader} functions (provided by \code{grade_learnr}). This contains: \describe{ \item{\code{user_quo}}{Quoted R code submitted by the user. Ex: \code{rlang::\link[rlang]{quo}(1)} } diff --git a/man/check_result.Rd b/man/check_result.Rd index 947a1eef..91d59c56 100644 --- a/man/check_result.Rd +++ b/man/check_result.Rd @@ -19,7 +19,10 @@ This character string will be run through \code{glue::\link[glue]{glue_data}} wi \item{incorrect}{A character string to display if the student answer matches a known answer. -This character string will be run through \code{glue::\link[glue]{glue_data}} with \code{list(correct = FALSE, message = "")}. where message is the matched result message.} +This character string will be run through +\code{glue::\link[glue]{glue_data}} with +\code{list(correct = FALSE, message = "")}. +where message is the matched result message.} \item{grader_args}{A list of parameters passed to \code{grader} functions (provided by \code{grade_learnr}). This contains: \describe{ \item{\code{user_quo}}{Quoted R code submitted by the user. Ex: \code{rlang::\link[rlang]{quo}(1)} } @@ -29,7 +32,8 @@ This character string will be run through \code{glue::\link[glue]{glue_data}} wi \item{learnr_args}{A list of all parameters passed to \code{\link{grade_learnr}} by \code{learnr}. See \url{https://rstudio.github.io/learnr/exercises.html#exercise_checking} for more details.} } \value{ -a \code{grader_graded} structure from \code{\link{result}} containing a formatted \code{correct} or \code{incorrect} message and whether or not a match was found. +a \code{grader_graded} structure from \code{\link{result}} containing a formatted + \code{correct} or \code{incorrect} message and whether or not a match was found. } \description{ \code{check_result()} compares the final result of the user code to known \code{results}. diff --git a/man/get_code.Rd b/man/get_code.Rd index ebbdf27a..c984598d 100644 --- a/man/get_code.Rd +++ b/man/get_code.Rd @@ -23,7 +23,8 @@ their own environments.} \item{name}{Name to print if a \code{NULL} expression is provided.} } \description{ -Helper methods around \code{rlang::\link[rlang]{eval_tidy}} to extract user code and solution code. +Helper methods around \code{rlang::\link[rlang]{eval_tidy}} +to extract user code and solution code. } \seealso{ \code{\link{check_result}}, \code{\link{test_result}}, and \code{\link{check_code}} diff --git a/man/graded.Rd b/man/graded.Rd index f65e8efa..75c78b53 100644 --- a/man/graded.Rd +++ b/man/graded.Rd @@ -12,5 +12,6 @@ graded(correct, message = NULL) \item{message}{A character string of the message to be displayed.} } \description{ -The return value from \code{graded} should be returned by every \code{*-check} chunk when used with \code{link{grade_learnr}}. +The return value from \code{graded} should be returned by every +\code{*-check} chunk when used with \code{link{grade_learnr}}. } diff --git a/man/grading_demo.Rd b/man/grading_demo.Rd index d52614a7..2240ddf2 100644 --- a/man/grading_demo.Rd +++ b/man/grading_demo.Rd @@ -13,11 +13,14 @@ file that demonstrates how to use the grader package to check student code. \details{ The tutorial sets the learnr exercise. checker option to \code{grade_learnr()} in the document's setup chunk. -It then uses three different exercise checking methods: \code{\link{check_result}}, \code{\link{test_result}}, and \code{\link{check_code}}. +It then uses three different exercise checking methods: +\code{\link{check_result}}, \code{\link{test_result}}, and \code{\link{check_code}}. To use a checking method, follow the exercise chunk with a chunk whose label matches the label of the exercise chunk (ex: \code{myexercise}) but includes the suffix -\code{-check} (ex: \code{myexercise-check}). Call any checking method in that chunk. To ensure that -checking method can provide informative feedback, you may provide custom \code{correct} and \code{incorrect} messages. +\code{-check} (ex: \code{myexercise-check}). Call any checking method in that chunk. +To ensure that checking method can provide informative feedback, +you may provide custom \code{correct} and \code{incorrect} messages. -If you are not using RStudio IDE, you can access the demo file at \code{system.file("extdata", "grading-demo/grading-demo.Rmd", package = "grader")}. +If you are not using RStudio IDE, you can access the demo file at +\code{system.file("extdata", "grading-demo/grading-demo.Rmd", package = "grader")}. } diff --git a/man/praise.Rd b/man/praise.Rd index 0e9398d6..b1e8309f 100644 --- a/man/praise.Rd +++ b/man/praise.Rd @@ -10,7 +10,9 @@ random_praise() random_encourage() } \description{ -Generate a random praise or encouragement phrase. This can be used in conjunction with \code{glue::\link[glue]{glue}} to generate praise or encouragement within feedback to users. +Generate a random praise or encouragement phrase. +This can be used in conjunction with +\code{glue::\link[glue]{glue}} to generate praise or encouragement within feedback to users. } \examples{ replicate(5, glue::glue("Random praise: {random_praise()}")) diff --git a/man/result.Rd b/man/result.Rd index 9b10a291..a8565ae5 100644 --- a/man/result.Rd +++ b/man/result.Rd @@ -14,7 +14,8 @@ result(x, message = NULL, correct = FALSE) \item{correct}{a boolean that determines if the result is a correct result} } \description{ -The \code{result} method returns an object containing information about what has been graded or what could be graded against. +The \code{result} method returns an object containing information about what has been graded +or what could be graded against. } \examples{ result(1, "Custom message for value 1.") diff --git a/man/test.Rd b/man/test.Rd index 873bb84f..8a673797 100644 --- a/man/test.Rd +++ b/man/test.Rd @@ -9,7 +9,8 @@ test(message, fn) \arguments{ \item{message}{Message to report back if the test throws an error.} -\item{fn}{function to execute against the user solution. If the test fails, it should throw an error to display the \code{message} provided.} +\item{fn}{function to execute against the user solution. +If the test fails, it should throw an error to display the \code{message} provided.} } \description{ TODO document with 'tests' documentation diff --git a/man/test_result.Rd b/man/test_result.Rd index 275a6331..e18221ce 100644 --- a/man/test_result.Rd +++ b/man/test_result.Rd @@ -37,7 +37,8 @@ test_result(..., \item{learnr_args}{A list of all parameters passed to \code{\link{grade_learnr}} by \code{learnr}. See \url{https://rstudio.github.io/learnr/exercises.html#exercise_checking} for more details.} } \value{ -a \code{grader_graded} structure from \code{\link{result}} containing a formatted \code{correct} or \code{incorrect} message. +a \code{grader_graded} structure from \code{\link{result}} containing + a formatted \code{correct} or \code{incorrect} message. } \description{ \code{test_result()} executes tests against the final result of the user code. diff --git a/man/test_solutions.Rd b/man/test_solutions.Rd index f1c05242..f451972e 100644 --- a/man/test_solutions.Rd +++ b/man/test_solutions.Rd @@ -4,14 +4,14 @@ \alias{test_solutions} \title{Test Solutions} \usage{ -test_solutions(file = NULL, show.answers = FALSE) +test_solutions(file = NULL, show_answers = FALSE) } \arguments{ \item{file}{The filepath to a learnr tutorial. If a file path is not provided and only a single .Rmd file exists in the current directory, \code{test_solutions} will test that .Rmd file.} -\item{show.answers}{TRUE or FALSE. Should solution results be printed in the +\item{show_answers}{TRUE or FALSE. Should solution results be printed in the output?} } \value{ diff --git a/tests/testthat/test_check_code.R b/tests/testthat/test_check_code.R index b355408d..e266a238 100644 --- a/tests/testthat/test_check_code.R +++ b/tests/testthat/test_check_code.R @@ -15,7 +15,7 @@ test_that("Spots differences in atomics", { user <- quote(1) solution <- quote(1) - #browser() + expect_correct( check_code(grader_args = list(user_quo = user, solution_quo = solution)) ) @@ -179,7 +179,7 @@ test_that("Spot differences when pipes are involved", { df } - pipe <- quote(1:10 %>% mean(na.rm = TRUE) %>% log(base = 10)) + pipe <- quote(1:10 %>% mean(na.rm = TRUE) %>% log(base = 10)) # nolint func <- quote(log(1:10 %>% mean(na.rm = TRUE), base = 10)) func1 <- quote(log(mean(1:10, na.rm = TRUE), base = 10)) pipe3 <- quote(iris %>% lm(Sepal.Length ~ Sepal.Width, data = .)) diff --git a/tests/testthat/test_check_result.R b/tests/testthat/test_check_result.R index 30a13fb3..03332146 100644 --- a/tests/testthat/test_check_result.R +++ b/tests/testthat/test_check_result.R @@ -23,14 +23,14 @@ test_that("Spots differences in atomics", { expect_correct( check_result( - learnr_args = list(last_value = 2/2), + learnr_args = list(last_value = 2 / 2), result(1, correct = TRUE) ) ) expect_message( check_result( - learnr_args = list(last_value = 3/2), + learnr_args = list(last_value = 3 / 2), result(1, correct = TRUE), incorrect = "check failed!" ), diff --git a/tests/testthat/test_detect_mistakes.R b/tests/testthat/test_detect_mistakes.R index c19fbca4..9ff18181 100644 --- a/tests/testthat/test_detect_mistakes.R +++ b/tests/testthat/test_detect_mistakes.R @@ -30,7 +30,7 @@ test_that("detect_mistakes detects surplus code", { ) # non-function - user <- quote(1(a(1))) + user <- quote(1(a(1))) # nolint solution <- quote(a(1)) expect_equal( detect_mistakes(user, solution) @@ -49,7 +49,7 @@ test_that("detect_mistakes detects surplus code", { ) # internal non-function - user <- quote(a(1(1))) + user <- quote(a(1(1))) # nolint solution <- quote(a(1)) expect_equal( detect_mistakes(user, solution) @@ -71,7 +71,7 @@ test_that("detect_mistakes detects missing code", { # non-function - user <- quote(1(1)) + user <- quote(1(1)) # nolint solution <- quote(a(b(1))) expect_equal( detect_mistakes(user, solution) @@ -113,7 +113,7 @@ test_that("detect_mistakes detects mis-matched code", { ) # non-function - user <- quote(1(1)) + user <- quote(1(1)) # nolint solution <- quote(a(1)) expect_equal( detect_mistakes(user, solution) @@ -140,7 +140,7 @@ test_that("detect_mistakes detects mis-matched code", { ) # internal non-function - user <- quote(a(1(1))) + user <- quote(a(1(1))) # nolint solution <- quote(a(b(1))) expect_equal( detect_mistakes(user, solution) @@ -419,7 +419,7 @@ test_that("detect_mistakes works with infix operators", { wrong_value(this = "pi(1)", that = "1 + pi") ) - user <- quote(1(1)) + user <- quote(1(1)) # nolint solution <- quote(b(1) + 2) expect_equal( detect_mistakes(user, solution) @@ -454,7 +454,7 @@ test_that("detect_mistakes works with pipes", { ) user <- quote(sqrt(1)) - solution <- quote(sqrt(1 %>% log() %>% abs())) + solution <- quote(sqrt(1 %>% log() %>% abs())) # nolint expect_equal( detect_mistakes(user, solution) , @@ -462,7 +462,7 @@ test_that("detect_mistakes works with pipes", { ) user <- quote(sqrt(1 %>% log())) - solution <- quote(sqrt(1 %>% log() %>% abs())) + solution <- quote(sqrt(1 %>% log() %>% abs())) # nolint expect_equal( detect_mistakes(user, solution) , @@ -486,8 +486,8 @@ test_that("detect_mistakes works with pipes", { wrong_value(this = "abs(2)", that = "log()") ) - user <- quote(a(2 %>% abs() %>% sqrt())) - solution <- quote(a(2 %>% log() %>% sqrt())) + user <- quote(a(2 %>% abs() %>% sqrt())) # nolint + solution <- quote(a(2 %>% log() %>% sqrt())) # nolint expect_equal( detect_mistakes(user, solution) , @@ -520,7 +520,7 @@ test_that("detect_mistakes works with pipes", { ) user <- quote(1) - solution <- quote(1 %>% log() %>% abs()) + solution <- quote(1 %>% log() %>% abs()) # nolint expect_equal( detect_mistakes(user, solution) , @@ -528,7 +528,7 @@ test_that("detect_mistakes works with pipes", { ) user <- quote(1 %>% log()) - solution <- quote(1 %>% log() %>% abs()) + solution <- quote(1 %>% log() %>% abs()) # nolint expect_equal( detect_mistakes(user, solution) , @@ -552,8 +552,8 @@ test_that("detect_mistakes works with pipes", { wrong_value(this = "abs(2)", that = "log()") ) - user <- quote(2 %>% abs() %>% sqrt()) - solution <- quote(2 %>% log() %>% sqrt()) + user <- quote(2 %>% abs() %>% sqrt()) # nolint + solution <- quote(2 %>% log() %>% sqrt()) # nolint expect_equal( detect_mistakes(user, solution) , diff --git a/tests/testthat/test_unpipe.R b/tests/testthat/test_unpipe.R index ed67f696..0b793e8b 100644 --- a/tests/testthat/test_unpipe.R +++ b/tests/testthat/test_unpipe.R @@ -1,7 +1,7 @@ context("Unpipe pipes") test_that("unpipe() strips off the top level of piping", { - pipe <- quote(iris %>% filter(Species == "Virginica") %>% select(Sepal.Length)) + pipe <- quote(iris %>% filter(Species == "Virginica") %>% select(Sepal.Length)) # nolint func <- quote(select(iris %>% filter(Species == "Virginica"), Sepal.Length)) expect_equal(unpipe(pipe), func)