Skip to content

Commit

Permalink
Merge pull request #256 from aghaynes/master
Browse files Browse the repository at this point in the history
fix issues that have cropped up since the last version (of R and deps)
  • Loading branch information
aghaynes authored Nov 27, 2023
2 parents f0034ed + ef85893 commit f6423d2
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 44 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: secuTrialR
Type: Package
Title: Handling of Data from the Clinical Data Management System 'secuTrial'
Version: 1.1.1
Version: 1.2.0
Authors@R:
c(person(given = "Alan G.",
family = "Haynes",
role = c("cre", "aut", "cph"),
email = "alan.haynes@ctu.unibe.ch"),
email = "[email protected]"),
person(given = "Patrick R.",
family = "Wright",
role = c("aut", "cph"),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# secuTrialR 1.2.0

* `write_secuTrial()` no longer allows `format = "sas"` due to deprecation of write_sas in `haven` (version 2.5.2).
* `read_secuTrial_raw` now produces a more explicit warning when ISO-8859 encoding is used. Recent changes in R seem to have reduced compatibility with this encoding.

# secuTrialR 1.1.1
* fix CRAN notes - remove codecov badge, check class via inherits

Expand Down
1 change: 1 addition & 0 deletions R/read_export_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ read_export_table <- function(data_dir, file_name, export_options,
curr_encoding <- export_options$encoding
if (curr_encoding == "ISO-8859-1" | curr_encoding == "ISO-8859-15") {
curr_encoding <- "latin1"
warning("ISO-8859-1 encoding detected. Strings may not be interpreted correctly")
}

if (export_options$is_zip) {
Expand Down
10 changes: 4 additions & 6 deletions R/write_secuTrial.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Write secuTrial exports to other formats
#' @description Convert the export prepared in R and export it to
#' SPSS (sav), Stata (dta) or SAS (sas, xpt version 8)
#' SPSS (sav), Stata (dta) or SAS (xpt version 8)
#' using the haven package.
#' @name write_secuTrial
#' @param object \code{secuTrialdata} object
Expand All @@ -27,12 +27,12 @@
write_secuTrial <- function(object, ...) UseMethod("write_secuTrial", object)
#' @export
#' @name write_secuTrial
#' @param format format in which to save the export (one of "dta", "sas", "sav", "xpt")
#' @param format format in which to save the export (one of "dta", "sav", "xpt")
#' @param metadata if TRUE then metadate files will also be written
write_secuTrial.secuTrialdata <- function(object, format = "dta", metadata = FALSE, ...) {

if (! format %in% c("dta", "sas", "sav", "xpt")) {
stop(paste0("format must be one of 'dta', 'sas', 'sav', 'xpt'. You specified: ", format))
if (! format %in% c("dta", "sav", "xpt")) {
stop(paste0("format must be one of 'dta', 'sav', 'xpt'. You specified: ", format))
}
x <- object$export_options$data_names
names(x) <- NULL
Expand All @@ -51,11 +51,9 @@ write_secuTrial.secuTrialdata <- function(object, format = "dta", metadata = FAL
write_secuTrial.data.frame <- function(df, filename, path = "", format = "dta", ...) {
df <- convertnames(df, format)
format2 <- format
if (format == "sas") format2 <- "sas7bdat"
out <- file.path(path, paste0(filename, ".", format2))
if (format == "dta") haven::write_dta(df, out, ...)
if (format == "sav") haven::write_sav(df, out, ...)
if (format == "sas") haven::write_sas(df, out, ...)
if (format == "xpt") haven::write_xpt(df, out, version = 8, ...)
paste("Saved to", out)
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# secuTrialR

[![](https://img.shields.io/badge/dev%20version-1.1.1-blue.svg)](https://github.com/SwissClinicalTrialOrganisation/secuTrialR)
[![](https://img.shields.io/badge/dev%20version-1.2.0-blue.svg)](https://github.com/SwissClinicalTrialOrganisation/secuTrialR)
[![](https://www.r-pkg.org/badges/version/secuTrialR?color=green)](https://cran.r-project.org/package=secuTrialR)
[![AppVeyor Build
Status](https://ci.appveyor.com/api/projects/status/github/SwissClinicalTrialOrganisation/secuTrialR?branch=master&svg=true)](https://ci.appveyor.com/project/SwissClinicalTrialOrganisation/secuTrialR)
Expand Down
4 changes: 2 additions & 2 deletions man/write_secuTrial.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-dates_secutrial.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ path <- system.file("extdata", "sT_exports", "encodings",
"s_export_CSV-xls_TES05_short_ref_en_iso8859-15.zip",
package = "secuTrialR")

tes05_raw <- read_secuTrial_raw(path)
tes05_raw <- suppressWarnings(read_secuTrial_raw(path))

test_that("loading data: TES05 incomplete dates (warn)", {
expect_warning(f <- dates_secuTrial(tes05_raw, warn = TRUE))
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-diff_secuTrial.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ ctu05_en_2 <- read_secuTrial(system.file("extdata", "sT_exports", "snames",
#> ctu05_en_2$export_options$project_version
#[1] "(20.06.2019 - 11:22:04 (CEST))"

ctu05_fr <- read_secuTrial(system.file("extdata", "sT_exports", "encodings",
"s_export_CSV-xls_CTU05_short_ref_miss_fr_iso8859-1.zip",
package = "secuTrialR"))
ctu05_fr <- suppressWarnings(
read_secuTrial(system.file("extdata", "sT_exports", "encodings",
"s_export_CSV-xls_CTU05_short_ref_miss_fr_iso8859-1.zip",
package = "secuTrialR")))
#> ctu05_fr$export_options$project_version
#[1] "(20.06.2019 - 11:22:04 (CEST))"

Expand Down Expand Up @@ -70,3 +71,4 @@ test_that("Different version and changes", {
expect_equal(length(v2_vs_v3$new_forms), 0)
expect_equal(v2_vs_v3$new_variables, "yet_another_item")
})

19 changes: 12 additions & 7 deletions tests/testthat/test-encoding.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ exp_opt_ctu05_iso1_loc <- system.file("extdata", "sT_exports", "encodings",
# utf8
exp_opt_ctu05_utf8_eo <- read_export_options(exp_opt_ctu05_utf8_loc)
# ISO-8859-15
exp_opt_ctu05_iso15_eo <- read_export_options(exp_opt_ctu05_iso15_loc)
exp_opt_ctu05_iso15_eo <- suppressWarnings(
read_export_options(exp_opt_ctu05_iso15_loc))
# ISO-8859-1
exp_opt_ctu05_iso1_eo <- read_export_options(exp_opt_ctu05_iso1_loc)
exp_opt_ctu05_iso1_eo <- suppressWarnings(
read_export_options(exp_opt_ctu05_iso1_loc))

# test encoding parser
test_that("encodings parsed as expected", {
Expand All @@ -53,9 +55,9 @@ test_that("all export options outputs are equal", {
# utf8
exp_opt_ctu05_utf8_export <- read_secuTrial_raw(exp_opt_ctu05_utf8_loc)
# ISO-8859-15
exp_opt_ctu05_iso15_export <- read_secuTrial_raw(exp_opt_ctu05_iso15_loc)
exp_opt_ctu05_iso15_export <- suppressWarnings(read_secuTrial_raw(exp_opt_ctu05_iso15_loc))
# ISO-8859-1
exp_opt_ctu05_iso1_export <- read_secuTrial_raw(exp_opt_ctu05_iso1_loc)
exp_opt_ctu05_iso1_export <- suppressWarnings(read_secuTrial_raw(exp_opt_ctu05_iso1_loc))

# nolint end

Expand All @@ -80,9 +82,12 @@ test_that("UTF-8 + BOM is not supported", {
# macroman
# the parsed options are incorrect thus we disallow MacRoman
test_that("MacRoman is not supported", {
expect_error(read_export_options(system.file("extdata", "sT_exports", "encodings",
"s_export_CSV-xls_CTU05_short_ref_miss_fr_macroman.zip",
package = "secuTrialR"))
expect_error(
suppressWarnings(
read_export_options(system.file("extdata", "sT_exports", "encodings",
"s_export_CSV-xls_CTU05_short_ref_miss_fr_macroman.zip",
package = "secuTrialR"))
)
)
})

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-links_secuTrial.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ len_long <- links_secuTrial(sT_export_long, plot = FALSE)
len_sep_ref <- links_secuTrial(sT_export_sep_ref, plot = FALSE)

test_that("igraph structure", {
expect_equal(len_short, len_short)
expect_equal(len_short, 310)
expect_equal(len_sep_ref, 1266)
expect_equal(len_short, len_long)
expect_equal(len_short, 170)
expect_equal(len_sep_ref, 666)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-plot_recruitment.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ ldat <- read_secuTrial(system.file("extdata", "sT_exports", "lnames",
ctu05_utf8_french <- read_secuTrial(system.file("extdata", "sT_exports", "encodings",
"s_export_CSV-xls_CTU05_short_ref_miss_fr_utf8.zip",
package = "secuTrialR"))
ctu05_iso15_french <- read_secuTrial(system.file("extdata", "sT_exports", "encodings",
ctu05_iso15_french <- suppressWarnings(read_secuTrial(system.file("extdata", "sT_exports", "encodings",
"s_export_CSV-xls_CTU05_short_ref_miss_fr_iso8859-15.zip",
package = "secuTrialR"))
package = "secuTrialR")))

only_col_names_export_location <- system.file("extdata", "sT_exports", "exp_opt",
"s_export_CSV-xls_CTU05_only_column_names.zip",
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-read_export_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ dup_meta <- read_export_options(system.file("extdata", "sT_exports", "lnames",
package = "secuTrialR"))

# ISO-8859-15
exp_opt_tes05_iso <- read_export_options(system.file("extdata", "sT_exports", "encodings",
exp_opt_tes05_iso <- suppressWarnings(read_export_options(system.file("extdata", "sT_exports", "encodings",
"s_export_CSV-xls_TES05_short_ref_en_iso8859-15.zip",
package = "secuTrialR"))
package = "secuTrialR")))

# test encoding
test_that("Encoding parsed as expected.", {
Expand Down
16 changes: 1 addition & 15 deletions tests/testthat/test-write_secuTrial.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,64 @@ tdir <- tempdir()

test_that("writing", {
expect_error(write_secuTrial(sdat, path = tdir, format = "dta"), regexp = NA)
expect_error(write_secuTrial(sdat, path = tdir, format = "sas"), regexp = NA)
expect_error(write_secuTrial(sdat, path = tdir, format = "sav"), regexp = NA)
expect_error(write_secuTrial(sdat, path = tdir, format = "xpt"), regexp = NA)
expect_error(write_secuTrial(ldat, path = tdir, format = "dta"), regexp = NA)
expect_error(write_secuTrial(ldat, path = tdir, format = "sas"), regexp = NA)
expect_error(write_secuTrial(ldat, path = tdir, format = "sav"), regexp = NA)
expect_error(write_secuTrial(ldat, path = tdir, format = "xpt"), regexp = NA)
})

test_that("files exist", {
expect_true(file.exists(file.path(tdir, paste0("treatment", ".dta"))))
expect_true(file.exists(file.path(tdir, paste0("treatment", ".sas7bdat"))))
expect_true(file.exists(file.path(tdir, paste0("treatment", ".sav"))))
expect_true(file.exists(file.path(tdir, paste0("treatment", ".xpt"))))
expect_false(file.exists(file.path(tdir, paste0("cn", ".dta"))))
expect_false(file.exists(file.path(tdir, paste0("cn", ".sas7bdat"))))
expect_false(file.exists(file.path(tdir, paste0("cn", ".sav"))))
expect_false(file.exists(file.path(tdir, paste0("cn", ".xpt"))))

expect_true(file.exists(file.path(tdir, paste0("ctu05treatment", ".dta"))))
expect_true(file.exists(file.path(tdir, paste0("ctu05treatment", ".sas7bdat"))))
expect_true(file.exists(file.path(tdir, paste0("ctu05treatment", ".sav"))))
expect_true(file.exists(file.path(tdir, paste0("ctu05treatment", ".xpt"))))
expect_false(file.exists(file.path(tdir, paste0("casenodes", ".dta"))))
expect_false(file.exists(file.path(tdir, paste0("casenodes", ".sas7bdat"))))
expect_false(file.exists(file.path(tdir, paste0("casenodes", ".sav"))))
expect_false(file.exists(file.path(tdir, paste0("casenodes", ".xpt"))))
})

test_that("writing meta", {
expect_error(write_secuTrial(sdat, path = tdir, format = "dta", metadata = TRUE), regexp = NA)
expect_error(write_secuTrial(sdat, path = tdir, format = "sas", metadata = TRUE), regexp = NA)
expect_error(write_secuTrial(sdat, path = tdir, format = "sav", metadata = TRUE), regexp = NA)
expect_error(write_secuTrial(sdat, path = tdir, format = "xpt", metadata = TRUE), regexp = NA)
expect_error(write_secuTrial(ldat, path = tdir, format = "dta", metadata = TRUE), regexp = NA)
expect_error(write_secuTrial(ldat, path = tdir, format = "sas", metadata = TRUE), regexp = NA)
expect_error(write_secuTrial(ldat, path = tdir, format = "sav", metadata = TRUE), regexp = NA)
expect_error(write_secuTrial(ldat, path = tdir, format = "xpt", metadata = TRUE), regexp = NA)
})

test_that("files exist", {
expect_true(file.exists(file.path(tdir, paste0("treatment", ".dta"))))
expect_true(file.exists(file.path(tdir, paste0("treatment", ".sas7bdat"))))
expect_true(file.exists(file.path(tdir, paste0("treatment", ".sav"))))
expect_true(file.exists(file.path(tdir, paste0("treatment", ".xpt"))))
expect_true(file.exists(file.path(tdir, paste0("cn", ".dta"))))
expect_true(file.exists(file.path(tdir, paste0("cn", ".sas7bdat"))))
expect_true(file.exists(file.path(tdir, paste0("cn", ".sav"))))
expect_true(file.exists(file.path(tdir, paste0("cn", ".xpt"))))

expect_true(file.exists(file.path(tdir, paste0("ctu05treatment", ".dta"))))
expect_true(file.exists(file.path(tdir, paste0("ctu05treatment", ".sas7bdat"))))
expect_true(file.exists(file.path(tdir, paste0("ctu05treatment", ".sav"))))
expect_true(file.exists(file.path(tdir, paste0("ctu05treatment", ".xpt"))))
expect_true(file.exists(file.path(tdir, paste0("casenodes", ".dta"))))
expect_true(file.exists(file.path(tdir, paste0("casenodes", ".sas7bdat"))))
expect_true(file.exists(file.path(tdir, paste0("casenodes", ".sav"))))
expect_true(file.exists(file.path(tdir, paste0("casenodes", ".xpt"))))
})

# test file content
write_secuTrial(sdat, format = "dta", path = tdir)
write_secuTrial(sdat, format = "sav", path = tdir)
write_secuTrial(sdat, format = "sas", path = tdir)
write_secuTrial(sdat, format = "xpt", path = tdir)
sdat_dta_bl <- read_dta(paste0(tdir, "/baseline.dta"))
sdat_sav_bl <- read_sav(paste0(tdir, "/baseline.sav"))
sdat_sas_bl <- read_sas(paste0(tdir, "/baseline.sas7bdat"))
sdat_xpt_bl <- read_xpt(paste0(tdir, "/baseline.xpt"))

test_that("Baseline weight data is equal exist", {
expect_true(all.equal(as.vector(sdat_dta_bl$weight), as.vector(sdat_sav_bl$weight)))
expect_true(all.equal(as.vector(sdat_dta_bl$weight), as.vector(sdat_sas_bl$weight)))
expect_true(all.equal(as.vector(sdat_dta_bl$weight), as.vector(sdat_xpt_bl$weight)))
expect_true(all.equal(as.vector(sdat_dta_bl$weight), as.vector(sdat$baseline$weight)))
expect_true(all.equal(as.vector(sdat_dta_bl$weight), as.vector(ldat$ctu05baseline$weight)))
Expand All @@ -93,4 +78,5 @@ test_that("Baseline weight data is equal exist", {
# test error catch for non-included formats
test_that("Format illegal", {
expect_error(write_secuTrial(sdat, format = "thatsnotit", path = tdir))
expect_error(write_secuTrial(sdat, format = "sas", path = tdir))
})

0 comments on commit f6423d2

Please sign in to comment.