Skip to content

Commit

Permalink
added fuimus namespace calls, updated pkgdown site, removed utility f…
Browse files Browse the repository at this point in the history
…unctions
  • Loading branch information
andrewallenbruce committed Apr 10, 2024
1 parent 4a11092 commit 1226d76
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 166 deletions.
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Imports:
vctrs (>= 0.6.5)
Suggests:
qs,
fuimus,
gt,
knitr,
rmarkdown,
Expand All @@ -33,6 +34,8 @@ Suggests:
testthat (>= 3.0.0)
VignetteBuilder:
knitr
Remotes:
github::andrewallenbruce/fuimus
Config/roxyglobals/filename: roxyglobals-generated.R
Config/roxyglobals/unique: TRUE
Encoding: UTF-8
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ export(appendix_B)
export(appendix_C)
export(apply_age_edits)
export(case_chapter_icd10)
export(display_long)
export(ex_data)
export(gt_marks)
export(gt_style)
export(icd10api)
export(icd10cm)
export(is_valid_icd)
export(mount_board)
export(remove_dot)
export(search_edits)
export(search_in)
export(search_msdrg)
export(years_floor)
9 changes: 5 additions & 4 deletions R/appendices.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ appendix_A <- function(drg = NULL,

msd <- pins::pin_read(mount_board(), "msdrg_41.1")

if (!is.null(type)) {msd <- vctrs::vec_slice(msd, msd$drg_type == type)}
if (!is.null(type)) {
msd <- vctrs::vec_slice(msd, msd$drg_type == type)
}

if (!is.null(drg)) {msd <- search_in(msd, msd$drg, drg)}

if (!is.null(mdc)) {msd <- search_in(msd, msd$mdc, mdc)}
msd <- fuimus::search_in_if(msd, msd$drg, drg)
msd <- fuimus::search_in_if(msd, msd$mdc, mdc)

return(msd)
}
Expand Down
2 changes: 1 addition & 1 deletion R/icd_10_cm.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ icd10cm <- function(icd = NULL,
) |>
tidyr::unnest(icd_sec_code)

icd10 <- search_in(icd10, icd10$icd_code, icd)
icd10 <- fuimus::search_in(icd10, icd10$icd_code, icd)

edit <- search_edits(icd = icd)

Expand Down
13 changes: 10 additions & 3 deletions R/icd_edits.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ search_edits <- function(icd = NULL,

edt <- pins::pin_read(mount_board(), "code_edits")

if (!is.null(icd)) {edt <- search_in(edt, edt$icd_code, icd)}
edt <- fuimus::search_in_if(edt, edt$icd_code, icd)

return(edt)
}
Expand All @@ -48,10 +48,17 @@ search_edits <- function(icd = NULL,
#'
#' @export
years_floor <- function(from, to) {
floor(as.integer(difftime(to, from, units = "weeks", tz = "UTC")) / 52.17857)
floor(
as.integer(
difftime(
to,
from,
units = "weeks",
tz = "UTC"
)
) / 52.17857)
}


#' Apply Age Conflict Edits
#'
#' @param rule `<chr>` ICD-10-CM Conflict Rule
Expand Down
11 changes: 5 additions & 6 deletions R/msdrg.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ search_msdrg <- function(drg = NULL,
...) {

ms <- pins::pin_read(mount_board(), "msdrg")
ms <- fuimus::search_in_if(ms, ms$drg, drg)
ms <- fuimus::search_in_if(ms, ms$mdc, mdc)

if (!is.null(type)) {ms <- vctrs::vec_slice(ms, ms$drg_type == type)}

if (!is.null(drg)) {ms <- search_in(ms, ms$drg, drg)}

if (!is.null(mdc)) {ms <- search_in(ms, ms$mdc, mdc)}

if (!is.null(type)) {
ms <- vctrs::vec_slice(ms, ms$drg_type == type)
}
return(ms)
}
88 changes: 1 addition & 87 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
#' Search in data frame
#'
#' @template args-df
#'
#' @param dfcol `<sym>` unquoted column to search, in the form of `df$col`
#'
#' @param search `<chr>` vector of strings to search for in `df$col`
#'
#' @template returns
#'
#' @keywords internal
#'
#' @autoglobal
#'
#' @export
search_in <- function(df, dfcol, search) {
vctrs::vec_slice(
df,
vctrs::vec_in(
dfcol,
collapse::funique(
search
)
)
)
}

#' Return GitHub raw url
#'
#' @noRd
gh_raw <- function(x) {
paste0("https://raw.githubusercontent.com/", x)
}

#' Mount [pins][pins::pins-package] board
#'
#' @param `<chr>` string; whether source is `"local"` or `"remote"`
Expand All @@ -51,34 +17,12 @@ mount_board <- function(source = c("local", "remote")) {
switch(
source,
local = pins::board_folder(fs::path_package("extdata/pins", package = "pathologie")),
remote = pins::board_url(gh_raw(
remote = pins::board_url(fuimus::gh_raw(
"andrewallenbruce/pathologie/master/inst/extdata/pins/"
))
)
}

#' Pivot data frame to long format for easy printing
#'
#' @template args-df
#'
#' @param cols `<syms>` vector of bare column name to pivot, default is [dplyr::everything()]
#'
#' @template returns
#'
#' @keywords internal
#'
#' @autoglobal
#'
#' @export
display_long <- function(df,
cols = dplyr::everything()) {

df |> dplyr::mutate(
dplyr::across(
dplyr::everything(), as.character)) |>
tidyr::pivot_longer({{ cols }})
}

#' gt Theme
#'
#' @param tbl `<gt_tbl>` object
Expand Down Expand Up @@ -128,36 +72,6 @@ gt_style <- function(tbl,
)
}

#' gt Marks
#'
#' @param tbl `<gt_tbl>` object
#'
#' @param cols `<syms>` vector of bare column names, e.g. `c(mdc, drg)`
#'
#' @template returns
#'
#' @keywords internal
#'
#' @autoglobal
#'
#' @export
gt_marks <- function(tbl, cols) {

tbl |>
gt::text_case_when(
x == TRUE ~ gt::html(
fontawesome::fa("check",
prefer_type = "solid",
fill = "red")),
x == FALSE ~ gt::html(
fontawesome::fa("xmark",
prefer_type = "solid",
fill = "white")),
.default = NA,
.locations = gt::cells_body(
columns = {{ cols }}))
}

#' Example data set
#'
#' @template returns
Expand Down
8 changes: 8 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
url: https://andrewallenbruce.github.io/pathologie/
template:
bootstrap: 5
theme: tango
bslib:
font_scale: 1.1
base_font: {google: "Atkinson Hyperlegible"}
heading_font: {google: "Atkinson Hyperlegible"}
code_font: "Hack, mono"
includes:
in_header: <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hack-font@3/build/web/hack-subset.css">

20 changes: 0 additions & 20 deletions man/display_long.Rd

This file was deleted.

20 changes: 0 additions & 20 deletions man/gt_marks.Rd

This file was deleted.

22 changes: 0 additions & 22 deletions man/search_in.Rd

This file was deleted.

1 change: 1 addition & 0 deletions vignettes/pathologie.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ knitr::opts_chunk$set(
library(dplyr)
library(gt)
library(pathologie)
library(fuimus)
```

```{r}
Expand Down

0 comments on commit 1226d76

Please sign in to comment.