diff --git a/.travis.yml b/.travis.yml index 4786fbd..ec67dcc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,11 @@ -language: R +language: r + +matrix: + include: + - r: release + - r: oldrel + - r: devel + cache: packages sudo: false diff --git a/DESCRIPTION b/DESCRIPTION index e849a15..be6d743 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,7 +3,7 @@ Title: A Toolbox for Writing 'swirl' Courses Description: A set of tools for writing and sharing interactive courses to be used with swirl. URL: http://swirlstats.com -Version: 0.5.0 +Version: 0.5.2 License: MIT + file LICENSE Authors@R: c( person("Sean", "Kross", , "sean@seankross.com", c("aut", "cre")), @@ -21,10 +21,11 @@ Imports: whisker, shiny, shinyAce, - base64enc + base64enc, + readr Encoding: UTF-8 Roxygen: list(wrap = FALSE) Suggests: testthat, digest -RoxygenNote: 5.0.1 +RoxygenNote: 6.0.1 diff --git a/LICENSE b/LICENSE index a2d2a40..83edc50 100644 --- a/LICENSE +++ b/LICENSE @@ -1,2 +1,2 @@ -YEAR: 2016 +YEAR: 2018 COPYRIGHT HOLDER: Team swirl \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE index 23f50be..f81aca1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,9 +8,11 @@ export(find_questions) export(get_current_lesson) export(google_form_decode) export(lesson_to_html) +export(make_pathname) export(new_lesson) export(pack_course) export(set_lesson) +export(swirl_courses_dir) export(swirlify) export(test_course) export(test_lesson) @@ -28,6 +30,7 @@ import(shiny) import(shinyAce) import(swirl) importFrom(base64enc,base64decode) +importFrom(readr,read_csv) importFrom(rmarkdown,render) importFrom(stringr,str_detect) importFrom(stringr,str_split) diff --git a/NEWS.md b/NEWS.md index 3c0c4b4..83a8d24 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,15 @@ +# swirlify 0.5.2 + +* Fixed failing tests by integrating new features in testthat 2.0. + +# swirlify 0.5.1 + +* Fixed issue where Ace editor was not working on Windows. + +* Added `make_pathname()`. + +* Added `swirl_courses_dir()`. + # swirlify 0.5.0 * Removed `lp()`. diff --git a/R/google_form_decode.R b/R/google_form_decode.R index 1f182ad..809148e 100644 --- a/R/google_form_decode.R +++ b/R/google_form_decode.R @@ -4,6 +4,7 @@ #' Google Sheets which contains student's encoded responses. #' @return A data frame containing each student's results. #' @importFrom base64enc base64decode +#' @importFrom readr read_csv #' @export #' @examples #' \dontrun{ @@ -16,16 +17,19 @@ #' #' } google_form_decode <- function(path = file.choose()){ - encoded <- suppressWarnings(read.csv(path, header = TRUE, stringsAsFactors = FALSE)) + encoded <- suppressMessages(suppressWarnings(read_csv(path))) decoded <- list() for(i in 1:nrow(encoded)){ - temp_write <- tempfile() - writeChar(encoded[i,2], temp_write) - temp_log <- tempfile() - base64decode(file = temp_write, output = temp_log) - decoded[[i]] <- read.csv(temp_log, header = TRUE, stringsAsFactors = FALSE) + decoded[[i]] <- suppressMessages( + read_csv( + rawToChar( + base64decode( + as.character(encoded[i,2]))))) } - do.call("rbind", decoded) + result <- as.data.frame(do.call("rbind", decoded)) + attributes(result)$spec <- NULL + attributes(result)$row.names <- 1:nrow(result) + result } diff --git a/R/swirlify.R b/R/swirlify.R index 23508c8..860a64c 100644 --- a/R/swirlify.R +++ b/R/swirlify.R @@ -35,7 +35,7 @@ make_skeleton <- function() { return(lessonPath) } -#' Lauch a Shiny application for writing swirl lessons +#' Launch a Shiny application for writing swirl lessons #' #' This function launches a user interface for writing #' swirl lessons. diff --git a/R/tools.R b/R/tools.R index 27f5080..76605f0 100644 --- a/R/tools.R +++ b/R/tools.R @@ -158,3 +158,35 @@ ensure_file_ends_with_newline <- function(path){ cat("\n", file = path, append = TRUE) } } + +#' Find the directory where swirl courses are stored +#' +#' @export +#' @return A string with the path to where swirl is searching for courses. +swirl_courses_dir <- function(){ + scd <- getOption("swirl_courses_dir") + if (is.null(scd)) { + file.path(find.package("swirl"), "Courses") + } + else { + scd + } +} + +#' Replace spaces in strings with underscores +#' +#' Useful for creating paths to a particular swirl course, as you might want +#' to do in files like \code{initLesson.R}. +#' @importFrom stringr str_trim +#' @param name A vector of strings. +#' @export +#' @return A string vector where spaces are replaced with underscores. +#' @examples +#' make_pathname("Developing Data Products") +#' # "Developing_Data_Products" +#' +#' make_pathname(c("R Programming", "Exploratory Data Analysis")) +#' # "R_Programming" "Exploratory_Data_Analysis" +make_pathname <- function(name){ + gsub(" ", "_", str_trim(name)) +} \ No newline at end of file diff --git a/R/wq.R b/R/wq.R index fc263b4..3931878 100644 --- a/R/wq.R +++ b/R/wq.R @@ -177,7 +177,7 @@ wq_video <- function(output = "Would you like to watch a short video about ___?" #' @param output Text that is displayed to the user. #' @param figure An R script that produces a figure that is displayed in the R #' plotting window. -#' @param figure_type Either \code{"new"} or \code{"add"}. \code{"new"} idicates +#' @param figure_type Either \code{"new"} or \code{"add"}. \code{"new"} indicates #' that a new plot should be displayed, while \code{"add"} indicates that #' features are being added to a plot that is already displayed. #' @importFrom whisker whisker.render diff --git a/cran-comments.md b/cran-comments.md index 5b89598..4e27274 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,12 +1,12 @@ ## Release summary -This is the first attempted CRAN release of swirlify 0.5.0. +This is the first attempted CRAN release of swirlify 0.5.2. ## Test environments -* local OSX Yosemite install, R 3.3.1 -* Ubuntu 12.04 (on travis-ci), R 3.3.1 -* win-builder (devel and release) +* local macOS Sierra install, R 3.4.3 +* Ubuntu 14.04 (on travis-ci), R 3.4.2, R 3.3.3, R-devel. +* win-builder (devel) ## R CMD check results diff --git a/inst/swirlify-app/server.R b/inst/swirlify-app/server.R index da0dc21..31227aa 100644 --- a/inst/swirlify-app/server.R +++ b/inst/swirlify-app/server.R @@ -19,8 +19,8 @@ shinyServer(function(input, output, session) { observeEvent(input$save, { cat(input$ace, file = getOption("swirlify_lesson_file_path")) updateAceEditor(session, "ace", - value = readChar(getOption("swirlify_lesson_file_path"), - file.info(getOption("swirlify_lesson_file_path"))$size) + value = gsub("\r", "", readChar(getOption("swirlify_lesson_file_path"), + file.info(getOption("swirlify_lesson_file_path"))$size)) ) }) @@ -54,8 +54,8 @@ shinyServer(function(input, output, session) { } updateAceEditor(session, "ace", - value = readChar(getOption("swirlify_lesson_file_path"), - file.info(getOption("swirlify_lesson_file_path"))$size)) + value = gsub("\r", "", readChar(getOption("swirlify_lesson_file_path"), + file.info(getOption("swirlify_lesson_file_path"))$size))) }) observeEvent(input$selectnone, { diff --git a/inst/swirlify-app/ui.R b/inst/swirlify-app/ui.R index b864470..f8cabd9 100644 --- a/inst/swirlify-app/ui.R +++ b/inst/swirlify-app/ui.R @@ -14,8 +14,8 @@ shinyUI(navbarPage("swirlify 0.5", actionButton("add", "Add Question") ), column(6, - aceEditor("ace", value = readChar(getOption("swirlify_lesson_file_path"), - file.info(getOption("swirlify_lesson_file_path"))$size), mode = "yaml", + aceEditor("ace", value = gsub("\r", "", readChar(getOption("swirlify_lesson_file_path"), + file.info(getOption("swirlify_lesson_file_path"))$size)), mode = "yaml", debounce = 100), actionButton("save", "Save Lesson"), actionButton("demo", "Demo Lesson"), diff --git a/inst/test/correct_responses.csv b/inst/test/correct_responses.csv new file mode 100644 index 0000000..7887bdf --- /dev/null +++ b/inst/test/correct_responses.csv @@ -0,0 +1,4 @@ +Timestamp,Submission +2016/06/06 11:21:49 AM AST,InVzZXIiLCJjb3Vyc2VfbmFtZSIsImxlc3Nvbl9uYW1lIiwicXVlc3Rpb25fbnVtYmVyIiwiY29ycmVjdCIsImF0dGVtcHQiLCJza2lwcGVkIiwiZGF0ZXRpbWUiCiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwyLFRSVUUsMSxGQUxTRSwxNDY1MjI2NDE5LjM5ODEzCiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwzLFRSVUUsMSxGQUxTRSwxNDY1MjI2NDIzLjAxMzg1CiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiA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xTRSwxNDY1MjI2ODk1LjkzMjk5Cg== +2016/06/06 11:28:18 AM AST,InVzZXIiLCJjb3Vyc2VfbmFtZSIsImxlc3Nvbl9uYW1lIiwicXVlc3Rpb25fbnVtYmVyIiwiY29ycmVjdCIsImF0dGVtcHQiLCJza2lwcGVkIiwiZGF0ZXRpbWUiCiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwyLFRSVUUsMSxGQUxTRSwxNDY1MjI2NDE5LjM5ODEzCiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwzLFRSVUUsMSxGQUxTRSwxNDY1MjI2NDIzLjAxMzg1CiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwyLFRSVUUsMSxGQUxTRSwxNDY1MjI2ODM5LjYxNzIyCiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwzLFRSVUUsMSxGQUxTRSwxNDY1MjI2ODQ2LjAzMTcxCiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwyLFRSVUUsMSxGQUxTRSwxNDY1MjI2ODY3Ljg1MzQ3CiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwzLFRSVUUsMSxGQUxTRSwxNDY1MjI2ODk1LjkzMjk5Cg== diff --git a/inst/test/diacritics_greek_cyrillic.csv b/inst/test/diacritics_greek_cyrillic.csv new file mode 100644 index 0000000..0c2efcb --- /dev/null +++ b/inst/test/diacritics_greek_cyrillic.csv @@ -0,0 +1,4 @@ +Timestamp,Submission +2016/06/06 11:21:49 AM AST,InVzZXIiLCJjb3Vyc2VfbmFtZSIsImxlc3Nvbl9uYW1lIiwicXVlc3Rpb25fbnVtYmVyIiwiY29ycmVjdCIsImF0dGVtcHQiLCJza2lwcGVkIiwiZGF0ZXRpbWUiCiJTw6vD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zq4iLCLQktCy0LXQtNC10L3QuNC1IiwyLFRSVUUsMSxGQUxTRSwxNDY1MjI2ODM5LjYxNzIyCiJTw6vDo8WEIMOHcm/DuMWhxbwiLCLOo8+EzrHPhM65z4PPhM65zrrOriIsItCS0LLQtdC00LXQvdC40LUiLDMsVFJVRSwxLEZBTFNFLDE0NjUyMjY4NDYuMDMxNzEKIlPDq8OjxYQgw4dyb8O4xaHFvCIsIs6jz4TOsc+EzrnPg8+EzrnOus6uIiwi0JLQstC10LTQtdC90LjQtSIsMixUUlVFLDEsRkFMU0UsMTQ2NTIyNjg2Ny44NTM0NwoiU8Orw6PFhCDDh3Jvw7jFocW8IiwizqPPhM6xz4TOuc+Dz4TOuc66zq4iLCLQktCy0LXQtNC10L3QuNC1IiwzLFRSVUUsMSxGQUxTRSwxNDY1MjI2ODk1LjkzMjk5Cg== diff --git a/inst/test/responses.csv b/inst/test/responses.csv deleted file mode 100644 index 4eb9702..0000000 --- a/inst/test/responses.csv +++ /dev/null @@ -1,4 +0,0 @@ -"Timestamp","Submission" -"2016/06/06 11:21:49 AM AST","InVzZXIiLCJjb3Vyc2VfbmFtZSIsImxlc3Nvbl9uYW1lIiwicXVlc3Rpb25fbnVtYmVyIiwiY29ycmVjdCIsImF0dGVtcHQiLCJza2lwcGVkIiwiZGF0ZXRpbWUiCiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwyLFRSVUUsMSxGQUxTRSwxNDY1MjI2NDE5LjM5ODEzCiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwzLFRSVUUsMSxGQUxTRSwxNDY1MjI2NDIzLjAxMzg1Cg==" -"2016/06/06 11:27:29 AM AST","InVzZXIiLCJjb3Vyc2VfbmFtZSIsImxlc3Nvbl9uYW1lIiwicXVlc3Rpb25fbnVtYmVyIiwiY29ycmVjdCIsImF0dGVtcHQiLCJza2lwcGVkIiwiZGF0ZXRpbWUiCiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwyLFRSVUUsMSxGQUxTRSwxNDY1MjI2ODM5LjYxNzIyCiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwzLFRSVUUsMSxGQUxTRSwxNDY1MjI2ODQ2LjAzMTcxCg==" -"2016/06/06 11:28:18 AM AST","InVzZXIiLCJjb3Vyc2VfbmFtZSIsImxlc3Nvbl9uYW1lIiwicXVlc3Rpb25fbnVtYmVyIiwiY29ycmVjdCIsImF0dGVtcHQiLCJza2lwcGVkIiwiZGF0ZXRpbWUiCiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwyLFRSVUUsMSxGQUxTRSwxNDY1MjI2ODY3Ljg1MzQ3CiJzZWFuIiwiR29vZ2xlIEZvcm1zIENvdXJzZSIsIkxlc3NvbiAxIiwzLFRSVUUsMSxGQUxTRSwxNDY1MjI2ODk1LjkzMjk5Cg==" \ No newline at end of file diff --git a/man/add_license.Rd b/man/add_license.Rd index 596e141..2afa02a 100644 --- a/man/add_license.Rd +++ b/man/add_license.Rd @@ -57,4 +57,3 @@ add_license("Team Bizzaro swirl", open_source_content = FALSE, open_source_code = FALSE) } } - diff --git a/man/add_to_manifest.Rd b/man/add_to_manifest.Rd index df9951e..fa4e41f 100644 --- a/man/add_to_manifest.Rd +++ b/man/add_to_manifest.Rd @@ -22,4 +22,3 @@ get_current_lesson() add_to_manifest() } } - diff --git a/man/count_questions.Rd b/man/count_questions.Rd index 32afa9e..8c83447 100644 --- a/man/count_questions.Rd +++ b/man/count_questions.Rd @@ -17,4 +17,3 @@ Returns and prints the number of questions in the current lesson. count_questions() } } - diff --git a/man/demo_lesson.Rd b/man/demo_lesson.Rd index 76fb5c4..c7e973c 100644 --- a/man/demo_lesson.Rd +++ b/man/demo_lesson.Rd @@ -26,4 +26,3 @@ demo_lesson(5) demo_lesson(8, 14) } } - diff --git a/man/find_questions.Rd b/man/find_questions.Rd index e7876bc..dfa6576 100644 --- a/man/find_questions.Rd +++ b/man/find_questions.Rd @@ -24,4 +24,3 @@ find_questions("plot") find_questions("which") } } - diff --git a/man/get_current_lesson.Rd b/man/get_current_lesson.Rd index 4151270..8407e11 100644 --- a/man/get_current_lesson.Rd +++ b/man/get_current_lesson.Rd @@ -14,4 +14,3 @@ Prints the current lesson and course that you are working on to the console get_current_lesson() } } - diff --git a/man/google_form_decode.Rd b/man/google_form_decode.Rd index c175b88..4168a06 100644 --- a/man/google_form_decode.Rd +++ b/man/google_form_decode.Rd @@ -27,4 +27,3 @@ google_form_decode("~/Desktop/My_Course.csv") } } - diff --git a/man/lesson_to_html.Rd b/man/lesson_to_html.Rd index 57be0b7..ac88b66 100644 --- a/man/lesson_to_html.Rd +++ b/man/lesson_to_html.Rd @@ -37,4 +37,3 @@ The output is formatted to be a readable, standalone tutorial. This means that information contained in the swirl lesson such as answer tests and hints are excluded from the Rmd/HTML output. } - diff --git a/man/make_pathname.Rd b/man/make_pathname.Rd new file mode 100644 index 0000000..a426817 --- /dev/null +++ b/man/make_pathname.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tools.R +\name{make_pathname} +\alias{make_pathname} +\title{Replace spaces in strings with underscores} +\usage{ +make_pathname(name) +} +\arguments{ +\item{name}{A vector of strings.} +} +\value{ +A string vector where spaces are replaced with underscores. +} +\description{ +Useful for creating paths to a particular swirl course, as you might want +to do in files like \code{initLesson.R}. +} +\examples{ +make_pathname("Developing Data Products") +# "Developing_Data_Products" + +make_pathname(c("R Programming", "Exploratory Data Analysis")) +# "R_Programming" "Exploratory_Data_Analysis" +} diff --git a/man/new_lesson.Rd b/man/new_lesson.Rd index 4d651fa..c47ddd9 100644 --- a/man/new_lesson.Rd +++ b/man/new_lesson.Rd @@ -35,4 +35,3 @@ new_lesson("How to use pnorm", "Normal Distribution Functions in R") new_lesson("How to use qnorm", "Normal Distribution Functions in R") } } - diff --git a/man/pack_course.Rd b/man/pack_course.Rd index 5724c38..8b00dd8 100644 --- a/man/pack_course.Rd +++ b/man/pack_course.Rd @@ -30,4 +30,3 @@ pack_course() pack_course(file.path("~", "Desktop")) } } - diff --git a/man/set_lesson.Rd b/man/set_lesson.Rd index 494a8ba..70b6dd7 100644 --- a/man/set_lesson.Rd +++ b/man/set_lesson.Rd @@ -29,4 +29,3 @@ set_lesson() set_lesson(file.path("~", "R_Programming", "Functions", "lesson.yaml")) } } - diff --git a/man/swirl_courses_dir.Rd b/man/swirl_courses_dir.Rd new file mode 100644 index 0000000..c1e03ca --- /dev/null +++ b/man/swirl_courses_dir.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tools.R +\name{swirl_courses_dir} +\alias{swirl_courses_dir} +\title{Find the directory where swirl courses are stored} +\usage{ +swirl_courses_dir() +} +\value{ +A string with the path to where swirl is searching for courses. +} +\description{ +Find the directory where swirl courses are stored +} diff --git a/man/swirlify.Rd b/man/swirlify.Rd index 827bd93..7a7bc24 100644 --- a/man/swirlify.Rd +++ b/man/swirlify.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/swirlify.R \name{swirlify} \alias{swirlify} -\title{Lauch a Shiny application for writing swirl lessons} +\title{Launch a Shiny application for writing swirl lessons} \usage{ swirlify(lesson_name = NULL, course_name = NULL) } @@ -33,4 +33,3 @@ swirlify("Lesson 1", "My Course") } } - diff --git a/man/test_course.Rd b/man/test_course.Rd index c8f3ea1..d0fbd13 100644 --- a/man/test_course.Rd +++ b/man/test_course.Rd @@ -20,4 +20,3 @@ set_lesson() test_course() } } - diff --git a/man/test_lesson.Rd b/man/test_lesson.Rd index 40cc56d..3522756 100644 --- a/man/test_lesson.Rd +++ b/man/test_lesson.Rd @@ -18,4 +18,3 @@ set_lesson() test_lesson() } } - diff --git a/man/testit.Rd b/man/testit.Rd index 3e9184b..20fc5c4 100644 --- a/man/testit.Rd +++ b/man/testit.Rd @@ -15,4 +15,3 @@ testit(from = NULL, to = NULL) This function is deprecated. Please use \code{demo_lesson} instead. } - diff --git a/man/unpack_course.Rd b/man/unpack_course.Rd index c96e590..6fe949e 100644 --- a/man/unpack_course.Rd +++ b/man/unpack_course.Rd @@ -34,4 +34,3 @@ unpack_course(file.path("~", "Desktop", "R_Programming.swc"), file.path("~", "Developer", "swirl")) } } - diff --git a/man/wq_command.Rd b/man/wq_command.Rd index 7ad404a..2966c08 100644 --- a/man/wq_command.Rd +++ b/man/wq_command.Rd @@ -35,4 +35,3 @@ wq_command("Assign the value 5 to the variable x.", "x <- 5", "omnitest(correctExpr='x <- 5')", "Just type: x <- 5") } } - diff --git a/man/wq_figure.Rd b/man/wq_figure.Rd index dd44348..9c4a8fb 100644 --- a/man/wq_figure.Rd +++ b/man/wq_figure.Rd @@ -13,7 +13,7 @@ wq_figure(output = "explain the figure here", figure = "sourcefile.R", \item{figure}{An R script that produces a figure that is displayed in the R plotting window.} -\item{figure_type}{Either \code{"new"} or \code{"add"}. \code{"new"} idicates +\item{figure_type}{Either \code{"new"} or \code{"add"}. \code{"new"} indicates that a new plot should be displayed, while \code{"add"} indicates that features are being added to a plot that is already displayed.} } @@ -31,4 +31,3 @@ wq_figure("Here we can see the curve of the normal distribution.", "normalplot.R", "new") } } - diff --git a/man/wq_message.Rd b/man/wq_message.Rd index 08d084b..47744f1 100644 --- a/man/wq_message.Rd +++ b/man/wq_message.Rd @@ -22,4 +22,3 @@ wq_message() wq_message("Welcome to a course on the central limit theorem.") } } - diff --git a/man/wq_multiple.Rd b/man/wq_multiple.Rd index dc81603..eb633f4 100644 --- a/man/wq_multiple.Rd +++ b/man/wq_multiple.Rd @@ -36,4 +36,3 @@ wq_multiple("Which of the following is not a planet in our solar system?", "It's the smallest celestial body you can choose.") } } - diff --git a/man/wq_numerical.Rd b/man/wq_numerical.Rd index 383f247..8df46fc 100644 --- a/man/wq_numerical.Rd +++ b/man/wq_numerical.Rd @@ -32,4 +32,3 @@ wq_numerical("The golden ratio is closest to what integer?", "2", "omnitest(correctVal=2)", "It's greater than 1 and less than 3.") } } - diff --git a/man/wq_script.Rd b/man/wq_script.Rd index 3a12be1..6ca57b0 100644 --- a/man/wq_script.Rd +++ b/man/wq_script.Rd @@ -36,4 +36,3 @@ wq_script("Write a function that adds three numbers.", "add-three.R") } } - diff --git a/man/wq_text.Rd b/man/wq_text.Rd index f5d9462..11cef79 100644 --- a/man/wq_text.Rd +++ b/man/wq_text.Rd @@ -32,4 +32,3 @@ wq_text("Where is the Johns Hopkins Bloomberg School of Public Health located?", "Baltimore", "omnitest(correctVal='Baltimore')", "North of Washington, south of Philadelphia.") } } - diff --git a/man/wq_video.Rd b/man/wq_video.Rd index cc2e711..98d804a 100644 --- a/man/wq_video.Rd +++ b/man/wq_video.Rd @@ -27,4 +27,3 @@ wq_video("Now Roger will show you the basics on YouTube.", "https://youtu.be/dQw4w9WgXcQ") } } - diff --git a/revdep/checks.rds b/revdep/checks.rds index b257bbc..4a7e099 100644 Binary files a/revdep/checks.rds and b/revdep/checks.rds differ diff --git a/tests/testthat.R b/tests/testthat.R index 017ecff..0598ee4 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,4 +1,5 @@ library(testthat) library(swirlify) +library(swirl) test_check("swirlify") diff --git a/tests/testthat/test_google_form_decode.R b/tests/testthat/test_google_form_decode.R index 3f9c916..2110808 100644 --- a/tests/testthat/test_google_form_decode.R +++ b/tests/testthat/test_google_form_decode.R @@ -13,9 +13,67 @@ correct_responses <- data.frame( stringsAsFactors = FALSE ) -csv_path <- system.file(file.path("test", "responses.csv"), package = "swirlify") -csv_responses <- google_form_decode(csv_path) +diacritics_greek_cyrillic <- data.frame( + user = rep("Sëãń Çroøšż", 6), + course_name = rep("Στατιστική", 6), + lesson_name = rep("Введение", 6), + question_number = rep(2:3, 3), + correct = rep(TRUE, 6), + attempt = rep(1, 6), + skipped = rep(FALSE, 6), + datetime = c(1465226419.39813, 1465226423.01385, 1465226839.61722, + 1465226846.03171, 1465226867.85347, 1465226895.93299), + stringsAsFactors = FALSE +) + +cr_path <- system.file(file.path("test", "correct_responses.csv"), + package = "swirlify") +dgc_path <- system.file(file.path("test", "diacritics_greek_cyrillic.csv"), + package = "swirlify") +cr <- google_form_decode(cr_path) +dgc <- google_form_decode(dgc_path) test_that("Google Forms can be Properly Decoded.", { - expect_equal(correct_responses, csv_responses) -}) \ No newline at end of file + expect_equal(cr, rbind(correct_responses, + correct_responses, + correct_responses)) +}) + +test_that("Google Forms with diacritics can be Properly Decoded.", { + skip_on_os("windows") + expect_equal(dgc, rbind(diacritics_greek_cyrillic, + diacritics_greek_cyrillic, + diacritics_greek_cyrillic)) +}) + +# # Google form encode +# library(base64enc) +# library(tibble) +# library(readr) +# +# cr_file <- tempfile() +# dgc_file <- tempfile() +# +# write.csv(correct_responses, file = cr_file, row.names = FALSE) +# write.csv(diacritics_greek_cyrillic, file = dgc_file, row.names = FALSE) +# +# encoded_cr <- base64encode(cr_file) +# encoded_dgc <- base64encode(dgc_file) +# +# write_csv( +# tribble( +# ~Timestamp, ~Submission, +# "2016/06/06 11:21:49 AM AST", encoded_cr, +# "2016/06/06 11:27:29 AM AST", encoded_cr, +# "2016/06/06 11:28:18 AM AST", encoded_cr +# ), "inst/test/correct_responses.csv" +# ) +# +# write_csv( +# tribble( +# ~Timestamp, ~Submission, +# "2016/06/06 11:21:49 AM AST", encoded_dgc, +# "2016/06/06 11:27:29 AM AST", encoded_dgc, +# "2016/06/06 11:28:18 AM AST", encoded_dgc +# ), "inst/test/diacritics_greek_cyrillic.csv" +# ) \ No newline at end of file diff --git a/tests/testthat/test_test_lesson.R b/tests/testthat/test_test_lesson.R index 5d77d67..a645e9a 100644 --- a/tests/testthat/test_test_lesson.R +++ b/tests/testthat/test_test_lesson.R @@ -2,9 +2,9 @@ context("Test test_lesson()") path <- tempdir() oldwd <- getwd() - + setwd(path) - + new_lesson("Test Lesson", "Test Course", open_lesson = FALSE) wq_command("0", "0", "0", "0") wq_figure("0", "0.R", "new") @@ -19,21 +19,15 @@ writeLines("test", file.path(scripts, "s.R")) writeLines("test", file.path(scripts, "s-correct.R")) wq_text("0", "0", "0", "0") wq_video("0", "0") - -zz <- file(file.path(path, "test.log"), open = "wt") -sink(zz) -sink(zz, type = "message") - -test_lesson() - -sink(type = "message") -sink() - -correct_output <- c("##### Begin testing: Test Lesson #####", - "##### End testing: Test Lesson #####", "") + +message_output <- capture_messages(test_lesson()) + +correct_output <- c("##### Begin testing: Test Lesson #####\n", + "##### End testing: Test Lesson #####\n\n") test_that("test_lesson() passes with well-formed lesson", { - expect_true(all(correct_output %in% readLines(file.path(path, "test.log")))) + expect_identical(message_output, correct_output) }) +setwd(oldwd) unlink(getOption("swirlify_course_dir_path"), recursive = TRUE, force = TRUE) diff --git a/tests/testthat/test_tools.R b/tests/testthat/test_tools.R new file mode 100644 index 0000000..ce1cbd4 --- /dev/null +++ b/tests/testthat/test_tools.R @@ -0,0 +1,18 @@ +context("Test tools") + +temp_dir <- tempdir() + +test_that("swirl_courses_dir() is working", { + swirl_options(swirl_courses_dir = temp_dir) + expect_equal(temp_dir, swirl_courses_dir()) + + swirl_options(swirl_courses_dir = NULL) + expect_true(!is.null(swirl_courses_dir())) +}) + +test_that("make_pathname() is working", { + expect_equal(make_pathname("Developing Data Products"), + "Developing_Data_Products") + expect_equal(make_pathname(c("R Programming", "Exploratory Data Analysis")), + c("R_Programming", "Exploratory_Data_Analysis")) +}) \ No newline at end of file