diff --git a/R/args_specification.R b/R/args_specification.R index 95a9465..ed891a9 100644 --- a/R/args_specification.R +++ b/R/args_specification.R @@ -2,11 +2,18 @@ args_specification <- function(e, ...)UseMethod("args_specification") args_specification.default <- function(e, ...) { # in normal, interactive mode, do nothing + targs <- list(...) + set_swirl_user(e, targs) + + # return(e) + return(invisible(NULL)) } args_specification.test <- function(e, ...) { # Capture ... args targs <- list(...) + set_swirl_user(e, targs) + # Check if appropriately named args exist if(is.null(targs$test_course) || is.null(targs$test_lesson)) { stop(s()%N%"Must specify 'test_course' and 'test_lesson' to run in 'test' mode!") @@ -31,4 +38,23 @@ args_specification.test <- function(e, ...) { } else { e$test_to <- targs$to } -} \ No newline at end of file + return(invisible(NULL)) +} + + +set_swirl_user = function(e, targs) { + swirl_user = getOption("swirl_user") + if (is.null(targs$usr)) { + targs$usr = swirl_user + } + if (!is.null(targs$usr)) { + e$usr = targs$usr + udat <- file.path(progressDir(e), e$usr) + if (!file.exists(udat)) { + housekeeping(e) + dir.create(udat, recursive = TRUE) + } + e$udat <- udat + } + return(invisible(NULL)) +} \ No newline at end of file diff --git a/R/menu.R b/R/menu.R index 7c4a8e4..26597f8 100644 --- a/R/menu.R +++ b/R/menu.R @@ -45,6 +45,7 @@ mainMenu.default <- function(e){ } if(response != "" ){ # If the user has chosen to continue, restore progress + response = gsub(": \\d*%.*", "", response) response <- gsub(" ", "_", response) response <- paste0(response,".rda") restoreUserProgress(e, response) @@ -382,9 +383,39 @@ progressName <- function(courseName, lesName){ } inProgress <- function(e){ - pfiles <- dir(e$udat)[grep("[.]rda$", dir(e$udat))] - pfiles <- gsub("[.]rda", "", pfiles) - pfiles <- str_trim(gsub("_", " ", pfiles)) + files = dir(e$udat, full.names = TRUE) + keep = grep("[.]rda$", files) + files = files[keep] + + get_progress = function(file) { + r = readRDS(file) + file = basename(file) + pfiles <- gsub("[.]rda", "", file) + pfiles <- str_trim(gsub("_", " ", pfiles)) + + # get row + rn = r$row + pbar = r$pbar_seq + nrows = length(pbar) + add = paste0(" of ", nrows) + if (is.null(rn)) { + rn = 1 + pbar = 0 + nrows = "All" + add = "" + } + add = paste0(add , ")") + x = paste0(round(pbar[rn] * 100, 1), "%") + x = paste0(pfiles, ": ", x, " (Question ", + rn, add) + return(x) + } + pfiles = sapply(files, get_progress) + names(pfiles) = NULL + + # pfiles <- dir(e$udat)[grep("[.]rda$", dir(e$udat))] + # pfiles <- gsub("[.]rda", "", pfiles) + # pfiles <- str_trim(gsub("_", " ", pfiles)) return(pfiles) } diff --git a/R/options.R b/R/options.R index dff930a..58d2fb4 100644 --- a/R/options.R +++ b/R/options.R @@ -42,15 +42,16 @@ swirl_courses_dir <- function(){ #' swirl_options(swirl_logging = TRUE) #' } swirl_options <- function(...){ - if(length(list(...)) == 0){ + if (length(list(...)) == 0){ list( swirl_courses_dir = getOption("swirl_courses_dir"), swirl_data_dir = getOption("swirl_data_dir"), swirl_language = getOption("swirl_language"), swirl_logging = getOption("swirl_logging"), + swirl_user = getOption("swirl_user"), swirl_is_fun = getOption("swirl_is_fun") ) } else { options(...) } -} \ No newline at end of file +}