Skip to content

Commit

Permalink
Merge branch 'release/0.14.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamblake committed Oct 12, 2023
2 parents ce40b76 + 0520958 commit 3a8e5ca
Show file tree
Hide file tree
Showing 90 changed files with 378 additions and 4,107 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
^\.vscode$
^.lintr$
^CHANGELOG\.md$
^cran-comments\.md$
^CRAN-SUBMISSION$
16 changes: 6 additions & 10 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: "release"}
- {os: windows-latest, r: "release"}
- {os: windows-latest, r: "3.6"}
# - {os: ubuntu-latest, r: "devel", http-user-agent: "release"}
- {os: ubuntu-latest, r: "release"}
- {os: ubuntu-latest, r: "oldrel-1"}
- { os: macOS-latest, r: "release" }
- { os: windows-latest, r: "release" }
- { os: windows-latest, r: "3.6" }
- { os: ubuntu-latest, r: "devel", http-user-agent: "release" }
- { os: ubuntu-latest, r: "release" }
- { os: ubuntu-latest, r: "oldrel-1" }

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -38,10 +38,6 @@ jobs:
# https://github.com/actions/checkout
- uses: actions/checkout@v3

- name: System dependencies
if: ${{ matrix.config.os == 'macOS-latest' }}
run: brew install gdal

# https://github.com/r-lib/actions/tree/v2/setup-pandoc
- uses: r-lib/actions/setup-pandoc@v2

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.RData
.DS_Store
README.html
CRAN-SUBMISSION
19 changes: 7 additions & 12 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: coursekata
Title: Packages and Functions for CourseKata Courses
Version: 0.13.0
Date: 2023-10-05
Title: Packages and Functions for 'CourseKata' Courses
Version: 0.14.0
Date: 2023-10-11
Authors@R: c(
person("Adam", "Blake", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0001-7881-8652")),
Expand All @@ -11,32 +11,28 @@ Authors@R: c(
comment = c(ORCID = "0000-0001-6107-7827"))
)
Description: Easily install and load all packages and functions used in
CourseKata courses. Aid teaching with helper functions and augment
'CourseKata' courses. Aid teaching with helper functions and augment
generic functions to provide cohesion between the network of packages.
Learn more about CourseKata at <https://www.coursekata.org>.
Learn more about 'CourseKata' at <https://coursekata.org>.
License: AGPL (>= 3)
URL: https://www.github.com/UCLTALL/coursekata-r
BugReports: https://www.github.com/UCLTALL/coursekata-r/issues
URL: https://github.com/coursekata/coursekata-r
BugReports: https://github.com/coursekata/coursekata-r/issues
Depends:
R (>= 3.6)
Imports:
cli (>= 3.2.0),
crayon (>= 1.5.0),
dslabs (>= 0.7.4),
ggformula (>= 0.10.1),
ggplot2 (>= 3.3.5),
glue (>= 1.6.2),
lifecycle (>= 1.0.1),
Lock5withR (>= 1.2.2),
lsr (>= 0.5.2),
magrittr (>= 2.0.2),
Metrics,
mosaic (>= 1.8.3),
pak,
palmerpenguins,
purrr (>= 0.3.4),
rlang (>= 1.0.2),
rstudioapi (>= 0.13),
supernova (>= 2.5.1),
vctrs (>= 0.4.1),
viridisLite,
Expand All @@ -48,7 +44,6 @@ Suggests:
mockr (>= 0.1),
readr (>= 2.1.2),
readxl (>= 1.4.0),
rgdal,
usethis (>= 2.1.6),
simstudy (>= 0.5.0),
testthat (>= 3.1.2),
Expand Down
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(PRE)
export(b)
export(b0)
Expand All @@ -19,7 +18,6 @@ export(fVal)
export(fit_stats)
export(fitstats)
export(gf_model)
export(gf_model_old)
export(lower)
export(middle)
export(p)
Expand All @@ -34,9 +32,7 @@ importFrom(Lock5withR,locket)
importFrom(Metrics,sse)
importFrom(dslabs,take_poll)
importFrom(glue,glue)
importFrom(lifecycle,deprecated)
importFrom(lsr,cohensD)
importFrom(magrittr,"%>%")
importFrom(mosaic,qdist)
importFrom(palmerpenguins,path_to_file)
importFrom(stats,lm)
Expand Down
14 changes: 13 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# `coursekata` change log

## coursekata 0.14.0

- Remove deprecated `gf_model_old()` function

## coursekata 0.13.1

- Fix issue where startup message was not being displayed
- Make dependent startup package messages visible by default
- Add `coursekata.quiet` option to suppress startup messages
- Document `coursekata.quickstart` and `coursekata.quiet` options in README
- Trim unused packages in preparation for CRAN submission

## coursekata 0.13.0

- Add `coursekata.quickstart` option, which can reduce load times significantly.
Expand All @@ -18,7 +30,7 @@

## coursekata 0.10.0

- Add [`Metrics` package](https://cran.r-project.org/web/packages/Metrics/index.html)
- Add [`Metrics` package](https://CRAN.R-project.org/package=Metrics)
- Remove `zargle`

## coursekata 0.9.4
Expand Down
1 change: 0 additions & 1 deletion R/coursekata-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
## usethis namespace: start
#' @import rlang
#' @importFrom glue glue
#' @importFrom lifecycle deprecated
## usethis namespace: end
NULL

Expand Down
42 changes: 14 additions & 28 deletions R/coursekata_attach.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
#' Attach the CourseKata course packages
#'
#' @param quietly Whether to suppress messages.
#'
#' @return A named logical vector indicating which packages were attached.
#'
#' @export
#' @examples
#' coursekata_attach()
coursekata_attach <- function() {
coursekata_attach <- function(quietly = FALSE) {
to_attach <- coursekata_detached()
invisible(suppressPackageStartupMessages(pkg_require(to_attach)))
invisible(pkg_require(to_attach, quietly = quietly))
}


#' Information about CourseKata packages.
#'
#' @param pkgs A character vector of packages being loaded.
#'
#' @return A coursekata_attachments object, also of class data.frame with a row for each course
#' package and a column for each of the `package` name, `version`, and whether it is currently
#' `attached`.
#' @keywords internal
#'
#' @noRd
coursekata_attach_message <- function(pkgs) {
if (length(pkgs) == 0) return(NULL)

is_dark_theme <- rstudioapi::isAvailable() &&
rstudioapi::hasFun("getThemeInfo") &&
rstudioapi::getThemeInfo()$dark
theme <- themes[[if (is_dark_theme) "dark" else "light"]]

info <- coursekata_packages()
version <- ifelse(is.na(info$version), "", info$version)
pkgs <- theme$pkg(paste(
ifelse(info$attached, theme$good(cli::symbol$tick), theme$bad("x")),
theme$text(format(info$package)),
pkgs <- paste(
ifelse(info$attached, cli::col_green(cli::symbol$tick), cli::col_red("x")),
cli::col_green(format(info$package)),
cli::ansi_align(version, max(cli::ansi_nchar(version)))
))
)

paste(
cli::rule(
Expand All @@ -40,19 +42,3 @@ coursekata_attach_message <- function(pkgs) {
sep = "\n"
)
}


themes <- list(
light = list(
text = cli::col_black,
pkg = cli::col_blue,
good = cli::col_green,
bad = cli::col_red
),
dark = list(
text = cli::col_white,
pkg = cli::col_br_blue,
good = cli::col_br_green,
bad = cli::col_br_red
)
)
2 changes: 2 additions & 0 deletions R/coursekata_install.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#' Install or update all CourseKata packages.
#'
#' @param ... Arguments passed on to [`pak::pkg_install`].
#'
#' @return The state of all the packages after any updates have been performed.
#'
#' @export
Expand Down
10 changes: 7 additions & 3 deletions R/coursekata_packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ coursekata_pkgs <- rev(c(
#'
#' @return A data frame with three variables: the name of the package `package`, the `version`, and
#' whether it is currently `attached`.
#' @export
#'
#' @export
#' @examples
#' coursekata_packages()
coursekata_packages <- function(check_remote_version = FALSE) {
Expand All @@ -37,16 +37,20 @@ coursekata_packages <- function(check_remote_version = FALSE) {


#' List all currently attached CourseKata course packages
#'
#' @return A character vector of the course packages that have been attached.
#' @keywords internal
#'
#' @noRd
coursekata_attached <- function() {
coursekata_pkgs[pkg_is_attached(coursekata_pkgs)]
}


#' List all currently NOT attached CourseKata course packages
#'
#' @return A character vector of the course packages that are not attached.
#' @keywords internal
#'
#' @noRd
coursekata_detached <- function() {
coursekata_pkgs[!pkg_is_attached(coursekata_pkgs)]
}
5 changes: 2 additions & 3 deletions R/coursekata_repos.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
#' Ensures a default CRAN is set if one is not already set, and adds the repository for
#' fivethirtyeightdata.
#'
#' @param repos Optionally set a repository character vector to augment. If one of the values is not
#' named CRAN, the RStudio CRAN server will be added.
#' @param repos Optionally set a repository character vector to augment.
#'
#' @return A set of repositories that can be used to install or update the CourseKata packages.
#' @export
#'
#' @export
#' @examples
#' coursekata_repos()
coursekata_repos <- function(repos = getOption("repos")) {
Expand Down
4 changes: 2 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' @references
#' De Cock, Dean, (2011). Ames, Iowa: Alternative to the Boston Housing Data as an end of semester
#' regression project, *Journal of Statistics Education, 19*(3).
#' <https://dx.doi.org/10.1080/10691898.2011.11889627>
#' \doi{10.1080/10691898.2011.11889627}
#'
#' @format A data frame with 2930 observations on the following 80 variables:
#' \describe{
Expand Down Expand Up @@ -117,7 +117,7 @@
#' @references
#' Kline, J. A., Fisher, M. A., Pettit, K. L., Linville, C. T., & Beck, A. M. (2019). Controlled
#' clinical trial of canine therapy versus usual care to reduce patient anxiety in the emergency
#' department. *PloS One, 14*(1), e0209232. <https://doi.org/10.1371/journal.pone.0209232>
#' department. *PloS One, 14*(1), e0209232. \doi{10.1371/journal.pone.0209232}
#'
#' @format A data frame with 84 observations on the following 53 variables:
#' \describe{
Expand Down
10 changes: 9 additions & 1 deletion R/distribution_parts.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#'
#' @rdname distribution_parts
#' @export
#'
#' @examples
#'
#' upper(1:10, .1)
Expand Down Expand Up @@ -66,6 +65,15 @@ upper <- function(x, prop = .025, greedy = TRUE) {
values[order(values$original_pos), "in_zone", drop = TRUE]
}

#' Calculate the number of values in the tail of a distribution
#'
#' @param x The distribution of values to check.
#' @param prop The proportion of values to find.
#' @param greedy Whether the function should be greedy, as per the description above.
#'
#' @return The number of values in the tail of the distribution.
#'
#' @noRd
tail_size <- function(x, prop, greedy) {
na_rm <- stats::na.omit(x)
tail_unbiased <- length(na_rm) * prop
Expand Down
28 changes: 23 additions & 5 deletions R/estimate_extraction.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,25 @@ p <- function(object, data = NULL, all = FALSE, predictor = character(), type =
}

#' Convert a potentially complex predictor to a character vector of terms.
#'
#' @param predictor The predictor(s) to return estimates for.
#'
#' @return A character vector of terms.
#' @keywords internal
#'
#' @noRd
convert_predictor <- function(predictor) {
purrr::map_if(c(predictor), is_formula, ~ deparse(f_rhs(.x))) %>%
purrr::flatten_chr()
}

#' Convert a formula and data to an [`lm`] object.
#'
#' @param object A [`lm`] object, or [`formula`].
#' @param data If `object` is a formula, the data to fit the formula to as a [`data.frame`].
#'
#' @return An [`lm`] object.
#' @keywords internal
#'
#' @noRd
convert_lm <- function(object, data) {
if ("lm" %in% class(object) == FALSE) {
data_call <- rlang::enquo(data)
Expand All @@ -131,19 +137,27 @@ convert_lm <- function(object, data) {
}

#' Assert that the arguments to the estimate extraction functions are valid.
#'
#' @param all Whether to return all the estimates (e.g. all *F*-values).
#' @param predictor The predictor(s) to return estimates for.
#' @param type The type (1, 2, 3) of sums of squares to use.
#' @keywords internal
#'
#' @return Nothing, but throws an error if the arguments are invalid.
#'
#' @noRd
check_extract_args <- function(all, predictor, type = 3) {
vctrs::vec_assert(all, logical(), 1)
vctrs::vec_assert(predictor, character())
vctrs::vec_assert(type, numeric(), 1)
}

#' Determine if the fitted model is the empty/null model.
#'
#' @param fit A fitted linear model to pass to supernova.
#' @keywords internal
#'
#' @return Nothing, but throws an error if the model is empty.
#'
#' @noRd
check_empty_model <- function(fit) {
models <- supernova::generate_models(fit)
if (length(models) == 0) {
Expand All @@ -152,11 +166,15 @@ check_empty_model <- function(fit) {
}

#' Extract a statistic from a supernova table and name the values
#'
#' @param fit A fitted linear model to pass to supernova.
#' @param type The type (1, 2, 3) of sums of squares to use.
#' @param stat The statistic from the supernova (as named in the `supernova(...)$tbl`).
#' @param predictor Optionally specify which terms to return (instead of all of them).
#' @keywords internal
#'
#' @return A named list (one for each term, where term is the name) of the values of the statistic.
#'
#' @noRd
extract_stat <- function(fit, type, stat, predictor = character(0)) {
sup_out <- supernova(fit, type)
vals <- sup_out$tbl[[stat]]
Expand Down
Loading

0 comments on commit 3a8e5ca

Please sign in to comment.