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

implement tutorial_package_dependencies() #329

Merged
merged 12 commits into from
Feb 12, 2020
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export(run_tutorial)
export(safe)
export(safe_env)
export(tutorial)
export(tutorial_dependencies)
schloerke marked this conversation as resolved.
Show resolved Hide resolved
export(tutorial_html_dependency)
export(tutorial_options)
import(rmarkdown)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ learnr 0.10.0.9000 (unreleased)

## Minor new features and improvements

* `learnr` gained the function `learnr::tutorial_dependencies()`, used to enumerate a tutorial's R package dependencies. Front-ends can use this to ensure a tutorial's dependencies are satisfied before attempting to run that tutorial.
schloerke marked this conversation as resolved.
Show resolved Hide resolved

* Include vignette about publishing learnr tutorials on shinyapps.io

* `learnr`'s built-in tutorials now come with a description as part of the YAML header, with the intention of this being used in front-end software that catalogues available `learnr` tutorials on the system. ([#312](https://github.com/rstudio/learnr/issues/312))
Expand Down
19 changes: 19 additions & 0 deletions R/dependencies.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#' List Tutorial Dependencies
#'
#' List the \R packages required to run a particular tutorial.
#'
#' @param name The tutorial name.
#' @param package The \R package providing the tutorial.
#'
#' @export
tutorial_dependencies <- function(name, package) {

# resolve tutorial path
dir <- get_tutorial_path(name, package)

# enumerate tutorial package dependencies
deps <- renv::dependencies(dir, quiet = TRUE)
sort(unique(deps$Package))

}
16 changes: 16 additions & 0 deletions man/tutorial_dependencies.Rd

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

4 changes: 4 additions & 0 deletions tests/testthat/test-dependency.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ test_that("tutor html dependencies can be retreived", {
expect_equal(dep$name, "tutorial")
})

test_that("tutorial package dependencies can be enumerated", {
packages <- tutorial_dependencies("ex-data-summarise", "learnr")
expect_true("tidyverse" %in% packages)
})