Skip to content

Commit aba3eb1

Browse files
authored
Merge pull request #515 from remlapmot/si-fang-possible-issue
TwoSampleMR 0.6.2
2 parents 99d1317 + a733001 commit aba3eb1

File tree

8 files changed

+65
-9
lines changed

8 files changed

+65
-9
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: TwoSampleMR
22
Title: Two Sample MR Functions and Interface to MR Base Database
3-
Version: 0.6.1
3+
Version: 0.6.2
44
Authors@R: c(
55
person("Gibran", "Hemani", , "g.hemani@bristol.ac.uk", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-0920-1055")),

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# TwoSampleMR v0.6.2
2+
3+
(Release date: 2024-05-09)
4+
5+
* `format_data()` now errors if it detects its `dat` object is of class `'data.table'` and issues a message informing the user to make their dat object simply a `'data.frame'` (thanks to Si Fang @sifang1678)
6+
17
# TwoSampleMR v0.6.1
28

39
(Release date: 2024-04-30)

R/format_mr_results2.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#'
77
#' @export
88
#' @return data frame
9-
109
split_outcome <- function(mr_res)
1110
{
1211
Pos<-grep("\\|\\|",mr_res$outcome) #the "||"" indicates that the outcome column was derived from summary data in MR-Base. Sometimes it wont look like this e.g. if the user has supplied their own outcomes

R/heterogeneity.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
#' Get heterogeneity statistics
42
#'
53
#' Get heterogeneity statistics.

R/mr.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#' Perform all Mendelian randomization tests
32
#'
43
#' @param dat Harmonised exposure and outcome data. Output from [harmonise_data()].

R/query.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#' Get list of studies with available GWAS summary statistics through API
32
#'
43
#' @param opengwas_jwt Used to authenticate protected endpoints. Login to <https://api.opengwas.io> to obtain a jwt. Provide the jwt string here, or store in .Renviron under the keyname OPENGWAS_JWT.

R/read_data.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
#' Read outcome data
42
#'
53
#' Reads in outcome data. Checks and organises columns for use with MR or enrichment tests.
@@ -165,7 +163,17 @@ format_data <- function(dat, type="exposure", snps=NULL, header=TRUE,
165163
z_col="z", info_col="info", chr_col="chr",
166164
pos_col="pos", log_pval=FALSE)
167165
{
168-
all_cols <- c(phenotype_col, snp_col, beta_col, se_col, eaf_col, effect_allele_col, other_allele_col, pval_col, units_col, ncase_col, ncontrol_col, samplesize_col, gene_col, id_col, z_col, info_col, chr_col, pos_col)
166+
167+
if (inherits(dat, "data.table")) {
168+
datname <- deparse(substitute(dat))
169+
stop(paste0(
170+
"Your ", datname, " data.frame is also of class 'data.table', ",
171+
"please reformat as simply a data.frame with ", datname, " <- data.frame(",
172+
datname, ") and then rerun your format_data() call."
173+
))
174+
}
175+
176+
all_cols <- c(phenotype_col, snp_col, beta_col, se_col, eaf_col, effect_allele_col, other_allele_col, pval_col, units_col, ncase_col, ncontrol_col, samplesize_col, gene_col, id_col, z_col, info_col, chr_col, pos_col)
169177

170178
i <- names(dat) %in% all_cols
171179
if(sum(i) == 0)

tests/testthat/test_format_data.R

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
df <- data.frame(
2+
"SNP" = c("9_69001927_C_T", "9_69459263_A_G", "9_69508544_G_A"),
3+
"effect_allele" = c("T", "G", "A"),
4+
"other_allele" = c("C", "A", "G"),
5+
"se" = c(0.01664, 0.02038, 0.04585),
6+
"beta" = c(0.367464, -0.265656, 0.254032),
7+
"eaf" = c(0.319894, 0.39234, 0.343751),
8+
"pval" = c(0.250677, 0.498338, 0.459907),
9+
"n" = c(30100, 30100, 30100),
10+
"pheno_id" = c("traita", "traita", "traita")
11+
)
12+
13+
df <- data.table::data.table(df)
14+
15+
test_that("format_data() should error on a dat object of class data.table", {
16+
expect_error(format_data(
17+
df,
18+
type = "exposure",
19+
snp_col = "SNP",
20+
pval_col = "pval",
21+
beta_col = "beta",
22+
se_col = "se",
23+
effect_allele_col = "effect_allele",
24+
other_allele_col = "other_allele",
25+
eaf_col = "eaf",
26+
phenotype_col = "pheno_id",
27+
samplesize_col = "n"
28+
))
29+
})
30+
31+
df <- data.frame(df)
32+
33+
test_that("format_data() should not error after having its data.table class removed", {
34+
expect_no_error(format_data(
35+
df,
36+
type = "exposure",
37+
snp_col = "SNP",
38+
pval_col = "pval",
39+
beta_col = "beta",
40+
se_col = "se",
41+
effect_allele_col = "effect_allele",
42+
other_allele_col = "other_allele",
43+
eaf_col = "eaf",
44+
phenotype_col = "pheno_id",
45+
samplesize_col = "n"
46+
))
47+
})

0 commit comments

Comments
 (0)