From 40d4318625722e6b78e344e65729544669b23a16 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 09:31:11 +0000 Subject: [PATCH 01/16] Specify remote for mr.raps mr.raps was archived from CRAN on 2025-03-01 https://cran.r-project.org/package=mr.raps --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 6325e38f..c7da8cfa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -64,6 +64,7 @@ Remotes: gqi/MRMix, mrcieu/MRInstruments, MRPRESSO=rondolab/MR-PRESSO, + qingyuanzhao/mr.raps, WSpiller/RadialMR Encoding: UTF-8 Roxygen: list(markdown = TRUE) From 3cbe6054c10d6e5f30c51a0a6b4b2da84263d3fc Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 09:38:54 +0000 Subject: [PATCH 02/16] Bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c7da8cfa..59963100 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: TwoSampleMR Title: Two Sample MR Functions and Interface to MRC Integrative Epidemiology Unit OpenGWAS Database -Version: 0.6.9 +Version: 0.6.10 Authors@R: c( person("Gibran", "Hemani", , "g.hemani@bristol.ac.uk", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0920-1055")), From 4948af7a403f2566d78d71673eabeffcff47ec4e Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 09:46:21 +0000 Subject: [PATCH 03/16] Add Additional_repositories field --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 59963100..fd1a80d1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -66,6 +66,7 @@ Remotes: MRPRESSO=rondolab/MR-PRESSO, qingyuanzhao/mr.raps, WSpiller/RadialMR +Additional_repositories: https://mrcieu.r-universe.dev Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 From f65dadb58ab5051cce3bbff2d91ac2edd545f772 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 09:46:37 +0000 Subject: [PATCH 04/16] usethis::use_tidy_description() --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index fd1a80d1..f7f95ada 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,6 @@ Package: TwoSampleMR -Title: Two Sample MR Functions and Interface to MRC Integrative Epidemiology Unit OpenGWAS Database +Title: Two Sample MR Functions and Interface to MRC Integrative + Epidemiology Unit OpenGWAS Database Version: 0.6.10 Authors@R: c( person("Gibran", "Hemani", , "g.hemani@bristol.ac.uk", role = c("aut", "cre"), From a0daa944c31121110248282453b8c206c76425fa Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 10:18:38 +0000 Subject: [PATCH 05/16] Add test for mr() with default options --- tests/testthat/test_mr.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/testthat/test_mr.R diff --git a/tests/testthat/test_mr.R b/tests/testthat/test_mr.R new file mode 100644 index 00000000..9aadfb6b --- /dev/null +++ b/tests/testthat/test_mr.R @@ -0,0 +1,15 @@ +# Test mr() + +# dat <- make_dat("ieu-a-2", "ieu-a-7") +load(system.file("extdata", "test_commondata.RData", package="TwoSampleMR")) + +test_that("Test mr(): MR Egger, Weighted median, Inverse variance weighted, Simple mode, Weighted mode", { + res <- mr(dat) + expect_equal(nrow(res), 5L) + expect_equal(ncol(res), 9L) + expect_equal(res[1, "b"], 0.5025, tolerance = 1e-4) + expect_equal(res[2, "b"], 0.3870, tolerance = 1e-4) + expect_equal(res[3, "b"], 0.4459, tolerance = 1e-4) + expect_equal(res[4, "b"], 0.3402, tolerance = 1e-4) + expect_equal(res[5, "b"], 0.3791, tolerance = 1e-4) +}) From e54aa157f7a379a47849e38ea431a9f21539e052 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 10:18:57 +0000 Subject: [PATCH 06/16] Add test for using mr.raps via mr_raps() --- tests/testthat/test_mr.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/testthat/test_mr.R b/tests/testthat/test_mr.R index 9aadfb6b..348c6da2 100644 --- a/tests/testthat/test_mr.R +++ b/tests/testthat/test_mr.R @@ -13,3 +13,10 @@ test_that("Test mr(): MR Egger, Weighted median, Inverse variance weighted, Simp expect_equal(res[4, "b"], 0.3402, tolerance = 1e-4) expect_equal(res[5, "b"], 0.3791, tolerance = 1e-4) }) + +test_that("mr.raps", { + res2 <- suppressWarnings(mr(dat, method_list = "mr_raps")) + expect_equal(nrow(res2), 1L) + expect_equal(ncol(res2), 9L) + expect_equal(res2[1, "b"], 0.4647, tolerance = 1e-4) +}) From d6c1ac80dd83cf5c37d1ab27cf885967170db0db Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 10:33:50 +0000 Subject: [PATCH 07/16] Add tests for 3 mr.raps() arguments --- tests/testthat/test_mr.R | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/testthat/test_mr.R b/tests/testthat/test_mr.R index 348c6da2..2cb0f217 100644 --- a/tests/testthat/test_mr.R +++ b/tests/testthat/test_mr.R @@ -20,3 +20,30 @@ test_that("mr.raps", { expect_equal(ncol(res2), 9L) expect_equal(res2[1, "b"], 0.4647, tolerance = 1e-4) }) + +test_that("mr.raps over.dispersion option", { + params <- default_parameters() + params$over.dispersion <- FALSE + res3 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params)) + expect_equal(nrow(res3), 1L) + expect_equal(ncol(res3), 9L) + expect_equal(res3[1, "b"], 0.4682, tolerance = 1e-4) +}) + +test_that("mr.raps loss.function option", { + params <- default_parameters() + params$loss.function <- "tukey" + res4 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params)) + expect_equal(nrow(res4), 1L) + expect_equal(ncol(res4), 9L) + expect_equal(res4[1, "b"], 0.4788, tolerance = 1e-4) +}) + +test_that("mr.raps shrinkage option", { + params <- default_parameters() + params$shrinkage <- TRUE + res5 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params)) + expect_equal(nrow(res5), 1L) + expect_equal(ncol(res5), 9L) + expect_equal(res5[1, "b"], 0.4647, tolerance = 1e-4) +}) From 9d7ea26a949ce2527be3f8636980937b50a73e54 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 10:34:29 +0000 Subject: [PATCH 08/16] Add shrinkage to helpfile text --- R/mr.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/mr.R b/R/mr.R index b50be4b0..17bd8dd3 100644 --- a/R/mr.R +++ b/R/mr.R @@ -232,7 +232,7 @@ mr_method_list <- function() #' List of parameters for use with MR functions #' -#' The default is `list(test_dist = "z", nboot = 1000, Cov = 0, penk = 20, phi = 1, alpha = 0.05, Qthresh = 0.05, over.dispersion = TRUE, loss.function = "huber")`. +#' The default is `list(test_dist = "z", nboot = 1000, Cov = 0, penk = 20, phi = 1, alpha = 0.05, Qthresh = 0.05, over.dispersion = TRUE, loss.function = "huber", shrinkage = FALSE)`. #' #' @export default_parameters <- function() @@ -246,8 +246,8 @@ default_parameters <- function() alpha = 0.05, Qthresh = 0.05, over.dispersion = TRUE, - loss.function = "huber", - shrinkage = FALSE + loss.function = "huber", + shrinkage = FALSE ) } From f03610723804ad8b9904eed6dfb8dc87bf710b01 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 10:34:40 +0000 Subject: [PATCH 09/16] devtools::document() --- man/default_parameters.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/default_parameters.Rd b/man/default_parameters.Rd index 5f838a25..55201268 100644 --- a/man/default_parameters.Rd +++ b/man/default_parameters.Rd @@ -7,5 +7,5 @@ default_parameters() } \description{ -The default is \code{list(test_dist = "z", nboot = 1000, Cov = 0, penk = 20, phi = 1, alpha = 0.05, Qthresh = 0.05, over.dispersion = TRUE, loss.function = "huber")}. +The default is \code{list(test_dist = "z", nboot = 1000, Cov = 0, penk = 20, phi = 1, alpha = 0.05, Qthresh = 0.05, over.dispersion = TRUE, loss.function = "huber", shrinkage = FALSE)}. } From 2e5e17851b91c71ff454e8e522cc9e3903cbe0e1 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 09:52:09 +0000 Subject: [PATCH 10/16] Move mr.raps to Suggests list --- DESCRIPTION | 2 +- R/mr.R | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f7f95ada..ac471654 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,7 +41,6 @@ Imports: magrittr, MASS, meta, - mr.raps, MRMix, MRPRESSO, pbapply, @@ -55,6 +54,7 @@ Suggests: car, markdown, MendelianRandomization, + mr.raps, MRInstruments, randomForest, testthat, diff --git a/R/mr.R b/R/mr.R index 17bd8dd3..31baab3f 100644 --- a/R/mr.R +++ b/R/mr.R @@ -12,6 +12,13 @@ #' } mr <- function(dat, parameters=default_parameters(), method_list=subset(mr_method_list(), use_by_default)$obj) { + + if ("mr_raps" %in% method_list) { + if (!(requireNamespace("mr.raps", quietly = TRUE))) { + stop("You can install mr.raps with install.packages('mr.raps', repos = c('https://mrcieu.r-universe.dev', 'https://cloud.r-project.org'))") + } + } + mr_tab <- plyr::ddply(dat, c("id.exposure", "id.outcome"), function(x1) { # message("Performing MR analysis of '", x1$id.exposure[1], "' on '", x18WII58$id.outcome[1], "'") @@ -974,6 +981,10 @@ mr_ivw_fe <- function(b_exp, b_out, se_exp, se_out, parameters=default_parameter #' @export mr_raps <- function(b_exp, b_out, se_exp, se_out, parameters = default_parameters()) { + if (!(requireNamespace("mr.raps", quietly = TRUE))) { + stop("You can install mr.raps with install.packages('mr.raps', repos = c('https://mrcieu.r-universe.dev', 'https://cloud.r-project.org'))") + } + data <- data.frame(beta.exposure = b_exp, beta.outcome = b_out, se.exposure = se_exp, From 5f9a7131cb651e1a8f868b793da7e5dcca854aa9 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 10:50:00 +0000 Subject: [PATCH 11/16] Add rsnps to Suggest list Until mr.raps is fixed --- DESCRIPTION | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ac471654..84e2dd04 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -57,6 +57,7 @@ Suggests: mr.raps, MRInstruments, randomForest, + rsnps, testthat, tidyr VignetteBuilder: @@ -66,7 +67,8 @@ Remotes: mrcieu/MRInstruments, MRPRESSO=rondolab/MR-PRESSO, qingyuanzhao/mr.raps, - WSpiller/RadialMR + WSpiller/RadialMR, + ropensci/rsnps Additional_repositories: https://mrcieu.r-universe.dev Encoding: UTF-8 Roxygen: list(markdown = TRUE) From 1a27a4fba34955b47e5b84fa4e4028d511717b63 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 09:39:00 +0000 Subject: [PATCH 12/16] Update NEWS.md --- NEWS.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/NEWS.md b/NEWS.md index 8d8fd519..2c65ffaa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,15 @@ +# TwoSampleMR v0.6.10 + +(Release date 2025-03-03) + +* The **mr.raps** package was archived from CRAN on 2025-03-01. +A later version (0.4.1) than was on CRAN (0.2) is available from its GitHub repo . +We believe this later version still works as expected in **TwoSampleMR**. +However, version 0.4.1 depends upon **rsnps** package which is itself now only available on its GitHub repo. +Hence, we have added both packages to our and added that to the `Additional_repositories` field in the DESCRIPTION. +We have also moved mr.raps to the soft dependency list (Suggests list) and added rsnps to our Suggests list with a remote. +* Fix to `default_parameters()` helpfile + # TwoSampleMR v0.6.9 (Release date 2025-02-05) From 33fe25eae94d1bfb4083f89843498a61c9e15815 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 12:09:46 +0000 Subject: [PATCH 13/16] Amend tolerance --- tests/testthat/test_mr.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test_mr.R b/tests/testthat/test_mr.R index 2cb0f217..1f51e612 100644 --- a/tests/testthat/test_mr.R +++ b/tests/testthat/test_mr.R @@ -7,18 +7,18 @@ test_that("Test mr(): MR Egger, Weighted median, Inverse variance weighted, Simp res <- mr(dat) expect_equal(nrow(res), 5L) expect_equal(ncol(res), 9L) - expect_equal(res[1, "b"], 0.5025, tolerance = 1e-4) - expect_equal(res[2, "b"], 0.3870, tolerance = 1e-4) - expect_equal(res[3, "b"], 0.4459, tolerance = 1e-4) - expect_equal(res[4, "b"], 0.3402, tolerance = 1e-4) - expect_equal(res[5, "b"], 0.3791, tolerance = 1e-4) + expect_equal(res[1, "b"], 0.5025, tolerance = 1e-3) + expect_equal(res[2, "b"], 0.3870, tolerance = 1e-3) + expect_equal(res[3, "b"], 0.4459, tolerance = 1e-3) + expect_equal(res[4, "b"], 0.3402, tolerance = 1e-3) + expect_equal(res[5, "b"], 0.3791, tolerance = 1e-3) }) test_that("mr.raps", { res2 <- suppressWarnings(mr(dat, method_list = "mr_raps")) expect_equal(nrow(res2), 1L) expect_equal(ncol(res2), 9L) - expect_equal(res2[1, "b"], 0.4647, tolerance = 1e-4) + expect_equal(res2[1, "b"], 0.4647, tolerance = 1e-3) }) test_that("mr.raps over.dispersion option", { @@ -27,7 +27,7 @@ test_that("mr.raps over.dispersion option", { res3 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params)) expect_equal(nrow(res3), 1L) expect_equal(ncol(res3), 9L) - expect_equal(res3[1, "b"], 0.4682, tolerance = 1e-4) + expect_equal(res3[1, "b"], 0.4682, tolerance = 1e-3) }) test_that("mr.raps loss.function option", { @@ -36,7 +36,7 @@ test_that("mr.raps loss.function option", { res4 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params)) expect_equal(nrow(res4), 1L) expect_equal(ncol(res4), 9L) - expect_equal(res4[1, "b"], 0.4788, tolerance = 1e-4) + expect_equal(res4[1, "b"], 0.4788, tolerance = 1e-3) }) test_that("mr.raps shrinkage option", { @@ -45,5 +45,5 @@ test_that("mr.raps shrinkage option", { res5 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params)) expect_equal(nrow(res5), 1L) expect_equal(ncol(res5), 9L) - expect_equal(res5[1, "b"], 0.4647, tolerance = 1e-4) + expect_equal(res5[1, "b"], 0.4647, tolerance = 1e-3) }) From ff30bed9b55384a19567a1aef2787080ab58709e Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 12:32:13 +0000 Subject: [PATCH 14/16] Update NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 2c65ffaa..120b2b4c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,7 +7,7 @@ A later version (0.4.1) than was on CRAN (0.2) is available from its GitHub repo We believe this later version still works as expected in **TwoSampleMR**. However, version 0.4.1 depends upon **rsnps** package which is itself now only available on its GitHub repo. Hence, we have added both packages to our and added that to the `Additional_repositories` field in the DESCRIPTION. -We have also moved mr.raps to the soft dependency list (Suggests list) and added rsnps to our Suggests list with a remote. +We have also moved mr.raps to the soft dependency list (Suggests list) and added rsnps to our Suggests list, both with remotes. * Fix to `default_parameters()` helpfile # TwoSampleMR v0.6.9 From 7fb5905de0b06b1b0fac17ae69ae16a432123e77 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 12:41:27 +0000 Subject: [PATCH 15/16] Amend tolerance --- tests/testthat/test_mr.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_mr.R b/tests/testthat/test_mr.R index 1f51e612..47aacf7d 100644 --- a/tests/testthat/test_mr.R +++ b/tests/testthat/test_mr.R @@ -11,7 +11,7 @@ test_that("Test mr(): MR Egger, Weighted median, Inverse variance weighted, Simp expect_equal(res[2, "b"], 0.3870, tolerance = 1e-3) expect_equal(res[3, "b"], 0.4459, tolerance = 1e-3) expect_equal(res[4, "b"], 0.3402, tolerance = 1e-3) - expect_equal(res[5, "b"], 0.3791, tolerance = 1e-3) + expect_equal(res[5, "b"], 0.3791, tolerance = 1e-1) }) test_that("mr.raps", { From 7a8ed537c5abf7206351772339aa6d15e244c115 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Mon, 3 Mar 2025 10:52:09 +0000 Subject: [PATCH 16/16] Update check-full.yaml Revert "Update check-full.yaml" This reverts commit fdd4e2e8710b70ce5746025f6e8fc7499f0cee0c.