#' This function grades a file for the grader
#' @param elapseSeconds = 10 for each file run no longer than 10 seconds
grade <- function(source_code_lines, elapsedSeconds = 10) {
success <- TRUE
tryCatch({
quiet({with_timeout(eval(parse(text = source_code_lines)), Inf, elapsedSeconds)})
},
error = function (e) {
cat("Error occurs when loading the .R file...run your code locally to check for errors\n")
print(e)
success <<- FALSE
})
table <- list()
if (!success) {
return(table)
}
for (function_name in names(test_cases)) {
result_list <- c()
for (test_case in test_cases[[function_name]]) {
tryCatch({
quiet(
result <-
with_timeout(eval(parse(text = test_case)), Inf, elapsedSeconds))
}, error = function(e) {
# print(e)
result <<- FALSE
}, finally = {
result_list <- c(result_list, result)
})
}
table[[function_name]] <- result_list
}
return(table)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.