From 11e664f2937713e553d03f186ffd90578c96391c Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Fri, 28 Jun 2024 20:34:01 +0100 Subject: [PATCH 01/48] Bump version --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d80fffcc..db31af00 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: TwoSampleMR Title: Two Sample MR Functions and Interface to MR Base Database -Version: 0.6.4 +Version: 0.6.5 Authors@R: c( person("Gibran", "Hemani", , "g.hemani@bristol.ac.uk", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0920-1055")), diff --git a/NEWS.md b/NEWS.md index 1eddb855..d0c5d10d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# TwoSampleMR v0.6.5 + +(Release date: 2024-##-##) + # TwoSampleMR v0.6.4 (Release date: 2024-06-05) From 2c02618179dc673223cd82323390d85469692a38 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Fri, 28 Jun 2024 20:34:25 +0100 Subject: [PATCH 02/48] Bump roxygen2 version --- DESCRIPTION | 2 +- NEWS.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index db31af00..efe14bee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -69,4 +69,4 @@ Remotes: WSpiller/RadialMR Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 diff --git a/NEWS.md b/NEWS.md index d0c5d10d..61e99638 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ (Release date: 2024-##-##) +* Bumped version of roxygen2 for creating package documentation # TwoSampleMR v0.6.4 (Release date: 2024-06-05) From ded538afdad3c9b06605e7f72fb70ed6f1b97842 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Fri, 28 Jun 2024 20:36:20 +0100 Subject: [PATCH 03/48] Only test back to R version 4.3.2 --- .github/workflows/check-full.yaml | 9 ++------- NEWS.md | 4 +++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/check-full.yaml b/.github/workflows/check-full.yaml index 4785740b..196eceba 100644 --- a/.github/workflows/check-full.yaml +++ b/.github/workflows/check-full.yaml @@ -25,9 +25,7 @@ jobs: - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} - {os: ubuntu-latest, r: 'oldrel-1'} - - {os: ubuntu-latest, r: 'oldrel-2'} - - {os: ubuntu-latest, r: 'oldrel-3'} - - {os: ubuntu-latest, r: 'oldrel-4'} + - {os: ubuntu-latest, r: '4.3.2'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} @@ -48,10 +46,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: > - any::rcmdcheck, - randomForest=?ignore-before-r=4.1.0, - car=?ignore-before-r=4.4.0, - MendelianRandomization=?ignore-before-r=4.4.0 + any::rcmdcheck needs: check - name: Create and populate .Renviron file diff --git a/NEWS.md b/NEWS.md index 61e99638..2db51dc9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,9 @@ (Release date: 2024-##-##) -* Bumped version of roxygen2 for creating package documentation +* Bumped version of **roxygen2** for creating package documentation +* Update the earliest version of R in the `R CMD check` GitHub Actions workflow to be 4.3.2. This is because the **meta** dependency depends on **lme4**, and the recent 1.1-35.4 release of **lme4** requires **Matrix** 1.6-2 which was released a few days after R 4.3.2. + # TwoSampleMR v0.6.4 (Release date: 2024-06-05) From c41c745b3a17424ece90df06564825c36bb4518d Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 11:09:36 +0100 Subject: [PATCH 04/48] Re-enable tests requiring API --- tests/testthat/test_rsq.r | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/tests/testthat/test_rsq.r b/tests/testthat/test_rsq.r index 9377b810..54e7addb 100644 --- a/tests/testthat/test_rsq.r +++ b/tests/testthat/test_rsq.r @@ -10,8 +10,9 @@ test_that("exposure data 1", { }) test_that("exposure data 2", { - skip("Skip unless you have good access to the API.") - d <- extract_instruments(c('ieu-a-2', 'ieu-a-7')) %>% add_rsq() + d <- extract_instruments(c('ieu-a-2', 'ieu-a-7')) + if(inherits(d, "response")) skip("Server issues") + d <- d %>% add_rsq() expect_true("rsq.exposure" %in% names(d)) expect_true("effective_n.exposure" %in% names(d)) }) @@ -19,31 +20,34 @@ test_that("exposure data 2", { exposure <- exp_dat[1:5,] test_that("outcome data 1", { - skip("Skip unless you have good access to the API.") - d <- extract_outcome_data(exposure$SNP, 'ieu-a-2') %>% add_rsq() + d <- extract_outcome_data(exposure$SNP, 'ieu-a-2') + if(inherits(d, "response")) skip("Server issues") + d <- d %>% add_rsq() expect_true("rsq.outcome" %in% names(d)) expect_true("effective_n.outcome" %in% names(d)) }) test_that("outcome data 2", { - skip("Skip unless you have good access to the API") - d <- extract_outcome_data(exposure$SNP, c('ieu-a-2', 'ieu-a-7')) %>% add_rsq() + d <- extract_outcome_data(exposure$SNP, c('ieu-a-2', 'ieu-a-7')) + if(inherits(d, "response")) skip("Server issues") + d <- d %>% add_rsq() expect_true("rsq.outcome" %in% names(d)) expect_true("effective_n.outcome" %in% names(d)) }) test_that("dat 2", { - skip("Skip unless you have good access to the API.") - d <- make_dat(proxies=FALSE) %>% add_rsq() + d <- make_dat(proxies=FALSE) + if(inherits(d, "response")) skip("Server issues") + d <- d %>% add_rsq() expect_true("rsq.outcome" %in% names(d) & "rsq.exposure" %in% names(d)) expect_true("effective_n.outcome" %in% names(d) & "effective_n.exposure" %in% names(d)) }) test_that("dat ukb-d", { - skip("Skip unless you have good access to the API.") - skip_on_ci() skip_on_cran() - d <- make_dat(exposure="ukb-d-30710_irnt", proxies=FALSE) %>% add_rsq() + d <- make_dat(exposure="ukb-d-30710_irnt", proxies=FALSE) + if(inherits(d, "response")) skip("Server issues") + d <- d %>% add_rsq() expect_true("rsq.outcome" %in% names(d) & "rsq.exposure" %in% names(d)) }) @@ -55,8 +59,8 @@ test_that("effective n", { }) test_that("get_population_allele_frequency", { - skip("Skip unless you have good access to the API.") d <- extract_instruments("ieu-a-7") + if(inherits(d, "response")) skip("Server issues") d <- add_metadata(d) d$eaf.exposure.controls <- get_population_allele_frequency( af = d$eaf.exposure, @@ -68,16 +72,16 @@ test_that("get_population_allele_frequency", { }) test_that("bbj-a-1", { - skip("Skip unless you have good access to the API.") - skip_on_ci() skip_on_cran() - d <- extract_instruments('bbj-a-1') %>% add_metadata() %>% add_rsq() + d <- extract_instruments('bbj-a-1') + if(inherits(d, "response")) skip("Server issues") + d <- d %>% add_metadata() %>% add_rsq() expect_true(all(!is.na(d$rsq.exposure))) }) test_that("bsen vs pn", { - skip("Skip unless you have good access to the API.") d <- extract_instruments("ieu-a-2") + if(inherits(d, "response")) skip("Server issues") r1 <- get_r_from_bsen(d$beta.exposure, d$se.exposure, d$samplesize.exposure) r2 <- get_r_from_pn(d$pval.exposure, d$samplesize.exposure) expect_true(cor(abs(r1), r2) > 0.99) From bda26e03074fa73134ab2b85d817d9b9a417d282 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 11:12:05 +0100 Subject: [PATCH 05/48] Re-enable tests requiring API --- tests/testthat/test_outcomes.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test_outcomes.R b/tests/testthat/test_outcomes.R index a7f0008d..8144e290 100644 --- a/tests/testthat/test_outcomes.R +++ b/tests/testthat/test_outcomes.R @@ -2,27 +2,32 @@ context("outcome") test_that("outcomes", { - skip("Skip unless you have good access to the API.") - skip_on_ci() skip_on_cran() a <- extract_instruments("ieu-a-7") + if(inherits(a, "response")) skip("Server issues") b <- extract_outcome_data(a$SNP, "ieu-a-2", proxies=FALSE) + if(inherits(b, "response")) skip("Server issues") expect_true(nrow(b) < 30 & nrow(b) > 15) b <- extract_outcome_data(a$SNP, "ieu-a-2", proxies=TRUE) + if(inherits(b, "response")) skip("Server issues") expect_true(nrow(b) > 30 & nrow(b) < nrow(a)) b <- extract_outcome_data(a$SNP, c("ieu-a-2", "a"), proxies=FALSE) + if(inherits(b, "response")) skip("Server issues") expect_true(nrow(b) < 30 & nrow(b) > 15) b <- extract_outcome_data(a$SNP, c("ieu-a-2", "a"), proxies=TRUE) + if(inherits(b, "response")) skip("Server issues") expect_true(nrow(b) > 30 & nrow(b) < nrow(a)) b <- extract_outcome_data(a$SNP, c("ieu-a-2", "ieu-a-7"), proxies=FALSE) + if(inherits(b, "response")) skip("Server issues") expect_true(nrow(b) > 60) b <- extract_outcome_data(a$SNP, c("ieu-a-2", "ieu-a-7"), proxies=TRUE) + if(inherits(b, "response")) skip("Server issues") expect_true(nrow(b) > 70) }) From bbb73c738898abd5c79a69a7353b1092662dc2f0 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 11:15:18 +0100 Subject: [PATCH 06/48] Re-enable tests requiring API --- tests/testthat/test_otherformats.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/testthat/test_otherformats.R b/tests/testthat/test_otherformats.R index 21bcecaf..e6a16f09 100644 --- a/tests/testthat/test_otherformats.R +++ b/tests/testthat/test_otherformats.R @@ -12,8 +12,6 @@ test_that("MRInput", { }) test_that("MRInput with cor", { - skip("Skip unless you have good access to the API.") - skip_on_ci() skip_on_cran() expect_warning(w <- dat_to_MRInput(dat, get_correlations=TRUE)[[1]]) expect_true(nrow(w@correlation) == length(w@betaX)) From 3a8670cf0222153b3c093630abd258c73c11be29 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 11:17:08 +0100 Subject: [PATCH 07/48] Add API checks for future --- tests/testthat/test_ldsc.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test_ldsc.R b/tests/testthat/test_ldsc.R index 290a9796..4d8b9f19 100644 --- a/tests/testthat/test_ldsc.R +++ b/tests/testthat/test_ldsc.R @@ -4,7 +4,9 @@ context("LDSC") test_that("get afl2", { skip("Very slow") hm3info <- ieugwasr::afl2_list("hapmap3") + if(inherits(hm3info, "response")) skip("Server issues") s <- ieugwasr::afl2_list() + if(inherits(s, "response")) skip("Server issues") a <- ldsc_h2("ieu-a-2", snpinfo=hm3info) b <- ldsc_rg("ieu-a-2", "ieu-a-2", snpinfo=hm3info) c <- ldsc_rg("ukb-a-248", "ukb-b-19953", snpinfo=hm3info) From f5d2e71f80818ab97bdb1bb0d66c84d8aa8a1aa0 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 11:22:10 +0100 Subject: [PATCH 08/48] Re-enable test requiring API --- tests/testthat/test_ld.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/testthat/test_ld.R b/tests/testthat/test_ld.R index dccbc938..4af3dcba 100644 --- a/tests/testthat/test_ld.R +++ b/tests/testthat/test_ld.R @@ -1,10 +1,9 @@ context("ld") test_that("extract some data", { - skip("Skip unless you have good access to the API.") - skip_on_ci() skip_on_cran() a <- extract_instruments(2, clump=FALSE) + if(inherits(a, "response")) skip("Server issues") out <- clump_data(a) }) From 47df9a306b0b5a87462146c469a852e1102a71a8 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 11:22:22 +0100 Subject: [PATCH 09/48] Remove a skip() --- tests/testthat/test_ld.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test_ld.R b/tests/testthat/test_ld.R index 4af3dcba..13279aa3 100644 --- a/tests/testthat/test_ld.R +++ b/tests/testthat/test_ld.R @@ -37,7 +37,6 @@ test_that("clump multiple", { }) test_that("clump local", { - skip("Skip unless you're GH running this test locally.") skip_on_ci() skip_on_cran() skip_if_not(file.exists("/Users/gh13047/repo/opengwas-api-internal/opengwas-api/app/ld_files/EUR.bim")) From cdb50f223bc7f66f748cb3179ac7ddcaca8db575 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 11:29:20 +0100 Subject: [PATCH 10/48] Add skip_on_ci() --- tests/testthat/test_add_metadata.r | 20 ++++++++++---------- tests/testthat/test_instruments.R | 2 +- tests/testthat/test_ld.R | 3 --- tests/testthat/test_mvmr.R | 3 --- tests/testthat/test_mvmr_local.R | 1 - tests/testthat/test_otherformats.R | 1 + tests/testthat/test_outcomes.R | 1 + tests/testthat/test_rsq.r | 8 ++++++++ 8 files changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/testthat/test_add_metadata.r b/tests/testthat/test_add_metadata.r index 925c8c2e..9e47c227 100644 --- a/tests/testthat/test_add_metadata.r +++ b/tests/testthat/test_add_metadata.r @@ -18,64 +18,64 @@ context("add metadata") load(system.file("extdata", "test_add_metadata.RData", package="TwoSampleMR")) test_that("exposure data 1", { - skip("Skip unless you have good access to the API.") + skip_on_ci() d1 <- d1 %>% add_metadata() expect_true("units.exposure" %in% names(d1)) }) test_that("exposure data 2", { - skip("Skip unless you have good access to the API.") + skip_on_ci() d2 <- d2 %>% add_metadata() expect_true("units.exposure" %in% names(d2)) }) test_that("outcome data 1", { - skip("Skip unless you have good access to the API.") + skip_on_ci() d3 <- d3 %>% add_metadata() expect_true("units.outcome" %in% names(d3)) }) test_that("outcome data 2", { - skip("Skip unless you have good access to the API.") + skip_on_ci() d4 <- d4 %>% add_metadata() expect_true("units.outcome" %in% names(d4)) }) test_that("dat 2", { - skip("Skip unless you have good access to the API.") + skip_on_ci() d5 <- d5 %>% add_metadata() expect_true("units.outcome" %in% names(d5) & "units.exposure" %in% names(d5)) }) test_that("no id1", { - skip("Skip unless you have good access to the API.") + skip_on_ci() d6$id.exposure <- "not a real id" d6 <- add_metadata(d6) expect_true(!"units.exposure" %in% names(d6)) }) test_that("no id2", { - skip("Skip unless you have good access to the API.") + skip_on_ci() d7$id.outcome <- "not a real id" d7 <- add_metadata(d7) expect_true(!"units.outcome" %in% names(d7)) }) test_that("ukb-d", { - skip("Skip unless you have good access to the API.") + skip_on_ci() d8 <- add_metadata(d8) expect_true("units.outcome" %in% names(d8)) }) test_that("bbj-a-1", { - skip("Skip unless you have good access to the API.") + skip_on_ci() d9 <- d9 %>% add_metadata() expect_true("samplesize.exposure" %in% names(d9)) expect_true(all(!is.na(d9$samplesize.exposure))) }) test_that("ieu-b-109", { - skip("Skip unless you have good access to the API.") + skip_on_ci() d10 <- d10 %>% add_metadata() expect_true("samplesize.exposure" %in% names(d10)) expect_true(all(!is.na(d10$samplesize.exposure))) diff --git a/tests/testthat/test_instruments.R b/tests/testthat/test_instruments.R index 222a470e..27c5cd13 100644 --- a/tests/testthat/test_instruments.R +++ b/tests/testthat/test_instruments.R @@ -2,7 +2,7 @@ context("Instruments") test_that("server and mrinstruments", { - skip("Skip unless you have good access to the API.") + skip_on_ci() # no no exp_dat <- extract_instruments(outcomes=c("ieu-a-1032")) diff --git a/tests/testthat/test_ld.R b/tests/testthat/test_ld.R index 13279aa3..267d8e1e 100644 --- a/tests/testthat/test_ld.R +++ b/tests/testthat/test_ld.R @@ -8,7 +8,6 @@ test_that("extract some data", { }) test_that("clump", { - skip("Skip unless you have good access to the API.") skip_on_ci() skip_on_cran() expect_equal(ncol(a), ncol(out)) @@ -18,7 +17,6 @@ test_that("clump", { test_that("matrix", { - skip("Skip unless you have good access to the API.") skip_on_ci() skip_on_cran() b <- ld_matrix(out$SNP) @@ -28,7 +26,6 @@ test_that("matrix", { test_that("clump multiple", { - skip("Skip unless you have good access to the API.") skip_on_ci() skip_on_cran() a <- extract_instruments(c("ieu-a-2", "ieu-a-1001"), clump=FALSE) diff --git a/tests/testthat/test_mvmr.R b/tests/testthat/test_mvmr.R index e217db6b..4025fe25 100644 --- a/tests/testthat/test_mvmr.R +++ b/tests/testthat/test_mvmr.R @@ -1,7 +1,6 @@ context("mvmr") test_that("control", { - skip("Skip unless you have good access to the API.") skip_on_ci() skip_on_cran() lipids <- mv_extract_exposures(c("ieu-a-299","ieu-a-300","ieu-a-302")) @@ -19,7 +18,6 @@ test_that("control", { test_that("dat", { - skip("Skip unless you have good access to the API.") skip_on_ci() skip_on_cran() a <- mv_extract_exposures(c("ukb-b-5238", "ieu-a-1001")) @@ -39,7 +37,6 @@ test_that("dat", { test_that("ordering", { - skip("Skip unless you have good access to the API.") skip_on_ci() skip_on_cran() lipids1 <- mv_extract_exposures(c("ieu-a-299","ieu-a-300","ieu-a-302")) diff --git a/tests/testthat/test_mvmr_local.R b/tests/testthat/test_mvmr_local.R index 657cbb45..158d51ec 100644 --- a/tests/testthat/test_mvmr_local.R +++ b/tests/testthat/test_mvmr_local.R @@ -10,7 +10,6 @@ context("mvmr local") load(system.file("extdata", "test_add_mvmr_local.RData", package="TwoSampleMR")) test_that("mv exposure local", { - skip("Skip unless you have good access to the API.") skip_on_ci() skip_on_cran() f1 <- tempfile() diff --git a/tests/testthat/test_otherformats.R b/tests/testthat/test_otherformats.R index e6a16f09..e8fd11e5 100644 --- a/tests/testthat/test_otherformats.R +++ b/tests/testthat/test_otherformats.R @@ -13,6 +13,7 @@ test_that("MRInput", { test_that("MRInput with cor", { skip_on_cran() + skip_on_ci() expect_warning(w <- dat_to_MRInput(dat, get_correlations=TRUE)[[1]]) expect_true(nrow(w@correlation) == length(w@betaX)) }) diff --git a/tests/testthat/test_outcomes.R b/tests/testthat/test_outcomes.R index 8144e290..d761acce 100644 --- a/tests/testthat/test_outcomes.R +++ b/tests/testthat/test_outcomes.R @@ -3,6 +3,7 @@ context("outcome") test_that("outcomes", { skip_on_cran() + skip_on_ci() a <- extract_instruments("ieu-a-7") if(inherits(a, "response")) skip("Server issues") diff --git a/tests/testthat/test_rsq.r b/tests/testthat/test_rsq.r index 54e7addb..1fb1b39b 100644 --- a/tests/testthat/test_rsq.r +++ b/tests/testthat/test_rsq.r @@ -10,6 +10,7 @@ test_that("exposure data 1", { }) test_that("exposure data 2", { + skip_on_ci() d <- extract_instruments(c('ieu-a-2', 'ieu-a-7')) if(inherits(d, "response")) skip("Server issues") d <- d %>% add_rsq() @@ -20,6 +21,7 @@ test_that("exposure data 2", { exposure <- exp_dat[1:5,] test_that("outcome data 1", { + skip_on_ci() d <- extract_outcome_data(exposure$SNP, 'ieu-a-2') if(inherits(d, "response")) skip("Server issues") d <- d %>% add_rsq() @@ -28,6 +30,7 @@ test_that("outcome data 1", { }) test_that("outcome data 2", { + skip_on_ci() d <- extract_outcome_data(exposure$SNP, c('ieu-a-2', 'ieu-a-7')) if(inherits(d, "response")) skip("Server issues") d <- d %>% add_rsq() @@ -36,6 +39,7 @@ test_that("outcome data 2", { }) test_that("dat 2", { + skip_on_ci() d <- make_dat(proxies=FALSE) if(inherits(d, "response")) skip("Server issues") d <- d %>% add_rsq() @@ -45,6 +49,7 @@ test_that("dat 2", { test_that("dat ukb-d", { skip_on_cran() + skip_on_ci() d <- make_dat(exposure="ukb-d-30710_irnt", proxies=FALSE) if(inherits(d, "response")) skip("Server issues") d <- d %>% add_rsq() @@ -59,6 +64,7 @@ test_that("effective n", { }) test_that("get_population_allele_frequency", { + skip_on_ci() d <- extract_instruments("ieu-a-7") if(inherits(d, "response")) skip("Server issues") d <- add_metadata(d) @@ -73,6 +79,7 @@ test_that("get_population_allele_frequency", { test_that("bbj-a-1", { skip_on_cran() + skip_on_ci() d <- extract_instruments('bbj-a-1') if(inherits(d, "response")) skip("Server issues") d <- d %>% add_metadata() %>% add_rsq() @@ -80,6 +87,7 @@ test_that("bbj-a-1", { }) test_that("bsen vs pn", { + skip_on_ci() d <- extract_instruments("ieu-a-2") if(inherits(d, "response")) skip("Server issues") r1 <- get_r_from_bsen(d$beta.exposure, d$se.exposure, d$samplesize.exposure) From 3c6a3c20ac4b499cc8fabacd48e7397a2ea8ecea Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 11:38:41 +0100 Subject: [PATCH 11/48] Fix API condition --- tests/testthat/test_ld.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_ld.R b/tests/testthat/test_ld.R index 267d8e1e..99301ae3 100644 --- a/tests/testthat/test_ld.R +++ b/tests/testthat/test_ld.R @@ -3,7 +3,7 @@ context("ld") test_that("extract some data", { skip_on_cran() a <- extract_instruments(2, clump=FALSE) - if(inherits(a, "response")) skip("Server issues") + if(length(a) == 0) skip("Server issues") out <- clump_data(a) }) From 978d1e67dab5a854b4f4ce6921e121ed11cf02b1 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 11:43:03 +0100 Subject: [PATCH 12/48] Add skip_on_ci() --- tests/testthat/test_ld.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test_ld.R b/tests/testthat/test_ld.R index 99301ae3..caa7eaca 100644 --- a/tests/testthat/test_ld.R +++ b/tests/testthat/test_ld.R @@ -2,6 +2,7 @@ context("ld") test_that("extract some data", { skip_on_cran() + skip_on_ci() a <- extract_instruments(2, clump=FALSE) if(length(a) == 0) skip("Server issues") out <- clump_data(a) From bee3f4335dd24c52e791e3da6156ebcb4333cf8d Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 21:02:07 +0100 Subject: [PATCH 13/48] Move skips to top of file --- tests/testthat/test_add_metadata.r | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/testthat/test_add_metadata.r b/tests/testthat/test_add_metadata.r index 9e47c227..4c30cce5 100644 --- a/tests/testthat/test_add_metadata.r +++ b/tests/testthat/test_add_metadata.r @@ -1,5 +1,10 @@ context("add metadata") +skip_if_offline() +skip_if_offline(host = "api.opengwas.io") +skip_on_cran() +skip_on_ci() + # get required data # d1 <- extract_instruments('ieu-a-2') # d2 <- extract_instruments(c('ieu-a-2', 'ieu-a-7')) @@ -18,64 +23,54 @@ context("add metadata") load(system.file("extdata", "test_add_metadata.RData", package="TwoSampleMR")) test_that("exposure data 1", { - skip_on_ci() d1 <- d1 %>% add_metadata() expect_true("units.exposure" %in% names(d1)) }) test_that("exposure data 2", { - skip_on_ci() d2 <- d2 %>% add_metadata() expect_true("units.exposure" %in% names(d2)) }) test_that("outcome data 1", { - skip_on_ci() d3 <- d3 %>% add_metadata() expect_true("units.outcome" %in% names(d3)) }) test_that("outcome data 2", { - skip_on_ci() d4 <- d4 %>% add_metadata() expect_true("units.outcome" %in% names(d4)) }) test_that("dat 2", { - skip_on_ci() d5 <- d5 %>% add_metadata() expect_true("units.outcome" %in% names(d5) & "units.exposure" %in% names(d5)) }) test_that("no id1", { - skip_on_ci() d6$id.exposure <- "not a real id" d6 <- add_metadata(d6) expect_true(!"units.exposure" %in% names(d6)) }) test_that("no id2", { - skip_on_ci() d7$id.outcome <- "not a real id" d7 <- add_metadata(d7) expect_true(!"units.outcome" %in% names(d7)) }) test_that("ukb-d", { - skip_on_ci() d8 <- add_metadata(d8) expect_true("units.outcome" %in% names(d8)) }) test_that("bbj-a-1", { - skip_on_ci() d9 <- d9 %>% add_metadata() expect_true("samplesize.exposure" %in% names(d9)) expect_true(all(!is.na(d9$samplesize.exposure))) }) test_that("ieu-b-109", { - skip_on_ci() d10 <- d10 %>% add_metadata() expect_true("samplesize.exposure" %in% names(d10)) expect_true(all(!is.na(d10$samplesize.exposure))) From aa1cd257a631f11142120037ae336c8643c28949 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 21:13:29 +0100 Subject: [PATCH 14/48] Add additional skips --- tests/testthat/test_instruments.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/testthat/test_instruments.R b/tests/testthat/test_instruments.R index 27c5cd13..dc098e90 100644 --- a/tests/testthat/test_instruments.R +++ b/tests/testthat/test_instruments.R @@ -2,6 +2,9 @@ context("Instruments") test_that("server and mrinstruments", { + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") + skip_on_cran() skip_on_ci() # no no From deb737abdb5ce6394026c78df92143113bc8b439 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 21:20:32 +0100 Subject: [PATCH 15/48] Move skips to top of file --- tests/testthat/test_ld.R | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/testthat/test_ld.R b/tests/testthat/test_ld.R index caa7eaca..e59501e5 100644 --- a/tests/testthat/test_ld.R +++ b/tests/testthat/test_ld.R @@ -1,16 +1,17 @@ context("ld") +skip_if_offline() +skip_if_offline(host = "api.opengwas.io") +skip_on_cran() +skip_on_ci() + test_that("extract some data", { - skip_on_cran() - skip_on_ci() a <- extract_instruments(2, clump=FALSE) if(length(a) == 0) skip("Server issues") out <- clump_data(a) }) test_that("clump", { - skip_on_ci() - skip_on_cran() expect_equal(ncol(a), ncol(out)) expect_true(nrow(a) > nrow(out)) expect_true(nrow(out) > 0) @@ -18,8 +19,7 @@ test_that("clump", { test_that("matrix", { - skip_on_ci() - skip_on_cran() + skip_if_not(exists('out'), "out not created in test above") b <- ld_matrix(out$SNP) expect_equal(nrow(b), nrow(out)) expect_equal(ncol(b), nrow(out)) @@ -27,16 +27,13 @@ test_that("matrix", { test_that("clump multiple", { - skip_on_ci() - skip_on_cran() a <- extract_instruments(c("ieu-a-2", "ieu-a-1001"), clump=FALSE) out <- clump_data(a) expect_equal(length(unique(a$id.exposure)), length(unique(out$id.exposure))) }) test_that("clump local", { - skip_on_ci() - skip_on_cran() + skip_if_not(exists('a'), "a not created in test above") skip_if_not(file.exists("/Users/gh13047/repo/opengwas-api-internal/opengwas-api/app/ld_files/EUR.bim")) aclump <- clump_data(a, bfile="/Users/gh13047/repo/opengwas-api-internal/opengwas-api/app/ld_files/EUR", plink_bin="plink") }) From 5d6c50511ae44bc6dd0c21d43819a1e03c79ff4c Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 21:20:47 +0100 Subject: [PATCH 16/48] Add two skips to test --- tests/testthat/test_ld.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test_ld.R b/tests/testthat/test_ld.R index e59501e5..99131501 100644 --- a/tests/testthat/test_ld.R +++ b/tests/testthat/test_ld.R @@ -12,6 +12,8 @@ test_that("extract some data", { }) test_that("clump", { + skip_if_not(exists('a'), "a not created in test above") + skip_if_not(exists('out'), "out not created in test above") expect_equal(ncol(a), ncol(out)) expect_true(nrow(a) > nrow(out)) expect_true(nrow(out) > 0) From 25350e059f77d39b618fea6cae3d5f0c53e7e40c Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 21:24:13 +0100 Subject: [PATCH 17/48] Remove empty test --- tests/testthat/test_ld.R | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test_ld.R b/tests/testthat/test_ld.R index 99131501..82256c82 100644 --- a/tests/testthat/test_ld.R +++ b/tests/testthat/test_ld.R @@ -5,11 +5,10 @@ skip_if_offline(host = "api.opengwas.io") skip_on_cran() skip_on_ci() -test_that("extract some data", { - a <- extract_instruments(2, clump=FALSE) - if(length(a) == 0) skip("Server issues") - out <- clump_data(a) -}) +# extract some data +a <- extract_instruments(2, clump=FALSE) +if(length(a) == 0) skip("Server issues") +out <- clump_data(a) test_that("clump", { skip_if_not(exists('a'), "a not created in test above") From 4c106c123e9aac8d5065c2d2d5a11dee097be963 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 21:26:17 +0100 Subject: [PATCH 18/48] Add offline skips --- tests/testthat/test_mvmr_local.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test_mvmr_local.R b/tests/testthat/test_mvmr_local.R index 158d51ec..084559ef 100644 --- a/tests/testthat/test_mvmr_local.R +++ b/tests/testthat/test_mvmr_local.R @@ -10,6 +10,8 @@ context("mvmr local") load(system.file("extdata", "test_add_mvmr_local.RData", package="TwoSampleMR")) test_that("mv exposure local", { + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") skip_on_ci() skip_on_cran() f1 <- tempfile() From 9afa1e1d37037104b032f7c9b23713705b8985f2 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 21:28:16 +0100 Subject: [PATCH 19/48] Move skips to top of file --- tests/testthat/test_mvmr.R | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test_mvmr.R b/tests/testthat/test_mvmr.R index 4025fe25..69b6c3fa 100644 --- a/tests/testthat/test_mvmr.R +++ b/tests/testthat/test_mvmr.R @@ -1,8 +1,11 @@ context("mvmr") +skip_on_ci() +skip_on_cran() +skip_if_offline() +skip_if_offline(host = "api.opengwas.io") + test_that("control", { - skip_on_ci() - skip_on_cran() lipids <- mv_extract_exposures(c("ieu-a-299","ieu-a-300","ieu-a-302")) chd <- extract_outcome_data(lipids$SNP, "ieu-a-7") control <- mv_harmonise_data(lipids, chd) @@ -18,8 +21,6 @@ test_that("control", { test_that("dat", { - skip_on_ci() - skip_on_cran() a <- mv_extract_exposures(c("ukb-b-5238", "ieu-a-1001")) b <- extract_outcome_data(a$SNP, "ieu-a-297") dat <- mv_harmonise_data(a, b) @@ -37,8 +38,6 @@ test_that("dat", { test_that("ordering", { - skip_on_ci() - skip_on_cran() lipids1 <- mv_extract_exposures(c("ieu-a-299","ieu-a-300","ieu-a-302")) chd1 <- extract_outcome_data(lipids1$SNP, "ieu-a-7") control1 <- mv_harmonise_data(lipids1, chd1) From 526a706a5a8f5840512888852db1e8d4df42525a Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 21:30:22 +0100 Subject: [PATCH 20/48] Add offline skips --- tests/testthat/test_otherformats.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test_otherformats.R b/tests/testthat/test_otherformats.R index e8fd11e5..28187514 100644 --- a/tests/testthat/test_otherformats.R +++ b/tests/testthat/test_otherformats.R @@ -14,6 +14,8 @@ test_that("MRInput", { test_that("MRInput with cor", { skip_on_cran() skip_on_ci() + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") expect_warning(w <- dat_to_MRInput(dat, get_correlations=TRUE)[[1]]) expect_true(nrow(w@correlation) == length(w@betaX)) }) From 28cc0dbf7bc665a884be45bccb1c4e2b845ffdd3 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 21:31:19 +0100 Subject: [PATCH 21/48] Add two offline skips --- tests/testthat/test_outcomes.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test_outcomes.R b/tests/testthat/test_outcomes.R index d761acce..c7a095cf 100644 --- a/tests/testthat/test_outcomes.R +++ b/tests/testthat/test_outcomes.R @@ -2,6 +2,8 @@ context("outcome") test_that("outcomes", { + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") skip_on_cran() skip_on_ci() From 08e51cf05283026528945df30457525131ea0616 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sat, 29 Jun 2024 21:33:33 +0100 Subject: [PATCH 22/48] Add skips --- tests/testthat/test_rsq.r | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/testthat/test_rsq.r b/tests/testthat/test_rsq.r index 1fb1b39b..68417722 100644 --- a/tests/testthat/test_rsq.r +++ b/tests/testthat/test_rsq.r @@ -10,6 +10,9 @@ test_that("exposure data 1", { }) test_that("exposure data 2", { + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") + skip_on_cran() skip_on_ci() d <- extract_instruments(c('ieu-a-2', 'ieu-a-7')) if(inherits(d, "response")) skip("Server issues") @@ -21,6 +24,9 @@ test_that("exposure data 2", { exposure <- exp_dat[1:5,] test_that("outcome data 1", { + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") + skip_on_cran() skip_on_ci() d <- extract_outcome_data(exposure$SNP, 'ieu-a-2') if(inherits(d, "response")) skip("Server issues") @@ -30,6 +36,9 @@ test_that("outcome data 1", { }) test_that("outcome data 2", { + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") + skip_on_cran() skip_on_ci() d <- extract_outcome_data(exposure$SNP, c('ieu-a-2', 'ieu-a-7')) if(inherits(d, "response")) skip("Server issues") @@ -39,6 +48,9 @@ test_that("outcome data 2", { }) test_that("dat 2", { + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") + skip_on_cran() skip_on_ci() d <- make_dat(proxies=FALSE) if(inherits(d, "response")) skip("Server issues") @@ -48,6 +60,9 @@ test_that("dat 2", { }) test_that("dat ukb-d", { + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") + skip_on_cran() skip_on_cran() skip_on_ci() d <- make_dat(exposure="ukb-d-30710_irnt", proxies=FALSE) @@ -64,6 +79,9 @@ test_that("effective n", { }) test_that("get_population_allele_frequency", { + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") + skip_on_cran() skip_on_ci() d <- extract_instruments("ieu-a-7") if(inherits(d, "response")) skip("Server issues") @@ -80,6 +98,8 @@ test_that("get_population_allele_frequency", { test_that("bbj-a-1", { skip_on_cran() skip_on_ci() + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") d <- extract_instruments('bbj-a-1') if(inherits(d, "response")) skip("Server issues") d <- d %>% add_metadata() %>% add_rsq() @@ -87,6 +107,9 @@ test_that("bbj-a-1", { }) test_that("bsen vs pn", { + skip_if_offline() + skip_if_offline(host = "api.opengwas.io") + skip_on_cran() skip_on_ci() d <- extract_instruments("ieu-a-2") if(inherits(d, "response")) skip("Server issues") From 0e1ac666a0ab689860548fc5e545a272025c1399 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 14:31:32 +0100 Subject: [PATCH 23/48] Catch server non-response with try() --- tests/testthat/test_instruments.R | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test_instruments.R b/tests/testthat/test_instruments.R index dc098e90..c5803538 100644 --- a/tests/testthat/test_instruments.R +++ b/tests/testthat/test_instruments.R @@ -8,35 +8,43 @@ test_that("server and mrinstruments", { skip_on_ci() # no no - exp_dat <- extract_instruments(outcomes=c("ieu-a-1032")) + exp_dat <- try(extract_instruments(outcomes=c("ieu-a-1032"))) + if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 0) # no yes - exp_dat <- extract_instruments(outcomes=c("ebi-a-GCST004634")) + exp_dat <- try(extract_instruments(outcomes=c("ebi-a-GCST004634"))) + if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 1) # yes no - exp_dat <- extract_instruments(outcomes=c("ieu-a-2", "ieu-a-1032")) + exp_dat <- try(extract_instruments(outcomes=c("ieu-a-2", "ieu-a-1032"))) + if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 1) # yes yes - exp_dat <- extract_instruments(outcomes=c("ieu-a-2", "ebi-a-GCST004634")) + exp_dat <- try(extract_instruments(outcomes=c("ieu-a-2", "ebi-a-GCST004634"))) + if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 2) - exp_dat <- extract_instruments(outcomes=c("ieu-a-1032", "ebi-a-GCST004634")) + exp_dat <- try(extract_instruments(outcomes=c("ieu-a-1032", "ebi-a-GCST004634"))) + if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 1) - exp_dat <- extract_instruments(outcomes=c(2,100,"ieu-a-1032",104,72,999)) + exp_dat <- try(extract_instruments(outcomes=c(2,100,"ieu-a-1032",104,72,999))) + if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 5) - exp_dat <- extract_instruments(outcomes=c(2,100,"ieu-a-1032",104,72,999, "ebi-a-GCST004634")) + exp_dat <- try(extract_instruments(outcomes=c(2,100,"ieu-a-1032",104,72,999, "ebi-a-GCST004634"))) + if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 6) }) load(system.file("extdata", "test_commondata.RData", package="TwoSampleMR")) test_that("read data", { - # exp_dat <- extract_instruments("ieu-a-2") + exp_dat <- try(extract_instruments("ieu-a-2")) + if (class(exp_dat) == "try-error") skip("Server issues") names(exp_dat) <- gsub(".exposure", "", names(exp_dat)) fn <- tempfile() write.table(exp_dat, file=fn, row=FALSE, col=TRUE, qu=FALSE, sep="\t") From ef7d8c062cfaf8912895c1deed3a76e7830192ed Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 14:33:21 +0100 Subject: [PATCH 24/48] Split into separate tests --- tests/testthat/test_instruments.R | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test_instruments.R b/tests/testthat/test_instruments.R index c5803538..4bde502e 100644 --- a/tests/testthat/test_instruments.R +++ b/tests/testthat/test_instruments.R @@ -1,40 +1,52 @@ context("Instruments") -test_that("server and mrinstruments", { +skip_if_offline() +skip_if_offline(host = "api.opengwas.io") +skip_on_cran() +skip_on_ci() - skip_if_offline() - skip_if_offline(host = "api.opengwas.io") - skip_on_cran() - skip_on_ci() - +test_that("server and mrinstruments 1", { # no no exp_dat <- try(extract_instruments(outcomes=c("ieu-a-1032"))) if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 0) +}) + +test_that("server and mrinstruments 2", { # no yes exp_dat <- try(extract_instruments(outcomes=c("ebi-a-GCST004634"))) if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 1) - +}) + +test_that("server and mrinstruments 3", { # yes no exp_dat <- try(extract_instruments(outcomes=c("ieu-a-2", "ieu-a-1032"))) if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 1) +}) +test_that("server and mrinstruments 4", { # yes yes exp_dat <- try(extract_instruments(outcomes=c("ieu-a-2", "ebi-a-GCST004634"))) if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 2) +}) +test_that("server and mrinstruments 5", { exp_dat <- try(extract_instruments(outcomes=c("ieu-a-1032", "ebi-a-GCST004634"))) if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 1) +}) +test_that("server and mrinstruments 6", { exp_dat <- try(extract_instruments(outcomes=c(2,100,"ieu-a-1032",104,72,999))) if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 5) +}) +test_that("server and mrinstruments 7", { exp_dat <- try(extract_instruments(outcomes=c(2,100,"ieu-a-1032",104,72,999, "ebi-a-GCST004634"))) if (class(exp_dat) == "try-error") skip("Server issues") expect_true(length(unique(exp_dat$id)) == 6) From 347c9ccb1e04000ad735ffb6f79fba2946372c64 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 14:38:06 +0100 Subject: [PATCH 25/48] Add try() to catch server non-response --- tests/testthat/test_add_metadata.r | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/testthat/test_add_metadata.r b/tests/testthat/test_add_metadata.r index 4c30cce5..4207df4f 100644 --- a/tests/testthat/test_add_metadata.r +++ b/tests/testthat/test_add_metadata.r @@ -23,55 +23,65 @@ skip_on_ci() load(system.file("extdata", "test_add_metadata.RData", package="TwoSampleMR")) test_that("exposure data 1", { - d1 <- d1 %>% add_metadata() + d1 <- try(d1 %>% add_metadata()) + if (class(d1) == "try-error") skip("Server issues") expect_true("units.exposure" %in% names(d1)) }) test_that("exposure data 2", { - d2 <- d2 %>% add_metadata() + d2 <- try(d2 %>% add_metadata()) + if (class(d2) == "try-error") skip("Server issues") expect_true("units.exposure" %in% names(d2)) }) test_that("outcome data 1", { - d3 <- d3 %>% add_metadata() + d3 <- try(d3 %>% add_metadata()) + if (class(d3) == "try-error") skip("Server issues") expect_true("units.outcome" %in% names(d3)) }) test_that("outcome data 2", { - d4 <- d4 %>% add_metadata() + d4 <- try(d4 %>% add_metadata()) + if (class(d4) == "try-error") skip("Server issues") expect_true("units.outcome" %in% names(d4)) }) test_that("dat 2", { - d5 <- d5 %>% add_metadata() + d5 <- try(d5 %>% add_metadata()) + if (class(d5) == "try-error") skip("Server issues") expect_true("units.outcome" %in% names(d5) & "units.exposure" %in% names(d5)) }) test_that("no id1", { d6$id.exposure <- "not a real id" - d6 <- add_metadata(d6) + d6 <- try(add_metadata(d6)) + if (class(d6) == "try-error") skip("Server issues") expect_true(!"units.exposure" %in% names(d6)) }) test_that("no id2", { d7$id.outcome <- "not a real id" - d7 <- add_metadata(d7) + d7 <- try(add_metadata(d7)) + if (class(d7) == "try-error") skip("Server issues") expect_true(!"units.outcome" %in% names(d7)) }) test_that("ukb-d", { - d8 <- add_metadata(d8) + d8 <- try(add_metadata(d8)) + if (class(d8) == "try-error") skip("Server issues") expect_true("units.outcome" %in% names(d8)) }) test_that("bbj-a-1", { - d9 <- d9 %>% add_metadata() + d9 <- try(d9 %>% add_metadata()) + if (class(d9) == "try-error") skip("Server issues") expect_true("samplesize.exposure" %in% names(d9)) expect_true(all(!is.na(d9$samplesize.exposure))) }) test_that("ieu-b-109", { - d10 <- d10 %>% add_metadata() + d10 <- try(d10 %>% add_metadata()) + if (class(d10) == "try-error") skip("Server issues") expect_true("samplesize.exposure" %in% names(d10)) expect_true(all(!is.na(d10$samplesize.exposure))) }) From 3c4962afc9456f1adaf81e0983d0d19cfbaf5e7f Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 14:49:10 +0100 Subject: [PATCH 26/48] Add try() to catch server non-response --- tests/testthat/test_ld.R | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test_ld.R b/tests/testthat/test_ld.R index 82256c82..fb386c1d 100644 --- a/tests/testthat/test_ld.R +++ b/tests/testthat/test_ld.R @@ -6,9 +6,11 @@ skip_on_cran() skip_on_ci() # extract some data -a <- extract_instruments(2, clump=FALSE) -if(length(a) == 0) skip("Server issues") -out <- clump_data(a) +a <- try(extract_instruments("ieu-a-2", clump=FALSE)) +if (class(a) == "try-error") skip("Server issues") +out <- try(clump_data(a)) +if (class(out) == "try-error") skip("Server issues") + test_that("clump", { skip_if_not(exists('a'), "a not created in test above") @@ -21,14 +23,16 @@ test_that("clump", { test_that("matrix", { skip_if_not(exists('out'), "out not created in test above") - b <- ld_matrix(out$SNP) + b <- try(ld_matrix(out$SNP)) + if (inherits(b, "try-error")) skip("Server issues") expect_equal(nrow(b), nrow(out)) expect_equal(ncol(b), nrow(out)) }) test_that("clump multiple", { - a <- extract_instruments(c("ieu-a-2", "ieu-a-1001"), clump=FALSE) + a <- try(extract_instruments(c("ieu-a-2", "ieu-a-1001"), clump=FALSE)) + if (class(a) == "try-error") skip("Server issues") out <- clump_data(a) expect_equal(length(unique(a$id.exposure)), length(unique(out$id.exposure))) }) From bc0e31388770da75ffcc03fad0b11e9832a81b18 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 14:51:23 +0100 Subject: [PATCH 27/48] Add try() to catch server non-response --- tests/testthat/test_mvmr_local.R | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test_mvmr_local.R b/tests/testthat/test_mvmr_local.R index 084559ef..4c2a636c 100644 --- a/tests/testthat/test_mvmr_local.R +++ b/tests/testthat/test_mvmr_local.R @@ -19,7 +19,7 @@ test_that("mv exposure local", { write.table(a1, file=f1, row.names = FALSE, col.names = TRUE, quote = FALSE, sep="\t") write.table(a2, file=f2, row.names = FALSE, col.names = TRUE, quote = FALSE, sep="\t") - exposure_dat <- mv_extract_exposures_local( + exposure_dat <- try(mv_extract_exposures_local( c(f1, f2), sep = "\t", snp_col=c("rsid"), @@ -28,9 +28,11 @@ test_that("mv exposure local", { effect_allele_col=c("ea"), other_allele_col=c("nea"), pval_col=c("p") - ) + )) + if (inherits(exposure_dat, "try-error")) skip("Server issues") + expect_true(nrow(exposure_dat) > 100) - exposure_dat2 <- mv_extract_exposures_local( + exposure_dat2 <- try(mv_extract_exposures_local( list(a1, a2), sep = "\t", snp_col=c("rsid"), @@ -39,8 +41,7 @@ test_that("mv exposure local", { effect_allele_col=c("ea"), other_allele_col=c("nea"), pval_col=c("p") - ) - - expect_true(nrow(exposure_dat) > 100) + )) + if (inherits(exposure_dat2, "try-error")) skip("Server issues") expect_true(all.equal(exposure_dat, exposure_dat2)) }) From 763a1652877c8d3dee3f541977d4e71f219ba13a Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 14:54:23 +0100 Subject: [PATCH 28/48] Split into separate tests --- tests/testthat/test_mvmr.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test_mvmr.R b/tests/testthat/test_mvmr.R index 69b6c3fa..2128d953 100644 --- a/tests/testthat/test_mvmr.R +++ b/tests/testthat/test_mvmr.R @@ -37,12 +37,14 @@ test_that("dat", { }) -test_that("ordering", { +test_that("ordering 1", { lipids1 <- mv_extract_exposures(c("ieu-a-299","ieu-a-300","ieu-a-302")) chd1 <- extract_outcome_data(lipids1$SNP, "ieu-a-7") control1 <- mv_harmonise_data(lipids1, chd1) expect_output(print(mv_multiple(control1))) +}) +test_that("ordering 2", { lipids2 <- mv_extract_exposures(c("ieu-a-302","ieu-a-300","ieu-a-299")) chd2 <- extract_outcome_data(lipids2$SNP, "ieu-a-7") control2 <- mv_harmonise_data(lipids2, chd2) From 3a832dada43d23253c24aa116192886442caac61 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 14:57:17 +0100 Subject: [PATCH 29/48] Add try() to catch server non-response --- tests/testthat/test_mvmr.R | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test_mvmr.R b/tests/testthat/test_mvmr.R index 2128d953..dbc6658c 100644 --- a/tests/testthat/test_mvmr.R +++ b/tests/testthat/test_mvmr.R @@ -6,9 +6,12 @@ skip_if_offline() skip_if_offline(host = "api.opengwas.io") test_that("control", { - lipids <- mv_extract_exposures(c("ieu-a-299","ieu-a-300","ieu-a-302")) - chd <- extract_outcome_data(lipids$SNP, "ieu-a-7") - control <- mv_harmonise_data(lipids, chd) + lipids <- try(mv_extract_exposures(c("ieu-a-299","ieu-a-300","ieu-a-302"))) + if (inherits(lipids, "try-error")) skip("Server issues") + chd <- try(extract_outcome_data(lipids$SNP, "ieu-a-7")) + if (inherits(chd, "try-error")) skip("Server issues") + control <- try(mv_harmonise_data(lipids, chd)) + if (inherits(control, "try-error")) skip("Server issues") expect_output(print(mv_residual(control, intercept=TRUE, instrument_specific=TRUE))) expect_output(print(mv_residual(control, intercept=FALSE, instrument_specific=TRUE))) expect_output(print(mv_residual(control, intercept=TRUE, instrument_specific=FALSE))) @@ -21,9 +24,12 @@ test_that("control", { test_that("dat", { - a <- mv_extract_exposures(c("ukb-b-5238", "ieu-a-1001")) - b <- extract_outcome_data(a$SNP, "ieu-a-297") - dat <- mv_harmonise_data(a, b) + a <- try(mv_extract_exposures(c("ukb-b-5238", "ieu-a-1001"))) + if (inherits(a, "try-error")) skip("Server issues") + b <- try(extract_outcome_data(a$SNP, "ieu-a-297")) + if (inherits(b, "try-error")) skip("Server issues") + dat <- try(mv_harmonise_data(a, b)) + if (inherits(dat, "try-error")) skip("Server issues") expect_output(print(mv_residual(dat, intercept=TRUE, instrument_specific=TRUE))) expect_output(print(mv_residual(dat, intercept=FALSE, instrument_specific=TRUE))) expect_output(print(mv_residual(dat, intercept=TRUE, instrument_specific=FALSE))) @@ -38,15 +44,21 @@ test_that("dat", { test_that("ordering 1", { - lipids1 <- mv_extract_exposures(c("ieu-a-299","ieu-a-300","ieu-a-302")) - chd1 <- extract_outcome_data(lipids1$SNP, "ieu-a-7") - control1 <- mv_harmonise_data(lipids1, chd1) + lipids1 <- try(mv_extract_exposures(c("ieu-a-299","ieu-a-300","ieu-a-302"))) + if (inherits(lipids1, "try-error")) skip("Server issues") + chd1 <- try(extract_outcome_data(lipids1$SNP, "ieu-a-7")) + if (inherits(chd1, "try-error")) skip("Server issues") + control1 <- try(mv_harmonise_data(lipids1, chd1)) + if (inherits(control1, "try-error")) skip("Server issues") expect_output(print(mv_multiple(control1))) }) test_that("ordering 2", { - lipids2 <- mv_extract_exposures(c("ieu-a-302","ieu-a-300","ieu-a-299")) - chd2 <- extract_outcome_data(lipids2$SNP, "ieu-a-7") - control2 <- mv_harmonise_data(lipids2, chd2) + lipids2 <- try(mv_extract_exposures(c("ieu-a-302","ieu-a-300","ieu-a-299"))) + if (inherits(lipids2, "try-error")) skip("Server issues") + chd2 <- try(extract_outcome_data(lipids2$SNP, "ieu-a-7")) + if (inherits(chd2, "try-error")) skip("Server issues") + control2 <- try(mv_harmonise_data(lipids2, chd2)) + if (inherits(control2, "try-error")) skip("Server issues") expect_output(print(mv_multiple(control2))) }) From 4206d2c8cf668ebbe1d40478304afd53a18c2d75 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:05:11 +0100 Subject: [PATCH 30/48] Split into separate tests and use try() --- tests/testthat/test_outcomes.R | 43 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/tests/testthat/test_outcomes.R b/tests/testthat/test_outcomes.R index c7a095cf..da9d672c 100644 --- a/tests/testthat/test_outcomes.R +++ b/tests/testthat/test_outcomes.R @@ -1,36 +1,45 @@ context("outcome") -test_that("outcomes", { +skip_if_offline() +skip_if_offline(host = "api.opengwas.io") +skip_on_cran() +skip_on_ci() - skip_if_offline() - skip_if_offline(host = "api.opengwas.io") - skip_on_cran() - skip_on_ci() +a <- try(extract_instruments("ieu-a-7")) +if(inherits(a, "try-error")) skip("Server issues") - a <- extract_instruments("ieu-a-7") - if(inherits(a, "response")) skip("Server issues") - b <- extract_outcome_data(a$SNP, "ieu-a-2", proxies=FALSE) - if(inherits(b, "response")) skip("Server issues") +test_that("outcomes 1", { + b <- try(extract_outcome_data(a$SNP, "ieu-a-2", proxies=FALSE)) + if(inherits(b, "try-error")) skip("Server issues") expect_true(nrow(b) < 30 & nrow(b) > 15) +}) - b <- extract_outcome_data(a$SNP, "ieu-a-2", proxies=TRUE) - if(inherits(b, "response")) skip("Server issues") +test_that("outcomes 2", { + b <- try(extract_outcome_data(a$SNP, "ieu-a-2", proxies=TRUE)) + if(inherits(b, "try-error")) skip("Server issues") expect_true(nrow(b) > 30 & nrow(b) < nrow(a)) +}) - b <- extract_outcome_data(a$SNP, c("ieu-a-2", "a"), proxies=FALSE) - if(inherits(b, "response")) skip("Server issues") +test_that("outcomes 3", { + b <- try(extract_outcome_data(a$SNP, c("ieu-a-2", "a"), proxies=FALSE)) + if(inherits(b, "try-error")) skip("Server issues") expect_true(nrow(b) < 30 & nrow(b) > 15) +}) +test_that("outcomes 4", { b <- extract_outcome_data(a$SNP, c("ieu-a-2", "a"), proxies=TRUE) - if(inherits(b, "response")) skip("Server issues") + if(inherits(b, "try-error")) skip("Server issues") expect_true(nrow(b) > 30 & nrow(b) < nrow(a)) +}) +test_that("outcomes 5", { b <- extract_outcome_data(a$SNP, c("ieu-a-2", "ieu-a-7"), proxies=FALSE) - if(inherits(b, "response")) skip("Server issues") + if(inherits(b, "try-error")) skip("Server issues") expect_true(nrow(b) > 60) +}) +test_that("outcomes 6", { b <- extract_outcome_data(a$SNP, c("ieu-a-2", "ieu-a-7"), proxies=TRUE) - if(inherits(b, "response")) skip("Server issues") + if(inherits(b, "try-error")) skip("Server issues") expect_true(nrow(b) > 70) - }) From c6286c101925d1bc44934d93cded63e850e75396 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:12:01 +0100 Subject: [PATCH 31/48] Use try() to catch server non-response --- tests/testthat/test_rsq.r | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/tests/testthat/test_rsq.r b/tests/testthat/test_rsq.r index 68417722..407cf201 100644 --- a/tests/testthat/test_rsq.r +++ b/tests/testthat/test_rsq.r @@ -14,8 +14,8 @@ test_that("exposure data 2", { skip_if_offline(host = "api.opengwas.io") skip_on_cran() skip_on_ci() - d <- extract_instruments(c('ieu-a-2', 'ieu-a-7')) - if(inherits(d, "response")) skip("Server issues") + d <- try(extract_instruments(c('ieu-a-2', 'ieu-a-7'))) + if(inherits(d, "try-error")) skip("Server issues") d <- d %>% add_rsq() expect_true("rsq.exposure" %in% names(d)) expect_true("effective_n.exposure" %in% names(d)) @@ -28,8 +28,8 @@ test_that("outcome data 1", { skip_if_offline(host = "api.opengwas.io") skip_on_cran() skip_on_ci() - d <- extract_outcome_data(exposure$SNP, 'ieu-a-2') - if(inherits(d, "response")) skip("Server issues") + d <- try(extract_outcome_data(exposure$SNP, 'ieu-a-2')) + if(inherits(d, "try-error")) skip("Server issues") d <- d %>% add_rsq() expect_true("rsq.outcome" %in% names(d)) expect_true("effective_n.outcome" %in% names(d)) @@ -40,8 +40,8 @@ test_that("outcome data 2", { skip_if_offline(host = "api.opengwas.io") skip_on_cran() skip_on_ci() - d <- extract_outcome_data(exposure$SNP, c('ieu-a-2', 'ieu-a-7')) - if(inherits(d, "response")) skip("Server issues") + d <- try(extract_outcome_data(exposure$SNP, c('ieu-a-2', 'ieu-a-7'))) + if(inherits(d, "try-error")) skip("Server issues") d <- d %>% add_rsq() expect_true("rsq.outcome" %in% names(d)) expect_true("effective_n.outcome" %in% names(d)) @@ -52,8 +52,8 @@ test_that("dat 2", { skip_if_offline(host = "api.opengwas.io") skip_on_cran() skip_on_ci() - d <- make_dat(proxies=FALSE) - if(inherits(d, "response")) skip("Server issues") + d <- try(make_dat(proxies=FALSE)) + if(inherits(d, "try-error")) skip("Server issues") d <- d %>% add_rsq() expect_true("rsq.outcome" %in% names(d) & "rsq.exposure" %in% names(d)) expect_true("effective_n.outcome" %in% names(d) & "effective_n.exposure" %in% names(d)) @@ -65,8 +65,8 @@ test_that("dat ukb-d", { skip_on_cran() skip_on_cran() skip_on_ci() - d <- make_dat(exposure="ukb-d-30710_irnt", proxies=FALSE) - if(inherits(d, "response")) skip("Server issues") + d <- try(make_dat(exposure="ukb-d-30710_irnt", proxies=FALSE)) + if(inherits(d, "try-error")) skip("Server issues") d <- d %>% add_rsq() expect_true("rsq.outcome" %in% names(d) & "rsq.exposure" %in% names(d)) }) @@ -83,9 +83,10 @@ test_that("get_population_allele_frequency", { skip_if_offline(host = "api.opengwas.io") skip_on_cran() skip_on_ci() - d <- extract_instruments("ieu-a-7") - if(inherits(d, "response")) skip("Server issues") - d <- add_metadata(d) + d <- try(extract_instruments("ieu-a-7")) + if(inherits(d, "try-error")) skip("Server issues") + d <- try(add_metadata(d)) + if(inherits(d, "try-error")) skip("Server issues") d$eaf.exposure.controls <- get_population_allele_frequency( af = d$eaf.exposure, prop = d$ncase.exposure / (d$ncase.exposure + d$ncontrol.exposure), @@ -100,9 +101,10 @@ test_that("bbj-a-1", { skip_on_ci() skip_if_offline() skip_if_offline(host = "api.opengwas.io") - d <- extract_instruments('bbj-a-1') - if(inherits(d, "response")) skip("Server issues") - d <- d %>% add_metadata() %>% add_rsq() + d <- try(extract_instruments('bbj-a-1')) + if(inherits(d, "try-error")) skip("Server issues") + d <- try(d %>% add_metadata() %>% add_rsq()) + if(inherits(d, "try-error")) skip("Server issues") expect_true(all(!is.na(d$rsq.exposure))) }) @@ -111,8 +113,8 @@ test_that("bsen vs pn", { skip_if_offline(host = "api.opengwas.io") skip_on_cran() skip_on_ci() - d <- extract_instruments("ieu-a-2") - if(inherits(d, "response")) skip("Server issues") + d <- try(extract_instruments("ieu-a-2")) + if(inherits(d, "try-error")) skip("Server issues") r1 <- get_r_from_bsen(d$beta.exposure, d$se.exposure, d$samplesize.exposure) r2 <- get_r_from_pn(d$pval.exposure, d$samplesize.exposure) expect_true(cor(abs(r1), r2) > 0.99) From 58689aca1f3099a2c937c5af764e59ac959ad004 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:12:26 +0100 Subject: [PATCH 32/48] Delete whitespace --- tests/testthat/test_singlesnp.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/testthat/test_singlesnp.R b/tests/testthat/test_singlesnp.R index 8ce54e3a..bc29c7f1 100644 --- a/tests/testthat/test_singlesnp.R +++ b/tests/testthat/test_singlesnp.R @@ -3,13 +3,11 @@ context("singlesnp") # dat <- make_dat("ieu-a-2", "ieu-a-7") load(system.file("extdata", "test_commondata.RData", package="TwoSampleMR")) - test_that("singlesnp", { w <- mr_singlesnp(dat) expect_true(nrow(w) == sum(dat$mr_keep) + 2) }) - test_that("singlesnp_plot", { w <- mr_singlesnp(dat) p <- mr_forest_plot(w) From 605f0b4c89b1e3aeff96caa3c6839e6778a4ea49 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:12:50 +0100 Subject: [PATCH 33/48] Delete blank lines --- tests/testthat/test_steiger.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/testthat/test_steiger.R b/tests/testthat/test_steiger.R index 7740e952..e75e3cfe 100644 --- a/tests/testthat/test_steiger.R +++ b/tests/testthat/test_steiger.R @@ -3,20 +3,17 @@ context("steiger") # w <- make_dat(2, 7) load(system.file("extdata", "test_commondata.RData", package="TwoSampleMR")) - test_that("directionality", { o <- directionality_test(dat) expect_true(nrow(o) == 1) }) - test_that("directionality cc", { dat$r.outcome <- get_r_from_lor(dat$beta.outcome, dat$eaf.outcome, dat$samplesize.outcome/2, dat$samplesize.outcome/2, 0.1) o <- directionality_test(dat) expect_true(nrow(o) == 1) }) - test_that("steiger filtering", { expect_warning(dat <- steiger_filtering(dat)) expect_true("steiger_pval" %in% names(dat)) From dbe176af3bf3c053d8a9c45a31d35a7f2ab3d0c3 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:14:02 +0100 Subject: [PATCH 34/48] Delete blank line --- tests/testthat/test_eve.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test_eve.R b/tests/testthat/test_eve.R index 92b213f6..9f0623c2 100644 --- a/tests/testthat/test_eve.R +++ b/tests/testthat/test_eve.R @@ -3,7 +3,6 @@ context("eve") # dat <- make_dat("ieu-a-2", "ieu-a-7") %>% add_metadata() load(system.file("extdata", "test_commondata.RData", package="TwoSampleMR")) - test_that("wrapper", { skip_if_not_installed("car") expect_warning(w <- mr_wrapper(dat)) From 7f87268306b3ecb357e2047413cc0fd7a2318f3c Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:14:09 +0100 Subject: [PATCH 35/48] Delete blank lines --- tests/testthat/test_harmonise_edge_cases.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/testthat/test_harmonise_edge_cases.R b/tests/testthat/test_harmonise_edge_cases.R index 987ccf63..e2c7288f 100644 --- a/tests/testthat/test_harmonise_edge_cases.R +++ b/tests/testthat/test_harmonise_edge_cases.R @@ -6,7 +6,6 @@ set.seed(1) old <- options(stringsAsFactors = FALSE) on.exit(options(old), add = TRUE) - df <- data.frame( "SNP" = c("9_69001927_C_T", "9_69459263_A_G", "9_69508544_G_A"), "effect_allele" = c("T", "G", "A"), @@ -47,7 +46,6 @@ df_out <- format_data( samplesize_col = "n" ) - test_that("harmonise_data works when exposure and outcome df are 1 row.", { for (i in seq(1,3)) { result <- harmonise_data( @@ -59,7 +57,6 @@ test_that("harmonise_data works when exposure and outcome df are 1 row.", { } }) - test_that("harmonise_data works when there are no matching SNPs.", { for (i in seq(1,3)) { df_out$SNP <- paste(df_out$SNP, "foo", sep = "_") From 119039d08177885c18a17ee0594c24460ca1ceec Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:16:00 +0100 Subject: [PATCH 36/48] Amend 2 to "ieu-a-2" --- R/moe.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/moe.R b/R/moe.R index 0aeaff11..89dd07d0 100644 --- a/R/moe.R +++ b/R/moe.R @@ -171,7 +171,7 @@ get_rsq <- function(dat) #' \dontrun{ #' # Example of body mass index on coronary heart disease #' # Extract and harmonise data -#' a <- extract_instruments(2) +#' a <- extract_instruments("ieu-a-2") #' b <- extract_outcome_data(a$SNP, 7) #' dat <- harmonise_data(a,b) #' From feb271f0d8240d82213f4a24511bac153a28e180 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:16:06 +0100 Subject: [PATCH 37/48] Formatting --- R/moe.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/moe.R b/R/moe.R index 89dd07d0..b723436f 100644 --- a/R/moe.R +++ b/R/moe.R @@ -173,7 +173,7 @@ get_rsq <- function(dat) #' # Extract and harmonise data #' a <- extract_instruments("ieu-a-2") #' b <- extract_outcome_data(a$SNP, 7) -#' dat <- harmonise_data(a,b) +#' dat <- harmonise_data(a, b) #' #' # Apply all MR methods #' r <- mr_wrapper(dat) From 51500652e80b17e8e4105453efa395311998fe7b Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:16:26 +0100 Subject: [PATCH 38/48] devtools::document() --- man/mr_moe.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/mr_moe.Rd b/man/mr_moe.Rd index bf8348e0..dcd79ac9 100644 --- a/man/mr_moe.Rd +++ b/man/mr_moe.Rd @@ -32,9 +32,9 @@ Note that the mixture of experts has only been trained on datasets with at least \dontrun{ # Example of body mass index on coronary heart disease # Extract and harmonise data -a <- extract_instruments(2) +a <- extract_instruments("ieu-a-2") b <- extract_outcome_data(a$SNP, 7) -dat <- harmonise_data(a,b) +dat <- harmonise_data(a, b) # Apply all MR methods r <- mr_wrapper(dat) From f387eae6cbeefa13134d5b759d4752d122f58467 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:17:38 +0100 Subject: [PATCH 39/48] Amend old names --- tests/testthat/test_plots.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_plots.R b/tests/testthat/test_plots.R index f050778c..c83c15fc 100644 --- a/tests/testthat/test_plots.R +++ b/tests/testthat/test_plots.R @@ -3,7 +3,7 @@ context("plots") load(system.file("extdata", "test_commondata.RData", package="TwoSampleMR")) test_that("scatter plot", { - # dat <- make_dat(2,7) + # dat <- make_dat("ieu-a-2", "ieu-a-7") m <- mr(dat, method_list="mr_ivw") p <- mr_scatter_plot(m, dat) expect_true(is.list(p)) From 63cb3df854b1aad3936e8ef2931effd8880062fa Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:18:41 +0100 Subject: [PATCH 40/48] Amend old names --- tests/testthat/test_steiger.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_steiger.R b/tests/testthat/test_steiger.R index e75e3cfe..582dabf4 100644 --- a/tests/testthat/test_steiger.R +++ b/tests/testthat/test_steiger.R @@ -1,6 +1,6 @@ context("steiger") -# w <- make_dat(2, 7) +# dat <- make_dat("ieu-a-2", "ieu-a-7") load(system.file("extdata", "test_commondata.RData", package="TwoSampleMR")) test_that("directionality", { From d397b7229cf56327a403dbaa14eea7e0fca0e92e Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:21:34 +0100 Subject: [PATCH 41/48] Add tests bullet --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 2db51dc9..add27267 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ * Bumped version of **roxygen2** for creating package documentation * Update the earliest version of R in the `R CMD check` GitHub Actions workflow to be 4.3.2. This is because the **meta** dependency depends on **lme4**, and the recent 1.1-35.4 release of **lme4** requires **Matrix** 1.6-2 which was released a few days after R 4.3.2. +* Made package tests more robust to non-response from the OpenGWAS API # TwoSampleMR v0.6.4 From d86623b71f7a9a288ebca69a20f8a5e6eb360fd2 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:21:55 +0100 Subject: [PATCH 42/48] Add release date --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index add27267..01fd5e3f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # TwoSampleMR v0.6.5 -(Release date: 2024-##-##) +(Release date: 2024-06-30) * Bumped version of **roxygen2** for creating package documentation * Update the earliest version of R in the `R CMD check` GitHub Actions workflow to be 4.3.2. This is because the **meta** dependency depends on **lme4**, and the recent 1.1-35.4 release of **lme4** requires **Matrix** 1.6-2 which was released a few days after R 4.3.2. From 2739d3e8bcc68e6d0d51df320b241eab05a4645c Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:33:32 +0100 Subject: [PATCH 43/48] Delete blank line --- NEWS.md | 1 - 1 file changed, 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 01fd5e3f..eb289b4f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,7 +11,6 @@ (Release date: 2024-06-05) * Update installation instructions in README.md - * Fixed a bug in which the wrong indels recoding function was called (thanks @ruochiz) # TwoSampleMR v0.6.3 From c9de9c32756863584a3dc70bed3d01595e7703fa Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:46:43 +0100 Subject: [PATCH 44/48] Update test-coverage.yaml --- .github/workflows/test-coverage.yaml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 8b5140c2..ca096091 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -24,7 +24,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::covr + extra-packages: any::covr, any::xml2 needs: coverage - name: Create and populate .Renviron file @@ -34,15 +34,22 @@ jobs: - name: Test coverage run: | - token <- Sys.getenv("CODECOV_TOKEN", "") - covr::codecov( + cov <- covr::package_coverage( quiet = FALSE, clean = FALSE, - install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package"), - token = if (token != "") token + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") ) + covr::to_cobertura(cov) shell: Rscript {0} + - uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} + file: ./cobertura.xml + plugin: noop + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} + - name: Show testthat output if: always() run: | From 7408edd4e3d1713576d7f6ab53389fdced4138b3 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 15:54:25 +0100 Subject: [PATCH 45/48] Delete skip_on_ci() --- tests/testthat/test_add_metadata.r | 1 - tests/testthat/test_instruments.R | 1 - tests/testthat/test_ld.R | 1 - tests/testthat/test_mvmr.R | 1 - tests/testthat/test_mvmr_local.R | 1 - tests/testthat/test_otherformats.R | 1 - tests/testthat/test_outcomes.R | 1 - tests/testthat/test_rsq.r | 9 --------- 8 files changed, 16 deletions(-) diff --git a/tests/testthat/test_add_metadata.r b/tests/testthat/test_add_metadata.r index 4207df4f..7aa71c54 100644 --- a/tests/testthat/test_add_metadata.r +++ b/tests/testthat/test_add_metadata.r @@ -3,7 +3,6 @@ context("add metadata") skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() -skip_on_ci() # get required data # d1 <- extract_instruments('ieu-a-2') diff --git a/tests/testthat/test_instruments.R b/tests/testthat/test_instruments.R index 4bde502e..0d2a5c06 100644 --- a/tests/testthat/test_instruments.R +++ b/tests/testthat/test_instruments.R @@ -3,7 +3,6 @@ context("Instruments") skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() -skip_on_ci() test_that("server and mrinstruments 1", { # no no diff --git a/tests/testthat/test_ld.R b/tests/testthat/test_ld.R index fb386c1d..c763218c 100644 --- a/tests/testthat/test_ld.R +++ b/tests/testthat/test_ld.R @@ -3,7 +3,6 @@ context("ld") skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() -skip_on_ci() # extract some data a <- try(extract_instruments("ieu-a-2", clump=FALSE)) diff --git a/tests/testthat/test_mvmr.R b/tests/testthat/test_mvmr.R index dbc6658c..b74ee7e1 100644 --- a/tests/testthat/test_mvmr.R +++ b/tests/testthat/test_mvmr.R @@ -1,6 +1,5 @@ context("mvmr") -skip_on_ci() skip_on_cran() skip_if_offline() skip_if_offline(host = "api.opengwas.io") diff --git a/tests/testthat/test_mvmr_local.R b/tests/testthat/test_mvmr_local.R index 4c2a636c..4446aadb 100644 --- a/tests/testthat/test_mvmr_local.R +++ b/tests/testthat/test_mvmr_local.R @@ -12,7 +12,6 @@ load(system.file("extdata", "test_add_mvmr_local.RData", package="TwoSampleMR")) test_that("mv exposure local", { skip_if_offline() skip_if_offline(host = "api.opengwas.io") - skip_on_ci() skip_on_cran() f1 <- tempfile() f2 <- tempfile() diff --git a/tests/testthat/test_otherformats.R b/tests/testthat/test_otherformats.R index 28187514..6f5e0e12 100644 --- a/tests/testthat/test_otherformats.R +++ b/tests/testthat/test_otherformats.R @@ -13,7 +13,6 @@ test_that("MRInput", { test_that("MRInput with cor", { skip_on_cran() - skip_on_ci() skip_if_offline() skip_if_offline(host = "api.opengwas.io") expect_warning(w <- dat_to_MRInput(dat, get_correlations=TRUE)[[1]]) diff --git a/tests/testthat/test_outcomes.R b/tests/testthat/test_outcomes.R index da9d672c..5290503b 100644 --- a/tests/testthat/test_outcomes.R +++ b/tests/testthat/test_outcomes.R @@ -3,7 +3,6 @@ context("outcome") skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() -skip_on_ci() a <- try(extract_instruments("ieu-a-7")) if(inherits(a, "try-error")) skip("Server issues") diff --git a/tests/testthat/test_rsq.r b/tests/testthat/test_rsq.r index 407cf201..b430a46a 100644 --- a/tests/testthat/test_rsq.r +++ b/tests/testthat/test_rsq.r @@ -13,7 +13,6 @@ test_that("exposure data 2", { skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() - skip_on_ci() d <- try(extract_instruments(c('ieu-a-2', 'ieu-a-7'))) if(inherits(d, "try-error")) skip("Server issues") d <- d %>% add_rsq() @@ -27,7 +26,6 @@ test_that("outcome data 1", { skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() - skip_on_ci() d <- try(extract_outcome_data(exposure$SNP, 'ieu-a-2')) if(inherits(d, "try-error")) skip("Server issues") d <- d %>% add_rsq() @@ -39,7 +37,6 @@ test_that("outcome data 2", { skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() - skip_on_ci() d <- try(extract_outcome_data(exposure$SNP, c('ieu-a-2', 'ieu-a-7'))) if(inherits(d, "try-error")) skip("Server issues") d <- d %>% add_rsq() @@ -51,7 +48,6 @@ test_that("dat 2", { skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() - skip_on_ci() d <- try(make_dat(proxies=FALSE)) if(inherits(d, "try-error")) skip("Server issues") d <- d %>% add_rsq() @@ -63,8 +59,6 @@ test_that("dat ukb-d", { skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() - skip_on_cran() - skip_on_ci() d <- try(make_dat(exposure="ukb-d-30710_irnt", proxies=FALSE)) if(inherits(d, "try-error")) skip("Server issues") d <- d %>% add_rsq() @@ -82,7 +76,6 @@ test_that("get_population_allele_frequency", { skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() - skip_on_ci() d <- try(extract_instruments("ieu-a-7")) if(inherits(d, "try-error")) skip("Server issues") d <- try(add_metadata(d)) @@ -98,7 +91,6 @@ test_that("get_population_allele_frequency", { test_that("bbj-a-1", { skip_on_cran() - skip_on_ci() skip_if_offline() skip_if_offline(host = "api.opengwas.io") d <- try(extract_instruments('bbj-a-1')) @@ -112,7 +104,6 @@ test_that("bsen vs pn", { skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() - skip_on_ci() d <- try(extract_instruments("ieu-a-2")) if(inherits(d, "try-error")) skip("Server issues") r1 <- get_r_from_bsen(d$beta.exposure, d$se.exposure, d$samplesize.exposure) From 1d5c620b53567b3a31234a5274ef608ae0b72ffa Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 16:00:47 +0100 Subject: [PATCH 46/48] Add try() to catch server non-response --- tests/testthat/test_otherformats.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test_otherformats.R b/tests/testthat/test_otherformats.R index 6f5e0e12..c469bd75 100644 --- a/tests/testthat/test_otherformats.R +++ b/tests/testthat/test_otherformats.R @@ -15,7 +15,8 @@ test_that("MRInput with cor", { skip_on_cran() skip_if_offline() skip_if_offline(host = "api.opengwas.io") - expect_warning(w <- dat_to_MRInput(dat, get_correlations=TRUE)[[1]]) + w <- try(dat_to_MRInput(dat, get_correlations=TRUE)[[1]]) + if (inherits(w, "try-error")) skip("Server issues") expect_true(nrow(w@correlation) == length(w@betaX)) }) From 433e7c46c451013e44e5c65073ea9985742ef730 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 16:01:00 +0100 Subject: [PATCH 47/48] Add try() to catch server non-response --- tests/testthat/test_rsq.r | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test_rsq.r b/tests/testthat/test_rsq.r index b430a46a..734649b7 100644 --- a/tests/testthat/test_rsq.r +++ b/tests/testthat/test_rsq.r @@ -28,7 +28,8 @@ test_that("outcome data 1", { skip_on_cran() d <- try(extract_outcome_data(exposure$SNP, 'ieu-a-2')) if(inherits(d, "try-error")) skip("Server issues") - d <- d %>% add_rsq() + d <- try(d %>% add_rsq()) + if (inherits(d, "try-error")) skip("Server issues") expect_true("rsq.outcome" %in% names(d)) expect_true("effective_n.outcome" %in% names(d)) }) @@ -39,7 +40,8 @@ test_that("outcome data 2", { skip_on_cran() d <- try(extract_outcome_data(exposure$SNP, c('ieu-a-2', 'ieu-a-7'))) if(inherits(d, "try-error")) skip("Server issues") - d <- d %>% add_rsq() + d <- try(d %>% add_rsq()) + if(inherits(d, "try-error")) skip("Server issues") expect_true("rsq.outcome" %in% names(d)) expect_true("effective_n.outcome" %in% names(d)) }) From 74046aa8720ff7c9d4f7cdc340442a558a07c37e Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 30 Jun 2024 16:14:29 +0100 Subject: [PATCH 48/48] Skip 2 tests on CI --- tests/testthat/test_rsq.r | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test_rsq.r b/tests/testthat/test_rsq.r index 734649b7..89d62984 100644 --- a/tests/testthat/test_rsq.r +++ b/tests/testthat/test_rsq.r @@ -26,6 +26,7 @@ test_that("outcome data 1", { skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() + skip_on_ci() d <- try(extract_outcome_data(exposure$SNP, 'ieu-a-2')) if(inherits(d, "try-error")) skip("Server issues") d <- try(d %>% add_rsq()) @@ -38,6 +39,7 @@ test_that("outcome data 2", { skip_if_offline() skip_if_offline(host = "api.opengwas.io") skip_on_cran() + skip_on_ci() d <- try(extract_outcome_data(exposure$SNP, c('ieu-a-2', 'ieu-a-7'))) if(inherits(d, "try-error")) skip("Server issues") d <- try(d %>% add_rsq())