Skip to content

Commit 806703f

Browse files
authored
Merge pull request #559 from remlapmot/v0-6-8
TwoSampleMR 0.6.8
2 parents d70ec00 + f9dfa45 commit 806703f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+535
-551
lines changed

.github/workflows/check-full.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525

2626
strategy:
2727
fail-fast: false
28+
max-parallel: 2
2829
matrix:
2930
config:
3031
- {os: macos-latest, r: 'release'}

.github/workflows/test-coverage.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ jobs:
4848

4949
- uses: codecov/codecov-action@v4
5050
with:
51-
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
51+
# Fail if error if not on PR, or if on PR and token is given
52+
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
5253
file: ./cobertura.xml
5354
plugin: noop
5455
disable_search: true

.lintr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ linters: linters_with_defaults(
22
line_length_linter = NULL,
33
commented_code_linter = NULL,
44
indentation_linter = NULL,
5-
trailing_whitespace_linter = NULL,
65
infix_spaces_linter = NULL,
76
quotes_linter = NULL,
8-
trailing_blank_lines_linter = NULL,
97
brace_linter = NULL,
108
commas_linter = NULL,
119
whitespace_linter = NULL,
1210
object_name_linter = NULL,
1311
assignment_linter = NULL,
14-
cyclocomp_linter = NULL
12+
cyclocomp_linter = NULL,
13+
object_usage_linter = NULL,
14+
spaces_left_parentheses_linter = NULL,
15+
object_length_linter = NULL
1516
)
1617
encoding: "UTF-8"

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.7
3+
Version: 0.6.8
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# TwoSampleMR v0.6.8
2+
3+
(Release date 2024-09-06)
4+
5+
* Replaced some `unique()` calls in `power_prune()` with `mean()` to ensure scalar `iv.se` values (thanks @phageghost)
6+
* Slightly improved formatting of code base
7+
18
# TwoSampleMR v0.6.7
29

310
(Release date 2024-08-21)

R/add_rsq.r

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' Can be applied to exposure_dat, outcome_dat or harmonised_data.
44
#' Note that it will be beneficial in some circumstances to add the meta data to
5-
#' the data object using [add_metadata()] before running this function.
5+
#' the data object using [add_metadata()] before running this function.
66
#' Also adds effective sample size for case control data.
77
#'
88
#' @param dat exposure_dat, outcome_dat or harmonised_data
@@ -76,7 +76,7 @@ add_rsq_one <- function(dat, what="exposure")
7676
ind1 <- !is.na(dat[[paste0("pval.", what)]]) & !is.na(dat[[paste0("samplesize.", what)]])
7777
dat[[paste0("rsq.", what)]] <- NA
7878
if(sum(ind1) > 0)
79-
{
79+
{
8080
dat[[paste0("rsq.", what)]][ind1] <- get_r_from_bsen(
8181
dat[[paste0("beta.", what)]][ind1],
8282
dat[[paste0("se.", what)]][ind1],
@@ -114,7 +114,7 @@ test_r_from_pn <- function()
114114
"Package \"tidyr\" must be installed to use this function.",
115115
call. = FALSE
116116
)
117-
}
117+
}
118118

119119
param <- expand.grid(
120120
n = c(10, 100, 1000, 10000, 100000),
@@ -228,7 +228,7 @@ compareNA <- function(v1,v2) {
228228

229229
#' Estimate proportion of variance of liability explained by SNP in general population
230230
#'
231-
#' This uses equation 10 in Lee et al. A Better Coefficient of Determination for Genetic Profile Analysis.
231+
#' This uses equation 10 in Lee et al. A Better Coefficient of Determination for Genetic Profile Analysis.
232232
#' Genetic Epidemiology 36: 214–224 (2012) \doi{10.1002/gepi.21614}.
233233
#'
234234
#' @param lor Vector of Log odds ratio.
@@ -309,7 +309,7 @@ contingency <- function(af, prop, odds_ratio, eps=1e-15)
309309
z <- -c_ / b
310310
} else {
311311
d <- b^2 - 4*a*c_
312-
if (d < eps*eps)
312+
if (d < eps*eps)
313313
{
314314
s <- 0
315315
} else {
@@ -327,7 +327,7 @@ contingency <- function(af, prop, odds_ratio, eps=1e-15)
327327
#' @param g Vector of 0/1/2
328328
#'
329329
#' @export
330-
#' @return Allele frequency
330+
#' @return Allele frequency
331331
allele_frequency <- function(g)
332332
{
333333
(sum(g == 1) + 2 * sum(g == 2)) / (2 * sum(!is.na(g)))

R/enrichment.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ enrichment_method_list <- function()
4242
a <- lapply(a, as.data.frame)
4343
a <- plyr::rbind.fill(a)
4444
a <- as.data.frame(lapply(a, as.character), stringsAsFactors=FALSE)
45-
return(a)
45+
return(a)
4646
}
4747

4848

R/eve.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ mr_mean_egger <- function(d)
114114
y2 <- ratios * weights2
115115
egger2 <- summary(stats::lm(y2 ~ weights2))
116116
eggeroutliers <- dplyr::tibble(
117-
SNP=d$SNP,
118-
Qj = weights2^2 * (ratios - stats::coefficients(egger2)[1,1] / weights2 - stats::coefficients(egger2)[2,1])^2,
117+
SNP=d$SNP,
118+
Qj = weights2^2 * (ratios - stats::coefficients(egger2)[1,1] / weights2 - stats::coefficients(egger2)[2,1])^2,
119119
Qpval=stats::pchisq(Qj,1,lower.tail=FALSE)
120120
)
121121

@@ -209,7 +209,7 @@ mr_all <- function(dat, parameters=default_parameters())
209209
m1$estimates <- dplyr::bind_rows(m1$estimates, m2, m3)
210210
}
211211
m1$info <- c(list(
212-
id.exposure = dat$id.exposure[1], id.outcome = dat$id.outcome[1]),
212+
id.exposure = dat$id.exposure[1], id.outcome = dat$id.outcome[1]),
213213
system_metrics(dat)
214214
) %>% dplyr::as_tibble()
215215
return(m1)

R/forest_plot.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#' @param decrease (logical) sort the studies by decreasing effect sizes `TRUE`/`FALSE`?
4444
#' @param se_Col (character) name of the column giving the standard error of the effect sizes.
4545
#' @param returnRobj (logical) return the graph as an internal R object `TRUE`/`FALSE`?
46-
#'
46+
#'
4747
#' @keywords internal
4848
#' @return grid object giving the forest plot (or plot as pdf)
4949
mr_forest_plot_grouped <-
@@ -117,7 +117,7 @@ mr_forest_plot_grouped <-
117117
idx <- idx + 2 + n_std
118118
}
119119
# returns data frame giving spacings, primary annotation (content_list), typeface attributes for the primary annotation (attr_list), and mapping between rows in forest plot and rows in meta-analytic data frame
120-
return( data.frame( spacing_vec = (1 + length(spacing_vec) - spacing_vec), content_list = unlist(content_list), row_list = unlist(row_list), attr_list = unlist(attr_list) ) )
120+
return(data.frame(spacing_vec = (1 + length(spacing_vec) - spacing_vec), content_list = unlist(content_list), row_list = unlist(row_list), attr_list = unlist(attr_list)))
121121
}
122122

123123

@@ -162,7 +162,7 @@ mr_forest_plot_grouped <-
162162
data_Fm$eff_col <- log(as.numeric(data_Fm[,eff_col]))
163163
}
164164
# ggplot code to generate the forest plot using geom_segments and geom_points and to make a relatively minimal theme
165-
raw_forest <- ggplot2::ggplot(data = data_Fm, ggplot2::aes( y = space_col, yend = space_col, x = as.numeric(lb_col), xend = as.numeric(ub_col) )) + ggplot2::geom_segment() + ggplot2::geom_point(ggplot2::aes( y = space_col, x = as.numeric(eff_col), size = 4 )) + ggplot2::theme_bw() + ggplot2::theme( axis.text.y = ggplot2::element_blank(), axis.ticks.y = ggplot2::element_blank(), axis.title = ggplot2::element_blank(), panel.grid = ggplot2::element_blank(), rect = ggplot2::element_blank(), title = ggplot2::element_text(size = 23), legend.position = 'none') + ggplot2::expand_limits(y = c(data_Fm[,space_col] - 1, data_Fm[,space_col] + 2)) + ggplot2::labs(title = title_text) # returns ggplot2 object with the (un-annotated) forest plot
165+
raw_forest <- ggplot2::ggplot(data = data_Fm, ggplot2::aes(y = space_col, yend = space_col, x = as.numeric(lb_col), xend = as.numeric(ub_col))) + ggplot2::geom_segment() + ggplot2::geom_point(ggplot2::aes(y = space_col, x = as.numeric(eff_col), size = 4)) + ggplot2::theme_bw() + ggplot2::theme(axis.text.y = ggplot2::element_blank(), axis.ticks.y = ggplot2::element_blank(), axis.title = ggplot2::element_blank(), panel.grid = ggplot2::element_blank(), rect = ggplot2::element_blank(), title = ggplot2::element_text(size = 23), legend.position = 'none') + ggplot2::expand_limits(y = c(data_Fm[,space_col] - 1, data_Fm[,space_col] + 2)) + ggplot2::labs(title = title_text) # returns ggplot2 object with the (un-annotated) forest plot
166166
return(raw_forest)
167167
}
168168

@@ -180,10 +180,10 @@ mr_forest_plot_grouped <-
180180
data_Fm$text_col <- data_Fm[,text_col]
181181

182182
# A hard rule to set the width of the annotation column, which sometimes truncates very wide columns (complex disease names, numbers with 16 digits, etc)
183-
text_widths <- c(-1, max(10,0.5 * max(sapply( as.character(data_Fm[,text_col]),nchar ))))
183+
text_widths <- c(-1, max(10,0.5 * max(sapply(as.character(data_Fm[,text_col]), nchar))))
184184

185185
# GGplot rendering of the annotation column
186-
lefttext <- ggplot2::ggplot(data = data_Fm, ggplot2::aes( y = space_col, x = 0, label = text_col, fontface = attr_list )) + ggplot2::geom_text(hjust = 0) + ggplot2::theme_bw() + ggplot2::theme( axis.text.y = ggplot2::element_blank(), axis.ticks.y = ggplot2::element_blank(),axis.text.x = ggplot2::element_text(colour = "white"),axis.ticks.x = ggplot2::element_line(colour = "white"), axis.title = ggplot2::element_blank(), rect = ggplot2::element_blank(), panel.grid = ggplot2::element_blank(), title = ggplot2::element_text(size = 23) ) + ggplot2::expand_limits(x = text_widths, y = c(data_Fm[,space_col] - 1, data_Fm[,space_col] + 2)) + ggplot2::labs(title = title_text, size = 40) # returns two-item list with left_text, the GGplot annotations, and text_widths, the x-axis limits of the plot
186+
lefttext <- ggplot2::ggplot(data = data_Fm, ggplot2::aes(y = space_col, x = 0, label = text_col, fontface = attr_list)) + ggplot2::geom_text(hjust = 0) + ggplot2::theme_bw() + ggplot2::theme(axis.text.y = ggplot2::element_blank(), axis.ticks.y = ggplot2::element_blank(), axis.text.x = ggplot2::element_text(colour = "white"), axis.ticks.x = ggplot2::element_line(colour = "white"), axis.title = ggplot2::element_blank(), rect = ggplot2::element_blank(), panel.grid = ggplot2::element_blank(), title = ggplot2::element_text(size = 23)) + ggplot2::expand_limits(x = text_widths, y = c(data_Fm[, space_col] - 1, data_Fm[, space_col] + 2)) + ggplot2::labs(title = title_text, size = 40) # returns two-item list with left_text, the GGplot annotations, and text_widths, the x-axis limits of the plot
187187
return(list(left_text = lefttext, text_widths = text_widths))
188188
}
189189

@@ -203,7 +203,7 @@ mr_forest_plot_grouped <-
203203

204204
for (i in seq_along(col_names)) {
205205
# loop to get the widths of each annotation column and to group the annotation objects together
206-
col <- anot_col( data_Fm = data_Fm, text_col = col_names[i], space_col = space_col, title_text = title_list[[i]] )
206+
col <- anot_col(data_Fm = data_Fm, text_col = col_names[i], space_col = space_col, title_text = title_list[[i]])
207207
relative_widths[i] <- col$text_widths[2] - col$text_widths[1]
208208
output[[col_names[i]]] <- ggplotGrob(col$left_text)
209209
}
@@ -246,7 +246,7 @@ mr_forest_plot_grouped <-
246246
width_vec <- c(left_RW,0.34,right_RW)
247247
width_vec <- width_vec / sum(width_vec)
248248
# convert the grid objects (now grouped) into a table of grid objects that can be plotted using grid.draw
249-
grp_FP <- gtable::gtable_matrix( name = "groupplot", grobs = matrix(grob_Bag, nrow = 1), widths = unit(width_vec, "npc"), heights = unit(1,"npc") )
249+
grp_FP <- gtable::gtable_matrix(name = "groupplot", grobs = matrix(grob_Bag, nrow = 1), widths = unit(width_vec, "npc"), heights = unit(1,"npc"))
250250

251251
# return the grid object table, to be plotted
252252
return(grp_FP)
@@ -263,18 +263,18 @@ mr_forest_plot_grouped <-
263263

264264

265265
## order and structure effect sizes and CIs for forest plot
266-
space1 <- spacer( exposure = exposure_Name, eff_col = eff_Col, outcome = outcome_Name, Data_Fm = data, decrease = decrease)
266+
space1 <- spacer(exposure = exposure_Name, eff_col = eff_Col, outcome = outcome_Name, Data_Fm = data, decrease = decrease)
267267

268268
expand_data <- space_Out(data_Fm = data, space_Fm = space1)
269269

270270
## Make the forest plot
271-
fo1 <- ggforest( data_Fm = expand_data, space_col = 'spacing_vec', eff_col = eff_Col, lb_col = "lb" ,ub_col = "ub", log_ES = log_ES, title_text = forest_Title )
271+
fo1 <- ggforest(data_Fm = expand_data, space_col = 'spacing_vec', eff_col = eff_Col, lb_col = "lb" ,ub_col = "ub", log_ES = log_ES, title_text = forest_Title)
272272

273273
## Construct left-hand-side annotations
274-
left <- anot_side( data_Fm = expand_data, space_col = 'spacing_vec', col_names = left_Col_Names, title_list = left_Col_Titles )
274+
left <- anot_side(data_Fm = expand_data, space_col = 'spacing_vec', col_names = left_Col_Names, title_list = left_Col_Titles)
275275

276276
## Construct right-hand-side annotations
277-
right <- anot_side( data_Fm = expand_data, space_col = 'spacing_vec', col_names = right_Col_Names, title_list = right_Col_Titles )
277+
right <- anot_side(data_Fm = expand_data, space_col = 'spacing_vec', col_names = right_Col_Names, title_list = right_Col_Titles)
278278

279279
## group all plots together
280280
group <- group_Plots(forst_Pt = fo1, left_Hs = left, right_Hs = right)

0 commit comments

Comments
 (0)