Skip to content

Commit

Permalink
#107 styler
Browse files Browse the repository at this point in the history
  • Loading branch information
edgar-manukyan committed Dec 2, 2024
1 parent 26345f2 commit 6e308e1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
13 changes: 0 additions & 13 deletions R/generate_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ is_character <- function(var_in) {
#' @export
#'
#' @examples
#'
#' \dontrun{
#' spec <- read_spec("cm_sdtm_oak_spec_cdash.csv")
#' domain <- "cm"
Expand All @@ -113,7 +112,6 @@ is_character <- function(var_in) {
#' }
#'
generate_code <- function(spec, domain, out_dir = ".") {

admiraldev::assert_data_frame(spec, required_vars = rlang::syms(expected_columns))
admiraldev::assert_character_scalar(domain)

Expand Down Expand Up @@ -144,7 +142,6 @@ generate_code <- function(spec, domain, out_dir = ".") {
#' @keywords internal
#'
generate_one_var_code <- function(spec_var) {

admiraldev::assert_data_frame(spec_var)
assertthat::assert_that(identical(nrow(spec_var), 1L))

Expand Down Expand Up @@ -186,7 +183,6 @@ generate_one_var_code <- function(spec_var) {
#' @keywords internal
#'
#' @examples
#'
#' \dontrun{
#' str_in <- "a, b, c"
#' parse_into_c_call("a, b, c")
Expand All @@ -196,7 +192,6 @@ generate_one_var_code <- function(spec_var) {
#' }
#'
parse_into_c_call <- function(str_in) {

admiraldev::assert_character_scalar(str_in)

str_out <- str_in |>
Expand All @@ -220,7 +215,6 @@ parse_into_c_call <- function(str_in) {
#' @keywords internal
#'
add_pipe <- function(code_block) {

admiraldev::assert_character_vector(code_block)

i <- length(code_block)
Expand All @@ -238,7 +232,6 @@ add_pipe <- function(code_block) {
#' @keywords internal
#'
remove_last_pipe <- function(code_blocks) {

admiraldev::assert_character_vector(code_blocks)

len_code_block <- length(code_blocks)
Expand All @@ -260,7 +253,6 @@ remove_last_pipe <- function(code_blocks) {
#'
#' @examples
get_domain_spec <- function(spec, domain) {

expected_columns <- c(
"raw_dataset",
"raw_variable",
Expand All @@ -286,9 +278,7 @@ get_domain_spec <- function(spec, domain) {
# TODO
# Doing only few variables
dplyr::filter(target_sdtm_variable %in% tgt_vars) |>

dplyr::select(dplyr::all_of(expected_columns)) |>

# For now swapping entity_sub_algorithm with mapping_algorithm since the
# algorithms like assign_no_ct are the mapping_algorithm and they are populated
# in the entity_sub_algorithm
Expand All @@ -306,7 +296,6 @@ get_domain_spec <- function(spec, domain) {
entity_sub_algorithm = entity_sub_algorithm_temp
) |>
dplyr::select(-entity_sub_algorithm_temp) |>

# Need to use the condition_add_raw_dat (if not missing) instead of raw_dataset
dplyr::mutate(
raw_dataset = dplyr::if_else(
Expand All @@ -326,14 +315,12 @@ get_domain_spec <- function(spec, domain) {
#' @export
#'
#' @examples
#'
#' \dontrun{
#' file <- "cm_sdtm_oak_spec_cdash.csv"
#' observed <- read_spec(file)
#' }
#'
read_spec <- function(file) {

admiraldev::assert_character_scalar(file)

spec <- utils::read.csv(file = file, na.strings = c("NA", ""), colClasses = "character") |>
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-generate_code.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
test_that("generate_code works", {

# nolint start
spec <- tibble::tribble(
~study_number, ~raw_dataset, ~raw_dataset_label, ~raw_variable, ~raw_variable_label, ~raw_variable_ordinal, ~raw_variable_type, ~raw_data_format, ~raw_fmt, ~raw_unk, ~study_specific, ~annotation_ordinal, ~mapping_is_dataset, ~annotation_text, ~target_sdtm_domain, ~target_sdtm_variable, ~target_sdtm_variable_role, ~target_sdtm_variable_codelist_code, ~target_sdtm_variable_controlled_terms_or_format, ~target_sdtm_variable_ordinal, ~origin, ~mapping_algorithm, ~entity_sub_algorithm, ~target_hardcoded_value, ~target_term_value, ~target_value, ~target_term_code, ~condition_ordinal, ~condition_group_ordinal, ~condition_add_raw_dat, ~condition_add_tgt_dat, ~condition_left_raw_dataset, ~condition_left_raw_variable, ~condition_left_sdtm_domain, ~condition_left_sdtm_variable, ~condition_operator, ~condition_right_text_value, ~condition_right_sdtm_domain, ~condition_right_sdtm_variable, ~condition_right_raw_dataset, ~condition_right_raw_variable, ~condition_next_logical_operator, ~merge_type, ~merge_left, ~merge_right, ~merge_condition, ~unduplicate_keys, ~groupby_keys, ~target_resource_raw_dataset, ~target_resource_raw_variable,
Expand All @@ -24,7 +23,7 @@ test_that("generate_code works", {

withr::with_options(list(width = 20L), {
generate_code(spec, domain, out_dir)
observed <- readLines(file.path(out_dir, paste0(domain, "_sdtm_oak_code.R")))
observed <- readLines(file.path(out_dir, paste0(domain, "_sdtm_oak_code.R")))

expect_gt(length(observed), 10L)
expect_true(grepl("generate_oak_id_vars", observed, fixed = TRUE) |> any())
Expand Down

0 comments on commit 6e308e1

Please sign in to comment.