Skip to content

Commit

Permalink
Cleanup doc warnings in iidda package
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencarlislewalker committed Feb 26, 2024
1 parent 7d322ca commit 7001b47
Show file tree
Hide file tree
Showing 33 changed files with 507 additions and 34 deletions.
6 changes: 6 additions & 0 deletions R/iidda/R/data_frame_tools.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#' Set IIDDA Column Types
#'
#' Deprecated -- iidda.api package is not more robust.
#'
#' @param data Dataset from IIDDA Api
#'
#' @export
set_iidda_col_types = function(data) {
if (names(data)[1] == 'Internal Server Error') {
Expand Down
6 changes: 6 additions & 0 deletions R/iidda/R/historical_normalization.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ normalize_diseases = function(diseases) {
)
}

#' Two Field Format
#'
#' Attempt to automatically convert a dataset from `disease{|_subclass|_family}`
#' format of disease ID to the `{|nesting_}disease` format.
#'
#' @param dataset A tidy data set with `disease{|_subclass|_family}` columns.
#' @export
two_field_format = function(dataset) {
(dataset
Expand Down
39 changes: 29 additions & 10 deletions R/iidda/R/metadata_tools.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#' Read Tracking Tables
#'
#' Read metadata tracking tables for an IIDDA project.
#'
#' @param path Path containing tracking tables.
#'
#' @export
read_tracking_tables = function(path) {
valid_colnames = c("access_script", "disease_family", "disease", "disease_subclass", "icd_7", "icd_9",
Expand All @@ -12,13 +18,20 @@ read_tracking_tables = function(path) {
"staging_url_prefix", "scan", "access_script", "prep_script"
)
paths = file.path(path, list.files(path, pattern = '.csv'))
(paths
output = (paths
%>% lapply(read.csv, check.names = FALSE)
%>% setNames(tools::file_path_sans_ext(basename(paths)))
%>% lapply(function(x) select(x, any_of(valid_colnames)))
#%>% lapply(function(x) select(x, any_of(valid_colnames)))
#%>% lapply(drop_empty_cols)
%>% lapply(drop_empty_rows)
)
valid_tabs = vapply(output, \(tab) all(names(tab) %in% valid_colnames), logical(1L))
if (any(!valid_tabs)) {
for (tnm in names(output)[!valid_tabs]) {
warn_msg = sprintf("Tracking table %s has invalid column names. Valid column names include:\n %s", tnm, paste0(valid_colnames, collapse = ", "))
warning(warn_msg)
}
}
}

#' Read Tracking Metadata
Expand Down Expand Up @@ -189,6 +202,10 @@ get_tracking_metadata = function(tidy_dataset, digitization, tracking_path, orig
metadata
}

#' Which Tracking Tables have a Particular Column
#'
#' @param metadata Output of \code{\link{read_tracking_tables}}.
#' @param col_nm Name of a column.
#' @export
tracking_tables_with_column = function(metadata, col_nm) {
(metadata
Expand All @@ -200,6 +217,8 @@ tracking_tables_with_column = function(metadata, col_nm) {
)
}

#' Tracking Table Keys
#'
#' @export
tracking_table_keys = list(
organization = list(
Expand All @@ -225,6 +244,11 @@ tracking_table_keys = list(
)


#' Melt Tracking Table Keys (Deprecated)
#'
#' To be used in conjunction with \code{\link{tracking_table_keys}}.
#'
#' @param keys Character vector of
#' @export
melt_tracking_table_keys = function(keys) {
(keys
Expand All @@ -233,15 +257,10 @@ melt_tracking_table_keys = function(keys) {
)
}

#' Check Tracking Table Consistency
#' Write Local Data Dictionaries
#'
#' @param path path to tracking tables
check_tracking_tables = function(path) {
d = read_tracking_tables(path)

}


#' @param metadata Output of \code{\link{read_tracking_tables}}.
#' @param path Path to a new JSON file.
#' @importFrom tibble rownames_to_column
#' @importFrom jsonlite write_json
#' @export
Expand Down
13 changes: 13 additions & 0 deletions R/iidda/R/missing_value_config.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#' Missing Handlers
#'
#' Construct an object with functions for handling missing values.
#'
#' @param unclear Character vector giving values corresponding to numbers
#' that were unclear to data enterers.
#' @param not_reported Character vector giving values corresponding to
#' numbers that were not reported in the original source.
#' @param zeros Character vector giving values corresponding to
#' `0` but that were entered as another character to resemble the original
#' source.
#'
#' @returns An environment with functions for handling missing values.
#' @export
MissingHandlers = function(
unclear = c("Unclear", "unclear", "uncleaar", "uncelar", "r")
Expand Down
4 changes: 4 additions & 0 deletions R/iidda/R/readme_templates.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#' README File Template
#'
#' (Deprecated)
#'
#' @export
readme_classic_iidda = "# %{new_data_name}s
Expand Down
57 changes: 56 additions & 1 deletion R/iidda/R/repo_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ list_file_id = function(..., ext, root) {
#' List Resources IDs
#'
#' @param source Source ID.
#' @param type Type of resouce.
#' @param type Type of resource.
#' @param root Path to the root of the repository.
#'
#' @export
Expand All @@ -90,6 +90,13 @@ list_resource_ids = function(source
read.csv(file.path(pipeline_dir, source, "tracking", file))[[1L]]
}

#' List Dependency IDs
#'
#' @param source Source ID.
#' @param dataset Dataset ID.
#' @param type Type of resource.
#' @param root Path to the root of the repository.
#'
#' @export
list_dependency_ids = function(source, dataset
, type = c("PrepScripts", "Scans", "Digitizations", "AccessScripts")
Expand All @@ -107,6 +114,13 @@ list_dependency_ids = function(source, dataset
tracking[[1L]][tracking[[2L]] == dataset]
}

#' List Dependency Paths
#'
#' @param source Source ID.
#' @param dataset dataset ID.
#' @param type Type of resource.
#' @param root Path to the root of the repository.
#'
#' @export
list_dependency_paths = function(source, dataset
, type = c("PrepScripts", "Scans", "Digitizations", "AccessScripts")
Expand All @@ -120,9 +134,15 @@ list_dependency_paths = function(source, dataset
vapply(strip_blob_github(urls), add_root_and_check, character(1L), USE.NAMES = FALSE)
}

#' List Source IDs
#'
#' @param root Path to the root of the repository.
#' @export
list_source_ids = function(root) list.files(add_root_and_check("pipelines", root))

#' List Dataset IDs by Source
#'
#' @param root Path to the root of the repository.
#' @export
list_dataset_ids_by_source = function(root) {
sources = list_source_ids(root)
Expand All @@ -133,16 +153,33 @@ list_dataset_ids_by_source = function(root) {
)
}

#' List Dataset IDs
#'
#' @param source Source ID.
#' @param root Path to the root of the repository.
#'
#' @export
list_dataset_ids = function(source, root) {
list_resource_ids(source, "TidyDatasets", root)
}

#' List Prep Script IDs
#'
#' @param source Source ID.
#' @param root Path to the root of the repository.
#'
#' @export
list_prep_script_ids = function(source, root) {
list_resource_ids(source, "PrepScripts", root)
}


#' Get Main Script
#'
#' @param source Source ID.
#' @param dataset dataset ID.
#' @param root Path to the root of the repository.
#'
#' @export
get_main_script = function(source, dataset, root) {
assert_string(
Expand All @@ -151,6 +188,12 @@ get_main_script = function(source, dataset, root) {
)
}

#' Get all Dependencies
#'
#' @param source Source ID.
#' @param dataset dataset ID.
#' @param root Path to the root of the repository.
#'
#' @export
get_all_dependencies = function(source, dataset, root) {
unlist(lapply(c("PrepScripts", "Scans", "Digitizations", "AccessScripts")
Expand All @@ -161,6 +204,13 @@ get_all_dependencies = function(source, dataset, root) {
))
}

#' Get Dataset path
#'
#' @param source Source ID.
#' @param dataset dataset ID.
#' @param root Path to the root of the repository.
#' @param ext Dataset file extension.
#'
#' @export
get_dataset_path = function(source, dataset, root, ext = "csv") {
path = file.path(
Expand All @@ -175,6 +225,11 @@ get_dataset_path = function(source, dataset, root, ext = "csv") {
add_root(path, root)
}

#' Get Source Path
#'
#' @param source Source ID.
#' @param root Path to the root of the repository.
#'
#' @export
get_source_path = function(source, root) {
add_root(
Expand Down
15 changes: 12 additions & 3 deletions R/iidda/R/string_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,25 @@ vsub = function(pattern, replacement, x, ...) {
x
}

#' Remove Trailing Slash
#' Remove Trailing / Leading Slash
#'
#' @param x Character vector with paths
#' @return Character vector without trailing slash
#' @param x Character vector with paths.
#' @return Character vector without trailing/leading slash.
#' @export
rm_trailing_slash = function(x) sub('/$', '', x)

#' @rdname rm_trailing_slash
#' @export
rm_leading_slash = function(x) sub('^/', '', x)

#' Or Pattern
#'
#' Construct regex for Boolean-or.
#'
#' @param x Character vector of alternative patterns.
#' @param at_start Match only at the start of strings.
#' @param at_end Match only at the end of strings.
#'
#' @export
or_pattern = function(x, at_start = TRUE, at_end = TRUE) {
x = "(" %+% paste0(x, collapse = "|") %+% ")"
Expand Down
6 changes: 6 additions & 0 deletions R/iidda/R/xlsx_diff.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ cp_git_version = function(file, version_hash) {
temp
}

#' Excel to CSV
#'
#' Convert an Excel file to a CSV file.
#'
#' @param xlsx_path Path to an Excel file.
#' @param csv_path Path to a new CSV file.
#' @importFrom tidyxl xlsx_cells
#' @importFrom readr write_csv
#' @export
Expand Down
29 changes: 29 additions & 0 deletions R/iidda/man/MissingHandlers.Rd

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

14 changes: 0 additions & 14 deletions R/iidda/man/check_tracking_tables.Rd

This file was deleted.

18 changes: 18 additions & 0 deletions R/iidda/man/get_all_dependencies.Rd

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

20 changes: 20 additions & 0 deletions R/iidda/man/get_dataset_path.Rd

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

Loading

0 comments on commit 7001b47

Please sign in to comment.