Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize the files and functions here #144

Merged
merged 19 commits into from
Jul 1, 2024
Merged
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
1 change: 0 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

- name: Check testthat
if: runner.os != 'Windows'
id: check_check
run: |
error_num=$(Rscript --vanilla '.github/workflows/check_testthat.R')
Expand Down
29 changes: 23 additions & 6 deletions .github/workflows/check_testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,38 @@ library(magrittr)
# Find .git root directory
root_dir <- rprojroot::find_root(rprojroot::has_dir(".git"))

# Read in the testthat results
out_file <- list.files(pattern = "testthat.Rout$|Rout.fail$", file.path(root_dir, "check"),
recursive = TRUE, full.names = TRUE)

check_content <- readLines(out_file)
test_result <- grep("\\[ FAIL", check_content, value = TRUE)[1]
test_result <- unlist(strsplit(test_result, "\\||\\[|\\]"))
# Extract testhat results
testthat_check_content <- readLines(out_file)
testthat_result <- grep("\\[ FAIL", testthat_check_content, value = TRUE)[1]
testthat_result <- unlist(strsplit(testthat_result, "\\||\\[|\\]"))

# Read in standard check results
check_content <- readLines(file.path(root_dir, "check", "ottrpal.Rcheck", "00check.log"))

# Extract standard check results
check_result <- grep("Status\\:", check_content, value = TRUE)
check_result <- unlist(strsplit(check_result, ","))
check_result <- stringr::str_remove(check_result, "Status:| ")

# Format the data into a dataframe
test_result_df <- data.frame(result = trimws(test_result)) %>%
testthat_result_df <- data.frame(result = trimws(testthat_result)) %>%
dplyr::filter(result != "") %>%
tidyr::separate(result, sep = " ", into = c("test_name", "num")) %>%
dplyr::mutate(num = as.numeric(num))

fail_num <- test_result_df %>%
dplyr::filter(test_name %in% c("FAIL", "WARN")) %>%
# Do the same for the check results
check_result_df <- data.frame(result = trimws(check_result)) %>%
tidyr::separate(result, sep = " ", into = c("num", "test_name")) %>%
dplyr::mutate(num = as.numeric(num)) %>%
dplyr::select("test_name", "num")

# We only want warnings or errors or fails
fail_num <- dplyr::bind_rows(check_result_df, testthat_result_df) %>%
dplyr::filter(test_name %in% c("FAIL", "WARN", "WARNINGs", "ERROR")) %>%
dplyr::summarize(total = sum(num))

fail_num <- as.character(fail_num$total)
Expand Down
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Imports:
curl,
dplyr,
fs,
glue,
httr,
jsonlite,
knitr (>= 1.33),
Expand Down
22 changes: 6 additions & 16 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ export("%>%")
export(auth_from_secret)
export(authorize)
export(bad_quiz_path)
export(bookdown_destination)
export(bookdown_file)
export(bookdown_path)
export(bookdown_rmd_files)
export(bookdown_to_book_txt)
export(bookdown_to_embed_leanpub)
export(check_all_questions)
export(check_question)
export(check_quiz)
Expand All @@ -18,44 +12,40 @@ export(check_quiz_question_attributes)
export(check_quizzes)
export(convert_coursera_quizzes)
export(convert_quiz)
export(convert_utube_link)
export(course_path)
export(course_to_book_txt)
export(download_ottr_template)
export(example_repo_cleanup)
export(example_repo_setup)
export(extract_meta)
export(extract_object_id)
export(extract_quiz)
export(get_bookdown_spec)
export(get_chapters)
export(get_gs_pptx)
export(get_image_from_slide)
export(get_image_link_from_slide)
export(get_object_id_notes)
export(get_slide_id)
export(get_slide_page)
export(get_yaml_spec)
export(good_quiz_path)
export(gs_id_from_slide)
export(gs_png_download)
export(gs_png_url)
export(include_slide)
export(leanpub_check)
export(make_embed_markdown)
export(output_destination)
export(parse_q_tag)
export(parse_quiz)
export(parse_quiz_df)
export(pptx_notes)
export(pptx_slide_note_df)
export(pptx_slide_text_df)
export(remove_yaml_header)
export(qrmd_files)
export(render_without_toc)
export(replace_html)
export(replace_single_html)
export(set_knitr_image_path)
export(set_up_leanpub)
export(simple_references)
export(unzip_pptx)
export(website_to_embed_leanpub)
export(xml_notes)
importFrom(fs,dir_copy)
importFrom(httr,GET)
importFrom(httr,accept_json)
importFrom(httr,config)
Expand Down
9 changes: 5 additions & 4 deletions R/coursera_and_leanpub.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ convert_coursera_quizzes <- function(input_quiz_dir = "quizzes",
)
}

#' Create TOC-less Bookdown for use in Coursera
#' Create TOC-less course website for use in Coursera or Leanpub
#'
#' Create a version of Leanpub that does not have a TOC and has quizzes in the Coursera yaml format. Requires Bookdown output files including "assets", "resources", and "libs".
#' Create a version of the course that does not have a TOC and has quizzes in the Coursera yaml format.
#' This is only needed to be used on Bookdown courses. Quarto has a simple command for this.
#'
#' @param output_dir A folder (existing or not) that the TOC-less Bookdown for Coursera files should be saved. By default is file.path("docs", "coursera")
#' @param output_yaml A output.yml file to be provided to bookdown. By default is "_output.yml"
Expand All @@ -220,8 +221,8 @@ render_without_toc <- function(output_dir = file.path("docs", "no_toc"),
input_quiz_dir = "quizzes",
output_quiz_dir = "coursera_quizzes",
verbose = TRUE) {
# Find root directory by finding `_bookdown.yml` file
root_dir <- bookdown_path()
# Find root directory by finding `.git` folder
root_dir <- course_path()

# Output files:
output_dir <- file.path(root_dir, output_dir)
Expand Down
32 changes: 32 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,38 @@ download_ottr_template <- function(dir = "inst/extdata", type = "rmd") {
return(output_dir)
}


#' Path to good example quiz
#'
#' @export
#' @return The file path to an example good quiz included in the package that should pass the quiz checks.
#'
good_quiz_path <- function() {
list.files(
pattern = "quiz_good.md$",
recursive = TRUE,
system.file("extdata", package = "ottrpal"),
full.names = TRUE
)
}

#' Path to bad example quiz
#'
#' @export
#' @return The file path to an example bad quiz included in the package that will fail the quiz checks.
#'
#' @examples
#'
#' quiz_path <- bad_quiz_path()
bad_quiz_path <- function() {
list.files(
pattern = "quiz_bad.md$",
recursive = TRUE,
system.file("extdata", package = "ottrpal"),
full.names = TRUE
)
}

#' Get file path to an key encryption RDS
key_encrypt_creds_path <- function() {
list.files(
Expand Down
89 changes: 0 additions & 89 deletions R/example_data.R

This file was deleted.

29 changes: 12 additions & 17 deletions R/bookdown_to_leanpub.R → R/iframe_leanpub.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Convert Bookdown to Leanpub
#' Convert Website Course to Leanpub
#'
#' @param path path to the bookdown book, must have a `_bookdown.yml` file
#' @param path path to the bookdown or quarto course repository, must have a `_bookdown.yml` or `_quarto.yml` file
#' @param chapt_img_key File path to a TSV whose contents are the chapter urls (`url`),
#' the chapter titles (`chapt_title`), the file path to the image to be used for the chapter (`img_path`).
#' Column names `url`, `chapt_title`, and `img_path` must be used.
Expand All @@ -17,13 +17,11 @@
#' @param remove_resources_start remove the word `resources/` at the front
#' of any image path.
#' @param run_quiz_checks TRUE/FALSE run quiz checks
#' @param make_book_txt Should [ottrpal::bookdown_to_book_txt()] be run
#' @param make_book_txt Should [ottrpal::course_to_book_txt()] be run
#' to create a `Book.txt` in the output directory?
#' @param quiz_dir directory that contains the quiz .md files that should be
#' checked and incorporated into the Book.txt file. If you don't have quizzes,
#' set this to NULL
#' @param clean_up TRUE/FALSE the old output directory should be deleted and
#' everything created fresh.
#' @param footer_text Optionally can add a bit of text that will be added to the
#' end of each file before the references section.
#'
Expand All @@ -32,19 +30,18 @@
#'
#' @examples \dontrun{
#'
#' ottrpal::bookdown_to_embed_leanpub(
#' ottrpal::website_to_embed_leanpub(
#' base_url = "https://jhudatascience.org/OTTR_Template/",
#' make_book_txt = TRUE,
#' quiz_dir = NULL
#' )
#' }
bookdown_to_embed_leanpub <- function(path = ".",
website_to_embed_leanpub <- function(path = ".",
chapt_img_key = NULL,
render = NULL,
html_page = file.path(base_url, "index.html"),
base_url = NULL,
clean_up = FALSE,
default_img = NULL,
render = TRUE,
output_dir = "manuscript",
make_book_txt = FALSE,
quiz_dir = "quizzes",
Expand All @@ -55,8 +52,6 @@ bookdown_to_embed_leanpub <- function(path = ".",
# Run the set up
set_up_leanpub(
path = path,
embed = TRUE,
clean_up = clean_up,
render = render,
output_dir = output_dir,
make_book_txt = make_book_txt,
Expand Down Expand Up @@ -110,10 +105,10 @@ bookdown_to_embed_leanpub <- function(path = ".",
####################### Book.txt creation ####################################
out <- NULL
if (make_book_txt) {
if (verbose) message("Running bookdown_to_book_txt")
if (verbose) message("Running course_to_book_txt")
md_files <- basename(unlist(md_output_files))

bookdown_to_book_txt(
course_to_book_txt(
md_files = md_files,
output_dir = output_dir,
quiz_dir = quiz_dir,
Expand Down Expand Up @@ -149,7 +144,7 @@ bookdown_to_embed_leanpub <- function(path = ".",

#' Create Book.txt file from files existing in quiz directory
#'
#' @param path path to the bookdown book, must have a `_bookdown.yml` file
#' @param path path to the bookdown or quarto course repository, must have a `_bookdown.yml` or `_quarto.yml` file
#' @param md_files vector of file path of the md's to be included
#' @param output_dir output directory to put files. It should likely be
#' relative to path
Expand All @@ -159,20 +154,20 @@ bookdown_to_embed_leanpub <- function(path = ".",
#' @return A list of quiz and chapter files in order in a file called Book.txt -- How Leanpub wants it.
#' @export
#'
bookdown_to_book_txt <- function(path = ".",
course_to_book_txt <- function(path = ".",
md_files = NULL,
output_dir = "manuscript",
quiz_dir = "quizzes",
verbose = TRUE) {
# If md_files are not specified, then try to get them
if (is.null(md_files)) {
# Establish path
path <- bookdown_path(path)
path <- course_path(path)

rmd_regex <- "[.][R|r]md$"

# Extract the names of the Rmd files (the chapters)
md_files <- bookdown_rmd_files(path = path)
md_files <- qrmd_files(path = path)
}

if (!is.null(quiz_dir)) {
Expand Down
Loading
Loading