From 50a243313635dab9bf5d6b0caae2f6e539eadbe4 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Tue, 23 Aug 2016 15:11:42 -0400 Subject: [PATCH 1/5] updating args spec --- DESCRIPTION | 2 +- R/args_specification.R | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1576a6a..2f81a7f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,7 @@ Description: Use the R console as an interactive learning environment. Users receive immediate feedback as they are guided through self-paced lessons in data science and R programming. URL: http://swirlstats.com -Version: 2.4.2 +Version: 2.4.2.1 License: MIT + file LICENSE Authors@R: c( person("Sean", "Kross", email = "sean@seankross.com", role = c("aut", "cre")), diff --git a/R/args_specification.R b/R/args_specification.R index 95a9465..889e64b 100644 --- a/R/args_specification.R +++ b/R/args_specification.R @@ -2,11 +2,33 @@ args_specification <- function(e, ...)UseMethod("args_specification") args_specification.default <- function(e, ...) { # in normal, interactive mode, do nothing + targs <- list(...) + 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(e) + return(invisible(NULL)) } args_specification.test <- function(e, ...) { # Capture ... args targs <- list(...) + 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 + } + # 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 +53,5 @@ args_specification.test <- function(e, ...) { } else { e$test_to <- targs$to } + return(invisible(NULL)) } \ No newline at end of file From 29a4fa5ab3fb36287c342eaca7e3ec45e3369145 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Tue, 23 Aug 2016 15:24:54 -0400 Subject: [PATCH 2/5] Added swirl_user option and associated function. --- DESCRIPTION | 2 +- R/args_specification.R | 41 ++++++++++++++++++++++------------------- R/options.R | 5 +++-- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2f81a7f..20d6b26 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,7 @@ Description: Use the R console as an interactive learning environment. Users receive immediate feedback as they are guided through self-paced lessons in data science and R programming. URL: http://swirlstats.com -Version: 2.4.2.1 +Version: 2.4.2.3 License: MIT + file LICENSE Authors@R: c( person("Sean", "Kross", email = "sean@seankross.com", role = c("aut", "cre")), diff --git a/R/args_specification.R b/R/args_specification.R index 889e64b..ed891a9 100644 --- a/R/args_specification.R +++ b/R/args_specification.R @@ -3,15 +3,8 @@ args_specification <- function(e, ...)UseMethod("args_specification") args_specification.default <- function(e, ...) { # in normal, interactive mode, do nothing targs <- list(...) - 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 - } + set_swirl_user(e, targs) + # return(e) return(invisible(NULL)) } @@ -19,15 +12,7 @@ args_specification.default <- function(e, ...) { args_specification.test <- function(e, ...) { # Capture ... args targs <- list(...) - 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 - } + set_swirl_user(e, targs) # Check if appropriately named args exist if(is.null(targs$test_course) || is.null(targs$test_lesson)) { @@ -54,4 +39,22 @@ args_specification.test <- function(e, ...) { e$test_to <- targs$to } return(invisible(NULL)) -} \ No newline at end of file +} + + +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/options.R b/R/options.R index 0b5e0c8..e02ff73 100644 --- a/R/options.R +++ b/R/options.R @@ -42,12 +42,13 @@ 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_logging = getOption("swirl_logging"), + swirl_user = getOption("swirl_user") ) } else { options(...) From 34ba9d1bac514ab68533433328061109c8917259 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Tue, 6 Sep 2016 12:53:44 -0400 Subject: [PATCH 3/5] added progress --- R/menu.R | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/R/menu.R b/R/menu.R index 7c4a8e4..95c576b 100644 --- a/R/menu.R +++ b/R/menu.R @@ -382,9 +382,32 @@ 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 = e$row + pbar = e$pbar_seq + nrows = length(pbar) + x = paste0(round(pbar[rn] * 100, 1), "%") + + x = paste0(pfiles, ": ", x, " (Question ", + rn, " of ", nrows, ")") + 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) } From beae2331120f6a971121b179b4abeac8cfb1c4a7 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Tue, 6 Sep 2016 12:58:09 -0400 Subject: [PATCH 4/5] added progress for swirl() --- R/menu.R | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/R/menu.R b/R/menu.R index 95c576b..b4d2abb 100644 --- a/R/menu.R +++ b/R/menu.R @@ -393,13 +393,20 @@ inProgress <- function(e){ pfiles <- str_trim(gsub("_", " ", pfiles)) # get row - rn = e$row - pbar = e$pbar_seq + 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, " of ", nrows, ")") + rn, add) return(x) } pfiles = sapply(files, get_progress) From e3af68fa42111d7ae031316e18213aa57aaf6032 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Tue, 6 Sep 2016 13:04:19 -0400 Subject: [PATCH 5/5] changed DESCRIPTION --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 20d6b26..b2730af 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,7 @@ Description: Use the R console as an interactive learning environment. Users receive immediate feedback as they are guided through self-paced lessons in data science and R programming. URL: http://swirlstats.com -Version: 2.4.2.3 +Version: 2.4.2.4 License: MIT + file LICENSE Authors@R: c( person("Sean", "Kross", email = "sean@seankross.com", role = c("aut", "cre")),