From 43080db449f3972a5876d49c8141213e3aecc989 Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 5 Oct 2016 11:04:05 +0200 Subject: [PATCH 1/3] Extra security in complete_part() up_through should never be higher than the total number of exercises in a lesson. --- R/utilities.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utilities.R b/R/utilities.R index 078b45b..3a176c5 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -159,7 +159,7 @@ loadDependencies <- function(lesson_dir) { # Execute correct answers for rows 1 through 'up_through' of lesson complete_part <- function(e) { - up_through <- e$test_from - 1 + up_through <- min(e$test_from - 1, nrow(e$les)) # Get rows though 'up_through' argument les <- e$les[seq(up_through), ] # Execute previous correct answers in global env From a87415e2ce0317c27bfa69166f703aecfb06eeae Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 5 Oct 2016 11:23:13 +0200 Subject: [PATCH 2/3] conditionally do complete_part --- R/menu.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/menu.R b/R/menu.R index 7c4a8e4..755d72d 100644 --- a/R/menu.R +++ b/R/menu.R @@ -175,7 +175,11 @@ mainMenu.default <- function(e){ # If running in 'test' mode and starting partway through # lesson, then complete first part if((is(e, "test") || is(e, "datacamp")) && e$test_from > 1) { - complete_part(e) + if (e$test_from > nrow(e$les)) { + e$test_from <- 1 + } else { + complete_part(e) + } } # Remove temp lesson name and course name vars, which were surrogates From 89b81c74c9770a1121fd1e063bead51862eafa49 Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 5 Oct 2016 11:23:30 +0200 Subject: [PATCH 3/3] Update utilities.R --- R/utilities.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utilities.R b/R/utilities.R index 3a176c5..078b45b 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -159,7 +159,7 @@ loadDependencies <- function(lesson_dir) { # Execute correct answers for rows 1 through 'up_through' of lesson complete_part <- function(e) { - up_through <- min(e$test_from - 1, nrow(e$les)) + up_through <- e$test_from - 1 # Get rows though 'up_through' argument les <- e$les[seq(up_through), ] # Execute previous correct answers in global env