@@ -68,7 +68,7 @@ add_rsq_one <- function(dat, what="exposure")
6868 } else {
6969 message(" Try adding metadata with add_metadata()" )
7070 }
71- } else if (all(grepl(" SD" , dat [[paste0(" units." , what )]])) & all(! is.na(dat [[paste0(" eaf." , what )]]))) {
71+ } else if (all(grepl(" SD" , dat [[paste0(" units." , what )]])) && all(! is.na(dat [[paste0(" eaf." , what )]]))) {
7272 dat [[paste0(" rsq." , what )]] <- NA
7373 dat [[paste0(" rsq." , what )]] <- 2 * dat [[paste0(" beta." , what )]]^ 2 * dat [[paste0(" eaf." , what )]] * (1 - dat [[paste0(" eaf." , what )]])
7474 dat [[paste0(" effective_n." , what )]] <- dat [[paste0(" samplesize." , what )]]
@@ -109,12 +109,19 @@ get_r_from_pn_less_accurate <- function(p, n)
109109
110110test_r_from_pn <- function ()
111111{
112+ if (! requireNamespace(" tidyr" , quietly = TRUE )) {
113+ stop(
114+ " Package \" tidyr\" must be installed to use this function." ,
115+ call. = FALSE
116+ )
117+ }
118+
112119 param <- expand.grid(
113120 n = c(10 , 100 , 1000 , 10000 , 100000 ),
114121 rsq = 10 ^ seq(- 4 ,- 0.5 , length.out = 30 )
115122 )
116123
117- for (i in 1 : nrow(param ))
124+ for (i in seq_len( nrow(param ) ))
118125 {
119126 message(i )
120127 x <- scale(stats :: rnorm(param $ n [i ]))
@@ -125,7 +132,7 @@ test_r_from_pn <- function()
125132 param $ rsq2 [i ] <- get_r_from_pn(param $ pval [i ], param $ n [i ])^ 2
126133 }
127134
128- param <- gather(param , key = out , value = value , rsq1 , rsq2 )
135+ param <- tidyr :: gather(param , key = out , value = value , rsq1 , rsq2 )
129136
130137 p <- ggplot2 :: ggplot(param , ggplot2 :: aes(x = rsq_emp , value )) +
131138 ggplot2 :: geom_abline(slope = 1 , linetype = " dotted" ) +
@@ -170,7 +177,7 @@ get_r_from_pn <- function(p, n)
170177 abs(- log10(suppressWarnings(get_p_from_r2n(x , sample_size ))) - - log10(pvalue ))
171178 }
172179
173- if (length(p ) > 1 & length(n ) == 1 )
180+ if (length(p ) > 1 && length(n ) == 1 )
174181 {
175182 message(" Assuming n the same for all p values" )
176183 n <- rep(n , length(p ))
@@ -182,7 +189,7 @@ get_r_from_pn <- function(p, n)
182189 if (any(index ))
183190 {
184191 index <- which(index )
185- for (i in 1 : length (index ))
192+ for (i in seq_along (index ))
186193 {
187194 if (p [index [i ]] == 0 )
188195 {
@@ -240,15 +247,15 @@ get_r_from_lor <- function(lor, af, ncase, ncontrol, prevalence, model="logit",
240247 stopifnot(length(ncase ) == 1 | length(ncase ) == length(lor ))
241248 stopifnot(length(ncontrol ) == 1 | length(ncontrol ) == length(lor ))
242249 stopifnot(length(prevalence ) == 1 | length(prevalence ) == length(lor ))
243- if (length(prevalence ) == 1 & length(lor ) != 1 )
250+ if (length(prevalence ) == 1 && length(lor ) != 1 )
244251 {
245252 prevalence <- rep(prevalence , length(lor ))
246253 }
247- if (length(ncase ) == 1 & length(lor ) != 1 )
254+ if (length(ncase ) == 1 && length(lor ) != 1 )
248255 {
249256 ncase <- rep(ncase , length(lor ))
250257 }
251- if (length(ncontrol ) == 1 & length(lor ) != 1 )
258+ if (length(ncontrol ) == 1 && length(lor ) != 1 )
252259 {
253260 ncontrol <- rep(ncontrol , length(lor ))
254261 }
@@ -340,7 +347,7 @@ get_population_allele_frequency <- function(af, prop, odds_ratio, prevalence)
340347{
341348 stopifnot(length(af ) == length(odds_ratio ))
342349 stopifnot(length(prop ) == length(odds_ratio ))
343- for (i in 1 : length (odds_ratio ))
350+ for (i in seq_along (odds_ratio ))
344351 {
345352 co <- contingency(af [i ], prop [i ], odds_ratio [i ])
346353 af_controls <- co [1 ,2 ] / (co [1 ,2 ] + co [2 ,2 ])
0 commit comments