Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")),
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
27 changes: 27 additions & 0 deletions R/mr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -311,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
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_eve.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
21 changes: 21 additions & 0 deletions tests/testthat/test_mr.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,24 @@ 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")))
})

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)
})
2 changes: 1 addition & 1 deletion tests/testthat/test_otherformats.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_steiger.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Loading