Skip to content

Commit

Permalink
added force arg to install_course
Browse files Browse the repository at this point in the history
  • Loading branch information
seankross committed Mar 15, 2016
1 parent 732786a commit 09a1a94
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
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.3.1.9017
Version: 2.3.1.9020
License: MIT + file LICENSE
Authors@R: c(
person("Sean", "Kross", email = "[email protected]", role = c("aut", "cre")),
Expand Down
18 changes: 18 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# swirl 2.4.0

* Added support for multiple languages, including Spanish, French, German,
Turkish, Simplified Chinese, and Korean. The default language can be changed
using the function `select_language()`.

* Added `install_course()` in order to install swirl courses that are
distributed in the .swc format.

* The directories where swirl courses and where user data is stored can now be
explicitly specified. These options can be set using the function
`swirl_options()`.

*




# swirl 2.3.1

* Add progress bar to track download progress of a course.
Expand Down
13 changes: 7 additions & 6 deletions R/install_course.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ NULL
#' @param swc_path The path to a local \code{.swc} file. By default this
#' argument defaults to \code{file.choose()} so the user can select the file using
#' their mouse.
#' @param force Should course installation be forced? The
#' default value is \code{FALSE}.
#' @importFrom httr GET progress content
#' @export
#' @family InstallCourses
Expand All @@ -53,7 +55,7 @@ NULL
#' install_course(swc_path = file.path("~", "Downloads", "R_Programming.swc"))
#'
#' }
install_course <- function(course_name = NULL, swc_path = NULL){
install_course <- function(course_name = NULL, swc_path = NULL, force = FALSE){
if(is.null(course_name) && is.null(swc_path)){
swc_path <- file.choose()
}
Expand All @@ -62,7 +64,6 @@ install_course <- function(course_name = NULL, swc_path = NULL){
stop(s()%N%"Please specify a value for either course_name or swc_path but not both.")
} else if(!is.null(swc_path)){
unpack_course(swc_path, swirl_courses_dir())
swirl_out(s()%N%"Course installed successfully!", skip_after=TRUE)
} else { # install from swirl course network
course_name <- make_pathname(course_name)
url <- paste0("http://swirlstats.com/scn/", course_name, ".swc")
Expand All @@ -79,8 +80,7 @@ install_course <- function(course_name = NULL, swc_path = NULL){

temp_swc <- tempfile()
writeBin(content(response, "raw"), temp_swc)
unpack_course(temp_swc, swirl_courses_dir())
swirl_out(s()%N%"Course installed successfully!", skip_after=TRUE)
unpack_course(temp_swc, swirl_courses_dir(), force = force)
}
}

Expand Down Expand Up @@ -534,13 +534,13 @@ install_course_url <- function(url, multi=FALSE){
invisible()
}

unpack_course <- function(file_path, export_path){
unpack_course <- function(file_path, export_path, force = FALSE){
# Remove trailing slash
export_path <- sub(paste0(.Platform$file.sep, "$"), replacement = "", export_path)

pack <- readRDS(file_path)
course_path <- file.path(export_path, pack$name)
if(file.exists(course_path) && interactive()){
if(!force && file.exists(course_path) && interactive()){
response <- ""
while(response != "Y"){
response <- select.list(c("Y", "n"), title = paste("\n\n", course_path, "already exists.\nAre you sure you want to overwrite it? [Y/n]"))
Expand All @@ -565,5 +565,6 @@ unpack_course <- function(file_path, export_path){

writeBin(pack$files[[i]]$raw_file, file_path, endian = pack$files[[i]]$endian)
}
swirl_out(s()%N%"Course installed successfully!", skip_after=TRUE)
invisible(course_path)
}
9 changes: 6 additions & 3 deletions R/languages.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,21 @@ s_helper <- function(x){

# set working directory to swirl repo before using
# make sure the global env is clear before using

#' @importFrom stringr str_match
check_strings <- function(){
load(file.path("R", "sysdata.rda"))
langs <- ls()
##langs <- "english"

for(i in list.files("R", pattern = "\\.R$")){
source_code <- readLines(file.path("R", i))
source_code <- readLines(file.path("R", i), warn = FALSE)
strings <- grep("s\\(\\)%N%", source_code)
for(j in strings){
for(l in langs){
if(!(str_match(source_code[j], '"(.+)"')[,2] %in% eval(parse(text = paste0("names(", l, ")"))))){
message(l, " : ", str_match(source_code[j], '"(.+)"')[,2], "\n")
if(!(str_match(source_code[j], '"(.*?)"')[,2] %in% eval(parse(text = paste0("names(", l, ")"))))){
message(l, " : '", str_match(source_code[j], '"(.*?)"')[,2], "' : ", i)
##cat('"', str_match(source_code[j], '"(.*?)"')[,2], '"', ':\n "', str_match(source_code[j], '"(.*?)"')[,2], '"\n\n', sep = "")
}
}
}
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
5 changes: 4 additions & 1 deletion man/install_course.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 09a1a94

Please sign in to comment.