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
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: epidict
Title: Epidemiology Data Dictionaries and Random Data Generators
Version: 0.1.0
Version: 0.2.0
Authors@R: c(
person("Alexander", "Spina", , "aspina@appliedepi.org", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8425-1867")),
Expand Down Expand Up @@ -40,11 +40,12 @@ Suggests:
knitr,
matchmaker,
rmarkdown,
sitrep,
testthat (>= 2.1.0),
withr
VignetteBuilder:
knitr
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(dict_rename_helper)
export(gen_data)
export(msf_dict)
export(msf_dict_rename_helper)
export(read_dict)
importFrom(clipr,write_clip)
importFrom(dplyr,bind_rows)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# epidict 0.2.0
* Reinstate msf_dict_rename_helper() with sitrep in DESCRIPTION suggests

# epidict 0.1.0
* First CRAN release
* Separated out functions for reading dictionaries
Expand Down
122 changes: 61 additions & 61 deletions R/msf_dict_rename_helper.R
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
#' #' Helper for aligning your data to MSF standardised dictionaries and analysis templates.
#' #'
#' #' @param dictionary Specify which MSF dictionary you would like to use.
#' #' See [msf_dict()] for options.
#' #'
#' #' @param copy_to_clipboard if `TRUE` (default), the rename template will be
#' #' copied to the user's clipboard with [clipr::write_clip()]. If `FALSE`, the
#' #' rename template will be printed to the user's console.
#' #'
#' #' @return A dplyr command used to rename columns in your data frame according
#' #' to the dictionary
#' #'
#' #' @importFrom readxl read_excel
#' #'
#' #' @export
#' Helper for aligning your data to MSF standardised dictionaries and analysis templates.
#'
#' msf_dict_rename_helper <- function(dictionary,
#' copy_to_clipboard = TRUE) {
#' @param dictionary Specify which MSF dictionary you would like to use.
#' See [msf_dict()] for options.
#'
#' # just add dict as "empty" if not defined (for checking errors)
#' if (missing("dictionary")) {
#' dictionary <- "empty"
#' }
#' @param copy_to_clipboard if `TRUE` (default), the rename template will be
#' copied to the user's clipboard with [clipr::write_clip()]. If `FALSE`, the
#' rename template will be printed to the user's console.
#'
#' # define dictionary types
#' dict <- get_dictionary(dictionary, org = "MSF")
#' disease <- unlist(dict, use.names = FALSE)
#' is_survey <- length(dict$survey) == 1
#' format <- ifelse(is_survey | grepl("_intersectional", disease),
#' "ODK", "DHIS2")
#' @return A dplyr command used to rename columns in your data frame according
#' to the dictionary
#'
#' # get dictionary
#' dat_dict <- msf_dict(dictionary = disease, compact = TRUE)
#'
#' # define the dictionary columns for variable names and variable type
#' varnames <- ifelse(format == "ODK", "name", "data_element_shortname")
#' varnames_type <- ifelse(format == "ODK", "type", "data_element_valuetype")
#'
#' # remove long and short from vaccination (only one template with 2 dicts)
#' if (disease == "vaccination_short" | disease == "vaccination_long") {
#' disease <- "vaccination"
#' }
#'
#' # only call sitrep if it's installed
#' if (!requireNamespace("sitrep", quietly = TRUE)) {
#' stop(
#' "The 'sitrep' package is required for this function but is not installed.\n",
#' "Please install it from GitHub: R4EPI/sitrep"
#' )
#' }
#'
#' # get the outbreak Rmd to check if the variable is optional or required
#' outbreak_file <- sitrep::available_sitrep_templates(recursive = TRUE, pattern = ".Rmd", full.names = TRUE)
#' outbreak_file <- grep(tolower(disease), outbreak_file, value = TRUE)[[1]]
#'
#' # call the dict_rename_helper function
#' dict_rename_helper(
#' dictionary = dat_dict,
#' varnames = varnames,
#' varnames_type = varnames_type,
#' rmd = outbreak_file,
#' copy_to_clipboard = copy_to_clipboard
#' )
#'
#' }
#' @importFrom readxl read_excel
#'
#' @export

msf_dict_rename_helper <- function(dictionary,
copy_to_clipboard = TRUE) {

# just add dict as "empty" if not defined (for checking errors)
if (missing("dictionary")) {
dictionary <- "empty"
}

# define dictionary types
dict <- get_dictionary(dictionary, org = "MSF")
disease <- unlist(dict, use.names = FALSE)
is_survey <- length(dict$survey) == 1
format <- ifelse(is_survey | grepl("_intersectional", disease),
"ODK", "DHIS2")

# get dictionary
dat_dict <- msf_dict(dictionary = disease, compact = TRUE)

# define the dictionary columns for variable names and variable type
varnames <- ifelse(format == "ODK", "name", "data_element_shortname")
varnames_type <- ifelse(format == "ODK", "type", "data_element_valuetype")

# remove long and short from vaccination (only one template with 2 dicts)
if (disease == "vaccination_short" | disease == "vaccination_long") {
disease <- "vaccination"
}

# only call sitrep if it's installed
if (!requireNamespace("sitrep", quietly = TRUE)) {
stop(
"The 'sitrep' package is required for this function but is not installed.\n",
"Please install it using install.packages('sitrep)"
)
}

# get the outbreak Rmd to check if the variable is optional or required
outbreak_file <- sitrep::available_sitrep_templates(recursive = TRUE, pattern = ".Rmd", full.names = TRUE)
outbreak_file <- grep(tolower(disease), outbreak_file, value = TRUE)[[1]]

# call the dict_rename_helper function
dict_rename_helper(
dictionary = dat_dict,
varnames = varnames,
varnames_type = varnames_type,
rmd = outbreak_file,
copy_to_clipboard = copy_to_clipboard
)

}

13 changes: 2 additions & 11 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,8 @@

## R CMD check results

0 errors | 0 warnings | 1 note
0 errors | 0 warnings | 0 note

* This is a new submission to CRAN.*

All URLs and metadata issues noted in the previous submission have been corrected:
- Updated Title field to title case.
- possible misspelled words in DESCRIPTION are correct as is.
- Updated all URLs to canonical HTTPS versions with trailing slashes.
- Updated lifecycle badge link to https://lifecycle.r-lib.org/articles/stages.html#maturing.
- Spelled out acronyms.
- description spacing fixed and link added to describe methods
- value descriptions added to functions
- new function added for a minor release


23 changes: 23 additions & 0 deletions man/msf_dict_rename_helper.Rd

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

Loading
Loading