Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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.4
License: MIT + file LICENSE
Authors@R: c(
person("Sean", "Kross", email = "sean@seankross.com", role = c("aut", "cre")),
Expand Down
28 changes: 27 additions & 1 deletion R/args_specification.R
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand All @@ -31,4 +38,23 @@ args_specification.test <- function(e, ...) {
} else {
e$test_to <- targs$to
}
}
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))
}
36 changes: 33 additions & 3 deletions R/menu.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,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)
}

Expand Down
5 changes: 3 additions & 2 deletions R/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)
Expand Down