Skip to content

Commit

Permalink
Merge pull request #231 from pharmaverse/230_debian
Browse files Browse the repository at this point in the history
Closes #230 - debian issues
  • Loading branch information
reesnj authored Jan 8, 2025
2 parents acc872f + 8874893 commit 95e8146
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: datacutr
Type: Package
Title: SDTM Datacut
Version: 0.2.1
Version: 0.2.2
Authors@R: c(
person("Tim", "Barnett", email = "timothy.barnett@roche.com", role = c("cph","aut", "cre")),
person("Nathan", "Rees", email = "nathan.rees@roche.com", role = c("aut")),
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# datacutr 0.2.2

## Updates of Existing Functions
None

## Various
Tests using temporary directories cleaned up

# datacutr 0.2.1

## Updates of Existing Functions
Expand Down
21 changes: 12 additions & 9 deletions tests/testthat/test-process_cut.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ expected <- list(
ae = ae_cut, lb = lb_cut, ts = ts_cut
)

# Create temporary directory for testing output file
temp_dir <- tempdir()

# Test that every type of datacut gives the expected result, when special_dm=TRUE -----------

test_that("Test that every type of datacut gives the expected result, when special_dm=TRUE", {
Expand Down Expand Up @@ -177,6 +174,9 @@ test_that("Test that process_cut() errors when special_dm = TRUE and dm is also
# Test Read-out file -------------
# Test that read-out file is ran successfully when special_dm = TRUE
test_that("Test that Correct .Rmd file is ran successfully when read_out = TRUE", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
# Run test
process_cut(
source_sdtm_data = source_data,
patient_cut_v = c("sc", "ds"),
Expand All @@ -189,10 +189,10 @@ test_that("Test that Correct .Rmd file is ran successfully when read_out = TRUE"
cut_var = DCUTDTM,
special_dm = TRUE,
read_out = TRUE,
out_path = paste0(temp_dir, "/dummyfile")
out_path = paste0(temp_dir)
)
expect_true(dir.exists(temp_dir) & (length(list.files(paste0(temp_dir, "/dummyfile")))) > 0)
unlink(paste0(temp_dir, "/dummyfile"), recursive = TRUE)
expect_true(dir.exists(temp_dir) & (length(list.files(temp_dir))) > 0)
unlink(temp_dir, recursive = TRUE)
})

# Test that every type of datacut gives the expected result, when special_dm=FALSE -----------
Expand Down Expand Up @@ -221,6 +221,9 @@ test_that("Test that every type of datacut gives the expected result, when speci

# Test that Read-out file is ran successfully when special_dm = FALSE
test_that("Test that Correct .Rmd file is ran successfully when read_out = TRUE", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
# Run test
process_cut(
source_sdtm_data = source_data,
patient_cut_v = c("sc", "ds"),
Expand All @@ -233,8 +236,8 @@ test_that("Test that Correct .Rmd file is ran successfully when read_out = TRUE"
cut_var = DCUTDTM,
special_dm = FALSE,
read_out = TRUE,
out_path = paste0(temp_dir, "/dummyfile")
out_path = temp_dir
)
expect_true(dir.exists(temp_dir) & (length(list.files(paste0(temp_dir, "/dummyfile"))) > 0))
unlink(paste0(temp_dir, "/dummyfile"), recursive = TRUE)
expect_true(dir.exists(temp_dir) & (length(list.files(temp_dir)) > 0))
unlink(temp_dir, recursive = TRUE)
})
71 changes: 54 additions & 17 deletions tests/testthat/test-read_out.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,189 +75,226 @@ dm_cut <- tibble::tribble(
# Test that .Rmd gives the expected result when all fields are set to default or contain valid data -----------
# Correct .Rmd file is run successfully when fields contain correct data inputs
test_that("Correct .Rmd file is run successfully when fields contain correct data inputs", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
# Call read_out() to generate the .Rmd file
result <- read_out(
dcut = dcut,
patient_cut_data = pt_cut_data,
date_cut_data = dt_cut_data,
dm_cut = dm_cut,
no_cut_list = no_cut_ls,
out_path = tempdir()
out_path = temp_dir
)
# Assert that the output file is generated successfully
expect_true(file.exists(result))
unlink(result, recursive = TRUE)
expect_true(dir.exists(temp_dir) & (length(list.files(temp_dir))) > 0)
unlink(temp_dir, recursive = TRUE)
})

# Test that Correct .Rmd file is ran successfully when fields are empty
test_that("Correct .Rmd file is ran successfully when fields are empty", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
# Call read_out() to generate the .Rmd file
result <- read_out(out_path = tempdir())
result <- read_out(out_path = temp_dir)
# Assert that the output file is generated successfully
expect_true(file.exists(result))
unlink(result, recursive = TRUE)
expect_true(dir.exists(temp_dir) & (length(list.files(temp_dir))) > 0)
unlink(temp_dir, recursive = TRUE)
})

# Test read_out() errors when data cut fields are incorrect input types -----------
## DCUT ----
# Test that read_out() errors dcut data frame does not contain the var DCUTDTC
test_that("Test that read_out() errors dcut data frame does not contain the var DCUTDTC", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
expect_error(read_out(
dcut = sc,
patient_cut_data = pt_cut_data,
date_cut_data = dt_cut_data,
dm_cut = dm_cut,
no_cut_list = no_cut_ls,
out_path = tempdir()
out_path = temp_dir
))
unlink(temp_dir, recursive = TRUE)
})

## Patient_cut_data ----
# Test that read_out() errors when patient_cut_data input is not a list
test_that("Test that read_out() errors when patient_cut_data input is not a list", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
expect_error(
read_out(
dcut = dcut,
patient_cut_data = sc,
date_cut_data = dt_cut_data,
dm_cut = dm_cut,
no_cut_list = no_cut_ls,
out_path = tempdir()
out_path = temp_dir
),
regexp = "patient_cut_data must be a list. \n
Note: If you have not used or do not with to view patient cut on any SDTMv domains, then
please leave patient_cut_data empty, in which case a default value of NULL will be used."
)
unlink(temp_dir, recursive = TRUE)
})

# Test that read_out() errors when elements in the patient_cut_data list are not data frames
test_that("Test that read_out() errors when elements in the patient_cut_data list are not data frames", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
expect_error(read_out(
dcut = dcut,
patient_cut_data = list("sc", "ds"),
date_cut_data = dt_cut_data,
dm_cut = dm_cut,
no_cut_list = no_cut_ls,
out_path = tempdir()
out_path = temp_dir
))
unlink(temp_dir, recursive = TRUE)
})

# Test that read_out() errors when data frames in patient_cut_data are unnamed
test_that("Test that read_out() errors when data frames in patient_cut_data are unnamed", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
expect_error(
read_out(
dcut = dcut,
patient_cut_data = list(sc, ds),
date_cut_data = dt_cut_data,
dm_cut = dm_cut,
no_cut_list = no_cut_ls,
out_path = tempdir()
out_path = temp_dir
),
regexp = "All elements patient_cut_data must be named with corresponding domain"
)
unlink(temp_dir, recursive = TRUE)
})

## Date_cut_data ----
# Test that read_out() errors when date_cut_data input is not a list
test_that("Test that read_out() errors when date_cut_data input is not a list", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
expect_error(
read_out(
dcut = dcut,
patient_cut_data = pt_cut_data,
date_cut_data = ae,
dm_cut = dm_cut,
no_cut_list = no_cut_ls,
out_path = tempdir()
out_path = temp_dir
),
regexp = "date_cut_data must be a list. \n
Note: If you have not used or do not with to view date cut on any SDTMv domains, then please
leave date_cut_data empty, in which case a default value of NULL will be used."
)
unlink(temp_dir, recursive = TRUE)
})

# Test that read_out() errors when elements in the date_cut_data list are not data frames
test_that("Test that read_out() errors when elements in the date_cut_data list are not data frames", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
expect_error(read_out(
dcut = dcut,
patient_cut_data = pt_cut_data,
date_cut_data = list("ae", "lb"),
dm_cut = dm_cut,
no_cut_list = no_cut_ls,
out_path = tempdir()
out_path = temp_dir
))
unlink(temp_dir, recursive = TRUE)
})

# Test that read_out() errors when data frames in date_cut_data are unnamed
test_that("Test that read_out() errors when data frames in date_cut_data are unnamed", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
expect_error(
read_out(
dcut = dcut,
patient_cut_data = pt_cut_data,
date_cut_data = list(ae, lb),
dm_cut = dm_cut,
no_cut_list = no_cut_ls,
out_path = tempdir()
out_path = temp_dir
),
regexp = "All elements in date_cut_data must be named with corresponding domain"
)
unlink(temp_dir, recursive = TRUE)
})

## dm_cut ----
# Test that read_out() errors when dm_cut data frame does not contain the vars DCUT_TEMP_REMOVE & DCUT_TEMP_DTHCHANG
test_that("Test that read_out() errors when dm_cut data frame does not contain the vars DCUT_TEMP_REMOVE & DCUT_TEMP_DTHCHANGE", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
expect_error(read_out(
dcut = dcut,
patient_cut_data = pt_cut_data,
date_cut_data = dt_cut_data,
dm_cut = sc,
no_cut_list = no_cut_ls,
out_path = tempdir()
out_path = temp_dir
))
unlink(temp_dir, recursive = TRUE)
})


## no_cut_list ----
# Test that read_out() errors when no_cut_list is not a list
test_that("Test that read_out() errors when no_cut_list is not a list", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
expect_error(
read_out(
dcut = dcut,
patient_cut_data = pt_cut_data,
date_cut_data = dt_cut_data,
dm_cut = dm_cut,
no_cut_list = ds,
out_path = tempdir()
out_path = temp_dir
),
regexp = "no_cut_list must be a list. \n
Note: If you have not used or do not with to view the SDTMv domains where no cut has been
applied, then please leave no_cut_list empty, in which case a default value of NULL will be
used."
)
unlink(temp_dir, recursive = TRUE)
})

# Test that read_out() errors when elements in the no_cut_list list are not data frames
test_that("Test that read_out() errors when elements in the no_cut_list list are not data frames", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
expect_error(read_out(
dcut = dcut,
patient_cut_data = pt_cut_data,
date_cut_data = dt_cut_data,
dm_cut = dm_cut,
no_cut_list = ls("ts"),
out_path = tempdir()
out_path = temp_dir
))
unlink(temp_dir, recursive = TRUE)
})

# Test that read_out() errors when elements in the no_cut_list list are not named with the corresponding domain
test_that("Test that read_out() errors when elements in the no_cut_list list are not named with the corresponding domain", {
# Create temporary directory for testing output file
temp_dir <- tempdir()
expect_error(
read_out(
dcut = dcut,
patient_cut_data = pt_cut_data,
date_cut_data = dt_cut_data,
dm_cut = dm_cut,
no_cut_list = list(ts, ae),
out_path = tempdir()
out_path = temp_dir
),
regexp = "All elements in no_cut_list must be named with corresponding domain"
)
unlink(temp_dir, recursive = TRUE)
})

0 comments on commit 95e8146

Please sign in to comment.