Skip to content

Commit

Permalink
#107 lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
edgar-manukyan committed Dec 2, 2024
1 parent 11e9ebc commit 26345f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
12 changes: 6 additions & 6 deletions R/generate_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ generate_code <- function(spec, domain, out_dir = ".") {
) |>
unlist() |>
remove_last_pipe() |>
append(cm_template_prefix, after = 0) |>
append(cm_template_prefix, after = 0L) |>
styler::style_text()

# Save the code to a file
Expand Down Expand Up @@ -165,7 +165,7 @@ generate_one_var_code <- function(spec_var) {
}

# Remove the arguments that are missing
args <- purrr::discard(args, \(x) is.vector(x) && any(is.na(x)))
args <- purrr::discard(args, \(x) is.vector(x) && anyNA(x))

# Generate the function call
generated_call <- rlang::call2(
Expand Down Expand Up @@ -200,7 +200,7 @@ parse_into_c_call <- function(str_in) {
admiraldev::assert_character_scalar(str_in)

str_out <- str_in |>
stringr::str_split(",") |>
stringr::str_split(stringr::fixed(",")) |>
unlist() |>
stringr::str_trim()

Expand Down Expand Up @@ -245,7 +245,7 @@ remove_last_pipe <- function(code_blocks) {

# The last code block should not have a pipe operator
code_blocks[len_code_block] <- code_blocks[len_code_block] |>
stringr::str_remove("%>%")
stringr::str_remove(stringr::fixed("%>%"))

code_blocks
}
Expand Down Expand Up @@ -296,12 +296,12 @@ get_domain_spec <- function(spec, domain) {
entity_sub_algorithm_temp = dplyr::if_else(
mapping_algorithm %in% "condition_add",
mapping_algorithm,
entity_sub_algorithm,
entity_sub_algorithm
),
mapping_algorithm = dplyr::if_else(
mapping_algorithm %in% "condition_add",
entity_sub_algorithm,
mapping_algorithm,
mapping_algorithm
),
entity_sub_algorithm = entity_sub_algorithm_temp
) |>
Expand Down
18 changes: 8 additions & 10 deletions tests/testthat/test-generate_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ test_that("generate_code works", {

# Convert all NA to NA_character_
spec <- spec |>
dplyr::mutate(
dplyr::across(
.cols = dplyr::everything(),
.fns = ~dplyr::if_else(is.na(.x), NA_character_, .x)
)
)
dplyr::mutate(dplyr::across(
.cols = dplyr::everything(),
.fns = ~ dplyr::if_else(is.na(.x), NA_character_, .x)
))

domain <- "cm"

Expand All @@ -24,12 +22,12 @@ test_that("generate_code works", {
unlink(out_dir, recursive = TRUE, force = TRUE)
dir.create(out_dir, showWarnings = FALSE, recursive = TRUE)

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

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

0 comments on commit 26345f2

Please sign in to comment.