Skip to content

Commit

Permalink
styled pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Jan 23, 2024
1 parent b172b88 commit 15faf61
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 39 deletions.
1 change: 0 additions & 1 deletion R/admiral_pkg_versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ admiral_pkg_versions <- function() {
unlist() |>
glue::glue_collapse(sep = ", ", last = ", and ")
}

8 changes: 6 additions & 2 deletions R/get_fns_with_keyword.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ get_fns_with_keyword <- function(package, keyword, lib.loc = NULL) {
df_all_fns <-
dplyr::tibble(
rd_file_name = names(db),
rd_file_contents = lapply(.data$rd_file_name, function(x) db[[x]] |> as.character() |> paste(collapse = "")),
rd_file_contents = lapply(.data$rd_file_name, function(x) {
db[[x]] |>
as.character() |>
paste(collapse = "")
}),
alias = lapply(.data$rd_file_contents, extract_alias), # these are the function names
has_keyword =
lapply(.data$rd_file_contents, function(x) stringr::str_detect(x, pattern = glue::glue("\\\\keyword\\{[[keyword]]\\}", .open = "[[", .close = "]]"))) |>
unlist()
unlist()
)

# return vector of all functions with matching keyword in help file
Expand Down
47 changes: 24 additions & 23 deletions R/interactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ interactive_discovery <- function(type = c("gt", "reactable")) {
type <- match.arg(type)

# create interactive table ---------------------------------------------------
switch(
type,
switch(type,
"gt" = .gt_discovery(),
"reactable" = .reactable_discovery()
)
Expand All @@ -37,25 +36,26 @@ interactive_discovery <- function(type = c("gt", "reactable")) {
temp |>
reactable::reactable(
rowStyle = function(index) {
if (is.na(temp[index, "superseded"]) && is.na(temp[index, "deprecated"])) list(background = '#ffffff')
else if (temp[index, "superseded"] == TRUE) list(background = '#ffffba')
else if (temp[index, "deprecated"] == TRUE) list(background = '#ffb3ba')
if (is.na(temp[index, "superseded"]) && is.na(temp[index, "deprecated"])) {
list(background = "#ffffff")
} else if (temp[index, "superseded"] == TRUE) {
list(background = "#ffffba")
} else if (temp[index, "deprecated"] == TRUE) list(background = "#ffb3ba")
},

columns = list(
dataset = reactable::colDef(
name = attr(admiraldiscovery::discovery$dataset, 'label'),
name = attr(admiraldiscovery::discovery$dataset, "label"),
maxWidth = 100
),
variable = reactable::colDef(
name = attr(admiraldiscovery::discovery$variable, 'label'),
name = attr(admiraldiscovery::discovery$variable, "label"),
maxWidth = 100
),
variable_label = reactable::colDef(
name = attr(admiraldiscovery::discovery$variable_label, 'label')
name = attr(admiraldiscovery::discovery$variable_label, "label")
),
fn_url = reactable::colDef(
name = attr(admiraldiscovery::discovery$fn, 'label'),
fn_url = reactable::colDef(
name = attr(admiraldiscovery::discovery$fn, "label"),
cell = function(value, index) {
htmltools::tags$a(
href = value,
Expand All @@ -65,7 +65,7 @@ interactive_discovery <- function(type = c("gt", "reactable")) {
},
width = 150
),
resource1_url = reactable::colDef(
resource1_url = reactable::colDef(
name = "Resource",
cell = function(value, index) {
htmltools::tags$a(
Expand All @@ -79,7 +79,6 @@ interactive_discovery <- function(type = c("gt", "reactable")) {
deprecated = reactable::colDef(show = FALSE),
superseded = reactable::colDef(show = FALSE)
),

searchable = TRUE,
filterable = TRUE,
defaultPageSize = 20,
Expand All @@ -98,32 +97,34 @@ interactive_discovery <- function(type = c("gt", "reactable")) {
get_admiral_superseded() |> dplyr::mutate(superseded = TRUE),
by = c("package", "fn")
) |>
dplyr::mutate(
function_link = glue::glue("[`{package}::{fn}()`]({fn_url})"),
.after = "fn_url"
) |>
dplyr::mutate(
function_link = glue::glue("[`{package}::{fn}()`]({fn_url})"),
.after = "fn_url"
) |>
dplyr::mutate(
resource1_link = glue::glue("[{resource1_text}]({resource1_url})")
) |>
gt::gt() |>
gt::cols_hide(columns = c("fn", "fn_url", "package", "dataset_type",
"resource1_text", "resource1_url",
"deprecated", "superseded")) |>
gt::cols_hide(columns = c(
"fn", "fn_url", "package", "dataset_type",
"resource1_text", "resource1_url",
"deprecated", "superseded"
)) |>
gt::cols_label(
function_link = "Function",
resource1_link = "Resources"
) |>
# color deprecated/superseded functions
gt::tab_style(
style = gt::cell_fill(color = '#ffb3ba'),
style = gt::cell_fill(color = "#ffb3ba"),
locations = gt::cells_body(columns = gt::everything(), rows = .data$deprecated)
) |>
gt::tab_style(
style = gt::cell_fill(color = '#ffffba'),
style = gt::cell_fill(color = "#ffffba"),
locations = gt::cells_body(columns = gt::everything(), rows = .data$superseded)
) |>
gt::fmt_markdown(columns = c("function_link", "resource1_link")) |>
gt::sub_missing(missing_text = "") |>
gt::sub_missing(missing_text = "") |>
gt::cols_width(c(dataset, dataset_type, variable) ~ gt::pct(8)) |>
gt::cols_align(align = "left") |>
gt::opt_interactive(
Expand Down
18 changes: 9 additions & 9 deletions data-raw/DATASET.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
discovery <- readr::read_csv(file = "./inst/admiral-lookup-book.csv") |>
dplyr::arrange(!dataset %in% "ADSL", dataset, variable)

attr(discovery$dataset, 'label') <- "Data Set"
attr(discovery$dataset_type, 'label') <- "Data Set Type" # ADSL, BDS, OCCDS
attr(discovery$variable, 'label') <- "Variable/Parameter"
attr(discovery$variable_label, 'label') <- "Description"
attr(discovery$package, 'label') <- "Admiral Package"
attr(discovery$fn, 'label') <- "Function"
attr(discovery$fn_url, 'label') <- "Function URL"
attr(discovery$resource1_text, 'label') <- "Resource Link Text"
attr(discovery$resource1_url, 'label') <- "Resource URL"
attr(discovery$dataset, "label") <- "Data Set"
attr(discovery$dataset_type, "label") <- "Data Set Type" # ADSL, BDS, OCCDS
attr(discovery$variable, "label") <- "Variable/Parameter"
attr(discovery$variable_label, "label") <- "Description"
attr(discovery$package, "label") <- "Admiral Package"
attr(discovery$fn, "label") <- "Function"
attr(discovery$fn_url, "label") <- "Function URL"
attr(discovery$resource1_text, "label") <- "Resource Link Text"
attr(discovery$resource1_url, "label") <- "Resource URL"

usethis::use_data(discovery, overwrite = TRUE)
9 changes: 6 additions & 3 deletions tests/spelling.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
if(requireNamespace('spelling', quietly = TRUE))
spelling::spell_check_test(vignettes = TRUE, error = FALSE,
skip_on_cran = TRUE)
if (requireNamespace("spelling", quietly = TRUE)) {
spelling::spell_check_test(
vignettes = TRUE, error = FALSE,
skip_on_cran = TRUE
)
}
1 change: 0 additions & 1 deletion tests/testthat/test-discovery.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ test_that("Warn for Deprecated/Superseded Functions", {
}
print(df_deprecated)
})

})


Expand Down

0 comments on commit 15faf61

Please sign in to comment.