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

Fix and improve knitr chunk option handling #668

Merged
merged 24 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
367a052
Add failing test: exercise chunk options not used
gadenbuie Feb 24, 2022
1273881
Fix setting global knitr opts chunk and improve SQL support
gadenbuie Feb 25, 2022
f48de57
re-instate code coverage
gadenbuie Feb 28, 2022
79453e9
Maybe callr is the cause of covr action failures?
gadenbuie Feb 28, 2022
30f4b72
Move test-safe.R into test-run.R to align with source code location
gadenbuie Feb 28, 2022
946dece
Test code coverage on Mac
gadenbuie Feb 28, 2022
72a17b3
Update mock_exercise() to use exercise chunk for primary information
gadenbuie Mar 2, 2022
7ffc60b
Test SQL exercises
gadenbuie Mar 2, 2022
ea8e4b9
we don't need {mockery} (yet)
gadenbuie Mar 2, 2022
5158a43
small touchup to mock_exercise()
gadenbuie Mar 2, 2022
d3eb1c1
Improve handling of explicit `output.var` and add tests
gadenbuie Mar 2, 2022
f971aca
Add code sections to exercise.R
gadenbuie Mar 2, 2022
b20ca76
Move debug_exercise_checker() to separate file
gadenbuie Mar 2, 2022
f347f80
Move with_masked_env_vars() to eval helpers section
gadenbuie Mar 2, 2022
08eb909
Add manual test slash sql example tutorial
gadenbuie Mar 2, 2022
c53691f
Standardize and test is_exercise_engine()
gadenbuie Mar 3, 2022
666855d
Use inherits() to detect DBIConnection
gadenbuie Mar 3, 2022
e745c70
fix grading and teardown code for sql.Rmd demo
gadenbuie Mar 9, 2022
f72a02b
Add NEWS
gadenbuie Mar 14, 2022
aae6efa
Add SQL example tutorial
gadenbuie Mar 14, 2022
46a8e53
Add SQL tutorial to examples
gadenbuie Mar 14, 2022
6ab7058
Update examples with screeshot
gadenbuie Mar 14, 2022
67726a3
Remove snapshot test where we dont have much control
gadenbuie Mar 14, 2022
ccfeaf3
Remove another snapshot test
gadenbuie Mar 14, 2022
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
14 changes: 7 additions & 7 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ jobs:
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

# - name: Code coverage
# if: matrix.config.os == 'ubuntu-18.04' && matrix.config.r == 'release'
# shell: Rscript {0}
# run: |
# pak::pkg_install("covr")
# covr::codecov()

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ matrix.config.os }}-r${{ matrix.config.r }}-results
path: check

- name: Code coverage
if: matrix.config.os == 'macOS-latest' && matrix.config.r == 'release'
shell: Rscript {0}
run: |
pak::pkg_install("covr")
covr::codecov()

deploy:
if: github.event_name == 'push'
needs: R-CMD-check
Expand Down
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: learnr
Title: Interactive Tutorials for R
Version: 0.10.1.9019
Authors@R:c(
Authors@R: c(
person("Garrick", "Aden-Buie", , "garrick@rstudio.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-7111-0077")),
person("Barret", "Schloerke", , "barret@rstudio.com", role = "aut",
Expand Down Expand Up @@ -42,6 +42,7 @@ Imports:
knitr (>= 1.31),
lifecycle,
markdown,
methods,
parallel,
promises,
rappdirs,
Expand All @@ -55,8 +56,10 @@ Imports:
withr
Suggests:
callr,
DBI (>= 0.4-1),
httpuv,
later,
RSQLite,
rstudioapi (>= 0.11),
shinytest (>= 1.5.0),
testthat (>= 2.1.0)
Expand Down
122 changes: 122 additions & 0 deletions R/debug_exercise_checker.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

#' An Exercise Checker for Debugging
#'
#' An exercise checker for debugging that renders all of the expected arguments
#' of the `exercise.checker` option into HTML. Additionally, this function is
#' used in testing of `evaluate_exercise()`.
#'
#' @param label Exercise label
#' @param user_code Submitted user code
#' @param solution_code The code in the `*-solution` chunk
#' @param check_code The checking code that originates from the `*-check` chunk,
#' the `*-code-check` chunk, or the `*-error-check` chunk.
#' @param envir_prep,envir_result The environment before running user code
#' (`envir_prep`) and the environment just after running the user's code
#' (`envir_result`).
#' @param evaluate_result The return value from `evaluate::evaluate()`, called
#' on `user_code`
#' @param last_value The last value after evaluating `user_code`
#' @param engine The engine of the exercise chunk
#' @param ... Not used (future compatibility)
#'
#' @keywords internal
debug_exercise_checker <- function(
label,
user_code,
solution_code,
check_code,
envir_result,
evaluate_result,
envir_prep,
last_value,
engine,
...
) {
# Use I() around check_code to indicate that we want to evaluate the check code
checker_result <- if (is_AsIs(check_code)) {
local(eval(parse(text = check_code)))
}

tags <- htmltools::tags
collapse <- function(...) paste(..., collapse = "\n")

str_chr <- function(x) {
utils::capture.output(utils::str(x))
}

str_env <- function(env) {
if (is.null(env)) {
return("NO ENVIRONMENT")
}
vars <- ls(env)
names(vars) <- vars
x <- str_chr(lapply(vars, function(v) get(v, env)))
x[-1]
}

code_block <- function(value, engine = "r") {
tags$pre(
class = engine,
tags$code(collapse(value), .noWS = "inside"),
.noWS = "inside"
)
}

message <- htmltools::tagList(
tags$p(
tags$strong("Exercise label:"),
tags$code(label),
tags$br(),
tags$strong("Engine:"),
tags$code(engine)
),
tags$p(
"last_value",
code_block(last_value)
),
tags$details(
tags$summary("envir_prep"),
code_block(str_env(envir_prep))
),
tags$details(
tags$summary("envir_result"),
code_block(str_env(envir_result))
),
tags$details(
tags$summary("user_code"),
code_block(user_code, engine)
),
tags$details(
tags$summary("solution_code"),
code_block(solution_code)
),
tags$details(
tags$summary("check_code"),
code_block(check_code)
),
tags$details(
tags$summary("evaluate_result"),
code_block(str_chr(evaluate_result))
)
)

list(
message = message,
correct = logical(),
type = "custom",
location = "replace",
checker_result = checker_result,
checker_args = list(
label = label,
user_code = user_code,
solution_code = solution_code,
check_code = check_code,
envir_result = envir_result,
evaluate_result = evaluate_result,
envir_prep = envir_prep,
last_value = last_value,
engine = engine,
"..." = list(...)
)
)
}
Loading