Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions .github/workflows/link_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Links (Fail Fast)

on:
pull_request:
branches:
- main

jobs:
linkChecker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up R # Install R from CRAN
uses: r-lib/actions/setup-r@v2
with:
r-version: '4.4.3' # You can specify a different R version if needed

- name: Install R packages
run: |
Rscript -e 'install.packages("fs")'
shell: bash

- name: Link Checker
uses: lycheeverse/[email protected]
with:
fail: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42 changes: 42 additions & 0 deletions .github/workflows/spellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Spellcheck
on:
pull_request:
branches: ['main']
jobs:
Spelling:
runs-on: ubuntu-latest
container:
image: "rocker/tidyverse:4.3.1"
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install packages
run: |
if (!require("roxygen2")) install.packages("roxygen2")
if (!require("spelling")) install.packages("spelling")
if (!require("testthat")) install.packages("testthat")
shell: Rscript {0}

- name: Check spelling
run: |
library(spelling)

# Check the entire package (R files, documentation, vignettes, etc.)
words <- spelling::spell_check_package()

print(words)

testthat::test_that(desc = "Check spelling", code = {
testthat::expect_equal(
object = nrow(words),
expected = 0,
info = if (nrow(words) > 0) {
paste("Spelling errors found:\n",
paste(capture.output(print(words)), collapse = "\n"))
} else {
"No spelling errors"
}
)
})
shell: Rscript {0}
20 changes: 20 additions & 0 deletions .github/workflows/style_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Style
on:
pull_request: {branches: ['main']}

jobs:
Style:
runs-on: ubuntu-latest
container: {image: "rocker/tidyverse:4.2.1"}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install styler
run: install.packages("styler")
shell: Rscript {0}
- name: styler version
run: packageVersion("styler")
shell: Rscript {0}
- name: Run styler
run: styler::style_dir(dry = "fail")
shell: Rscript {0}
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ VignetteBuilder:
knitr
Encoding: UTF-8
Roxygen: list(markdown = TRUE, r6 = FALSE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
104 changes: 52 additions & 52 deletions R/DatasetMeta.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,64 @@
DatasetMeta <- R6::R6Class("DatasetMeta",
inherit = MetaCore,
private = list(
.name = NA,
.label = NA,
.num_vars = NA,
.key_vars = NA,

.greet = function(quiet) {
cli_par()
cli_alert_success("{private$.name} dataset successfully selected")
if (quiet) {
cli_inform(c(
"i" = col_red("Dataset metadata specification subsetted with suppressed warnings")))
}
cli_end()
}
.name = NA,
.label = NA,
.num_vars = NA,
.key_vars = NA,
.greet = function(quiet) {
cli_par()
cli_alert_success("{private$.name} dataset successfully selected")
if (quiet) {
cli_inform(c(
"i" = col_red("Dataset metadata specification subsetted with suppressed warnings")
))
}
cli_end()
}
),

public = list(
initialize = function(metacore, quiet = FALSE) {
super$initialize(
ds_spec = metacore$ds_spec,
ds_vars = metacore$ds_vars,
var_spec = metacore$var_spec,
value_spec = metacore$value_spec,
derivations = metacore$derivations,
codelist = metacore$codelist,
supp = metacore$supp
)
private$.name = metacore$ds_spec$dataset[1]
private$.label = metacore$ds_spec$label[1]
private$.num_vars = metacore$ds_vars |> nrow()
private$.key_vars = metacore$ds_vars |>
filter(!is.na(key_seq)) |>
pull(variable)

private$.greet(quiet)
},
initialize = function(metacore, quiet = FALSE) {
super$initialize(
ds_spec = metacore$ds_spec,
ds_vars = metacore$ds_vars,
var_spec = metacore$var_spec,
value_spec = metacore$value_spec,
derivations = metacore$derivations,
codelist = metacore$codelist,
supp = metacore$supp
)
private$.name <- metacore$ds_spec$dataset[1]
private$.label <- metacore$ds_spec$label[1]
private$.num_vars <- metacore$ds_vars |> nrow()
private$.key_vars <- metacore$ds_vars |>
filter(!is.na(key_seq)) |>
pull(variable)

print = function() {
tables <- ls(envir = self)
private$.greet(quiet)
},
print = function() {
tables <- ls(envir = self)

cli_par()
cli_rule(left = "Dataset specification object for {private$.name} ({private$.label})")
cli_text("The dataset contains {private$.num_vars} variable{?s}")
cli_text("Dataset key{?s}: {ansi_collapse(private$.key_vars, last = ', ')}")
cli_end()
cli_par()
cli_rule(left = "Dataset specification object for {private$.name} ({private$.label})")
cli_text("The dataset contains {private$.num_vars} variable{?s}")
cli_text("Dataset key{?s}: {ansi_collapse(private$.key_vars, last = ', ')}")
cli_end()

cli_par()
cli_text("The structure of the specification object is:")
for (table in tables) {
obj <- get(table, envir = self)
if (!is.list(obj)) { next }
cli_bullets(c(">" = "{table}: {typeof(table)} [{dim(obj)[1]} x {dim(obj)[2]}] {ansi_collapse(names(obj), last = ', ')}"))
cli_par()
cli_text("The structure of the specification object is:")
for (table in tables) {
obj <- get(table, envir = self)
if (!is.list(obj)) {
next
}
cli_end()
cli_bullets(c(">" = "{table}: {typeof(table)} [{dim(obj)[1]} x {dim(obj)[2]}] {ansi_collapse(names(obj), last = ', ')}"))
}
cli_end()

cli_div()
cli_text("To inspect the specification object use {.fn View} in the console.")
cli_end()
}
cli_div()
cli_text("To inspect the specification object use {.fn View} in the console.")
cli_end()
}
)
)
60 changes: 31 additions & 29 deletions R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@
#'
#' check_inconsistent_types(metacore)
#' @rdname checks
check_inconsistent_labels <- function(metacore){
basic_check(label, metacore)
check_inconsistent_labels <- function(metacore) {
basic_check(label, metacore)
}

#' @export
#' @rdname checks
check_inconsistent_types <- function(metacore){
basic_check(type, metacore)
check_inconsistent_types <- function(metacore) {
basic_check(type, metacore)
}

#' @export
#' @rdname checks
check_inconsistent_formats <- function(metacore){
basic_check(format, metacore)
check_inconsistent_formats <- function(metacore) {
basic_check(format, metacore)
}

#' Base code for running cross variable checks
Expand All @@ -55,32 +55,34 @@ check_inconsistent_formats <- function(metacore){
#' @noRd
#' @importFrom stringr str_glue
#' @importFrom dplyr across
basic_check <- function(col_to_check, metacore){
if(!is_metacore(metacore)){
cli_abort("Expects a metacore object", call. = FALSE)
}
basic_check <- function(col_to_check, metacore) {
if (!is_metacore(metacore)) {
cli_abort("Expects a metacore object", call. = FALSE)
}

report_df <- metacore$var_spec %>%
mutate(var1 = str_remove(variable, "[[:alnum:]]+\\.")) %>%
group_by(var1) %>%
mutate(n_lab = n_distinct({{col_to_check}})) %>%
filter(n_lab > 1) %>%
mutate(across(everything(), remove_label)) %>%
group_by(var1, {{col_to_check}}) %>%
summarise(n_vars = n(),
ls_of_vars = list(variable),
.groups = "drop") %>%
select(variable = var1, everything())
report_df <- metacore$var_spec %>%
mutate(var1 = str_remove(variable, "[[:alnum:]]+\\.")) %>%
group_by(var1) %>%
mutate(n_lab = n_distinct({{ col_to_check }})) %>%
filter(n_lab > 1) %>%
mutate(across(everything(), remove_label)) %>%
group_by(var1, {{ col_to_check }}) %>%
summarise(
n_vars = n(),
ls_of_vars = list(variable),
.groups = "drop"
) %>%
select(variable = var1, everything())

if(nrow(report_df) > 0){
cli_warn(str_glue("Mismatch {as_label(enexpr(col_to_check))}s detected"))
return(report_df)
} else {
cli_inform(str_glue("No mismatch {as_label(enexpr(col_to_check))}s detected"))
}
if (nrow(report_df) > 0) {
cli_warn(str_glue("Mismatch {as_label(enexpr(col_to_check))}s detected"))
return(report_df)
} else {
cli_inform(str_glue("No mismatch {as_label(enexpr(col_to_check))}s detected"))
}
}

remove_label <- function(x) {
attr(x, "label") <- NULL
x
attr(x, "label") <- NULL
x
}
Loading