From 26f58d9575383c10de7e8a88dc2800c4b06cd7d7 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Wed, 25 Mar 2026 07:35:34 +0000 Subject: [PATCH 1/6] Add improved check of unsupported methods especially MR-PRESSO --- R/mr.R | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/R/mr.R b/R/mr.R index ced8a4af..0988b2aa 100644 --- a/R/mr.R +++ b/R/mr.R @@ -15,6 +15,25 @@ mr <- function( parameters = default_parameters(), method_list = subset(mr_method_list(), use_by_default)$obj ) { + supported_methods <- mr_method_list()$obj + unsupported <- setdiff(method_list, supported_methods) + if (length(unsupported) > 0) { + msg <- paste0( + "The following methods are not supported by mr(): ", + paste(unsupported, collapse = ", "), + ".\nSupported methods are: ", + paste(supported_methods, collapse = ", "), + "." + ) + if (any(unsupported %in% c("mr_presso", "run_mr_presso"))) { + msg <- paste0( + msg, + "\nFor MR-PRESSO, please use run_mr_presso() instead of mr()." + ) + } + stop(msg) + } + if ("mr_raps" %in% method_list) { if (!(requireNamespace("mr.raps", quietly = TRUE))) { stop( From ff76256315baca7d237fd29ee156e65f2a95d0a6 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Wed, 25 Mar 2026 07:36:52 +0000 Subject: [PATCH 2/6] Add test for mr() error if mr_presso or run_mr_presso included in list --- tests/testthat/test_mr.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/testthat/test_mr.R b/tests/testthat/test_mr.R index 6cf2d0b9..cb90ac6c 100644 --- a/tests/testthat/test_mr.R +++ b/tests/testthat/test_mr.R @@ -69,3 +69,11 @@ test_that("mr_grip() not from mr()", { expect_equal(tst$se.adj, 0.16389, tol = 1e-4) expect_equal(tst$nsnp, 79L) }) + +test_that("Including MR-PRESSO in the list", { + expect_error(res7 <- mr(dat, method_list = c("mr_presso"))) +}) + +test_that("Including MR-PRESSO in the list", { + expect_error(res8 <- mr(dat, method_list = c("run_mr_presso"))) +}) From 47d187626a63d4dc6cd1d89e6693730866c81845 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Wed, 25 Mar 2026 07:36:59 +0000 Subject: [PATCH 3/6] Bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 17f04de1..ee8b0ec0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: TwoSampleMR Title: Two Sample MR Functions and Interface to MRC Integrative Epidemiology Unit OpenGWAS Database -Version: 0.7.0 +Version: 0.7.1 Authors@R: c( person("Gibran", "Hemani", , "g.hemani@bristol.ac.uk", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0920-1055")), From 28ea447a2516116c8f98722f66f6ebc58264f0bf Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Wed, 25 Mar 2026 07:49:52 +0000 Subject: [PATCH 4/6] Add warning if mr_wald_ratio passed more than one genotype row --- R/mr.R | 8 ++++++++ tests/testthat/test_mr.R | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/R/mr.R b/R/mr.R index 0988b2aa..3f1b88a7 100644 --- a/R/mr.R +++ b/R/mr.R @@ -330,6 +330,14 @@ default_parameters <- function() { #' } mr_wald_ratio <- function(b_exp, b_out, se_exp, se_out, parameters) { if (length(b_exp) > 1) { + warning( + "mr_wald_ratio requires exactly one SNP, but ", + length(b_exp), + " were provided. ", + "Use a method that supports multiple SNPs (e.g. mr_ivw) or subset your data to a single SNP. ", + "Returning NA.", + call. = FALSE + ) return(list(b = NA, se = NA, pval = NA, nsnp = NA)) } b <- b_out / b_exp diff --git a/tests/testthat/test_mr.R b/tests/testthat/test_mr.R index cb90ac6c..3c2c51f7 100644 --- a/tests/testthat/test_mr.R +++ b/tests/testthat/test_mr.R @@ -77,3 +77,16 @@ test_that("Including MR-PRESSO in the list", { test_that("Including MR-PRESSO in the list", { expect_error(res8 <- mr(dat, method_list = c("run_mr_presso"))) }) + +test_that("mr_wald_ratio works with a single SNP", { + res9 <- mr(dat[1, ], method_list = "mr_wald_ratio") + expect_equal(nrow(res9), 1L) +}) + +test_that("mr_wald_ratio warns with multiple SNPs and returns 0 rows", { + res10 <- expect_warning( + mr(dat, method_list = "mr_wald_ratio"), + "mr_wald_ratio requires exactly one SNP" + ) + expect_equal(nrow(res10), 0L) +}) From 7549c311ebb9a8929d13efb3fdca2c369ce4b22e Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Wed, 25 Mar 2026 07:53:21 +0000 Subject: [PATCH 5/6] Amend expect_warning() calls --- tests/testthat/test_eve.R | 2 +- tests/testthat/test_otherformats.R | 2 +- tests/testthat/test_plots.R | 8 ++++---- tests/testthat/test_steiger.R | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test_eve.R b/tests/testthat/test_eve.R index 01a8a7d5..c890972b 100644 --- a/tests/testthat/test_eve.R +++ b/tests/testthat/test_eve.R @@ -5,7 +5,7 @@ load(system.file("extdata", "test_commondata.RData", package = "TwoSampleMR")) test_that("wrapper", { skip_if_not_installed("car") - expect_warning(w <- mr_wrapper(dat)) + w <- expect_warning(mr_wrapper(dat)) expect_true(length(w) == 1) expect_true(length(names(w[[1]])) == 5) }) diff --git a/tests/testthat/test_otherformats.R b/tests/testthat/test_otherformats.R index 95b1272a..63d6c2db 100644 --- a/tests/testthat/test_otherformats.R +++ b/tests/testthat/test_otherformats.R @@ -30,7 +30,7 @@ test_that("MRInput with cor", { test_that("mrpresso", { - expect_warning(w <- run_mr_presso(dat)) + w <- expect_warning(run_mr_presso(dat)) expect_true(length(w) == 1) expect_true(class(w) == "list") expect_true(class(w[[1]]) == "list") diff --git a/tests/testthat/test_plots.R b/tests/testthat/test_plots.R index 522f5918..00a1fd34 100644 --- a/tests/testthat/test_plots.R +++ b/tests/testthat/test_plots.R @@ -55,8 +55,8 @@ rm(list = ls()) load(system.file("extdata", "forestplot_1_to_many_data.RData", package = "TwoSampleMR")) test_that("Forest plot 1 to many", { - expect_warning( - p8 <- forest_plot_1_to_many( + p8 <- expect_warning( + forest_plot_1_to_many( res, b = "b", se = "se", @@ -113,8 +113,8 @@ test_that("Forest plot 1 to many test 3 - with subcategory in by argument", { res$subcategory[is.na(res$subcategory)] <- "Group 2" res$weight <- 1 / res$se res <- sort_1_to_many(res, sort_action = 1, group = "subcategory") - expect_warning( - p10 <- forest_plot_1_to_many( + p10 <- expect_warning( + forest_plot_1_to_many( res, b = "b", se = "se", diff --git a/tests/testthat/test_steiger.R b/tests/testthat/test_steiger.R index fcd510a2..f605d819 100644 --- a/tests/testthat/test_steiger.R +++ b/tests/testthat/test_steiger.R @@ -21,6 +21,6 @@ test_that("directionality cc", { }) test_that("steiger filtering", { - expect_warning(dat <- steiger_filtering(dat)) + dat <- expect_warning(steiger_filtering(dat)) expect_true("steiger_pval" %in% names(dat)) }) From 57f349f5d7fe6f06d242e7b09e19274d86865672 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Wed, 25 Mar 2026 07:37:03 +0000 Subject: [PATCH 6/6] Update NEWS.md --- NEWS.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS.md b/NEWS.md index 18c5b815..47737cc7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# TwoSampleMR v0.7.1 + +(Release date 2026-03-25) + +* Added error message if unsupported method listed in the `method_list` argument to the `mr()` function (thanks @42kuroniko) +* Added warning if `mr_wald_ratio()` passed more than one genotype's summary statistics + # TwoSampleMR v0.7.0 (Release date 2026-02-24)