Skip to content

Commit 255b8bc

Browse files
committed
lint
1 parent 9c191db commit 255b8bc

14 files changed

+102
-83
lines changed

R/app.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#' Runs the shinysse Shiny application
22
#'
3-
#' This runs the shinysse Shiny web application. You can run the application by
4-
#' calling the run_shiny() function.
3+
#' You can run the web application by alling the run_shiny() function.
54
#'
65
#' @seealso \code{\link{app}},\code{\link{app_ui}}
76
#' @export
87
#'
98
run_shiny <- function(){
10-
## with addResourcePath, one can make resources available in the global environment
11-
## this is needed for www since we keep it at a non-standard location for shiny term
12-
addResourcePath('www', system.file('www', package = 'shinysse'))
9+
## make resources available globally from non standard location
10+
addResourcePath("www", system.file("www", package = "shinysse"))
1311
shinyApp(ui = app_ui, server = app_server)
1412
}

R/fun_calc_prop.R

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ fun_calc_prop <- function(){
1717
seq(from = 0.2, to = 0.5, by = 0.05)), # possible range of effect sizes
1818
xi = seq(from = 0.05, to = 1, by = 0.05)) # possible range of proportions
1919

20-
## defining a power-function based on a power.prop.test
20+
## defining a power fun based on a power.prop.test
2121
powFuns_prop <- list()
22-
for(i in 1:length(alpha)){
23-
eval(parse(text = paste(paste0("powFuns_prop[[", paste0("'alpha", sub(".", "p", alpha[i], fixed = TRUE)), "']]", " <- function(psi)"),
22+
for (i in 1:length(alpha)){
23+
eval(parse(text = paste(paste0("powFuns_prop[[", paste0("'alpha", sub(".", "p", alpha[i], fixed = TRUE)), "']]",
24+
" <- function(psi)"),
2425
"{",
2526
"p1 = xi(psi)",
2627
"power.prop.test(n = sse::n(psi)/2,",
@@ -31,13 +32,8 @@ fun_calc_prop <- function(){
3132
")$power",
3233
"}", sep = "\n")))
3334
}
34-
35-
## evaulate power-function for all combinations of n, theta, xi and alpha
35+
## evaulate power function for all combinations of n, theta, xi and alpha
3636
calc_prop <- map(powFuns_prop, ~powCalc(psi_prop, .))
37-
38-
## readRDS
39-
calc_prop <- readRDS("calc_prop_test.rds")
40-
calc_prop <- readRDS(system.file("extdata", "calc_prop_test.rds", package = "shinyssepkg"))
4137
## save calcs to be used in the shiny app
4238
save_path <- file.path("inst", "extdata", "calc_prop_test.rds")
4339
saveRDS(calc_prop, save_path)

R/fun_calc_t.R

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,29 @@
88
#' @return list of calculated powPar objects
99
#' @export
1010
#'
11-
fun_calc_t <- function(type = "two.sided"){
11+
fun_calc_t <- function(type = "two.sample"){
1212
## define range of significance levels
1313
alpha <- c(0.01, 0.025, 0.05)
1414
## defining the range of n and theta to be evaluated
1515
psi_t <- powPar(n = seq(from = 5, to = 2000, by = 5), # possible range of sample sizes
1616
theta = seq(from = 1, to = 50, by = 1), # possible range of effect sizes
1717
xi = seq(from = 1, to = 80, by = 1)) # possible range of standard deviations
18-
## defining a power-function based on a power.t.test
18+
## defining a power fun based on a power.t.test
1919
powFuns_t <- list()
20-
for(i in 1:length(alpha)){
21-
eval(parse(text = paste(paste0("powFuns_t[[", paste0("'alpha", sub(".", "p", alpha[i], fixed = TRUE)), "']]", " <- function(psi)"),
22-
"{",
23-
"power.t.test(n = sse::n(psi)/2,",
24-
"delta = theta(psi),",
25-
"sd = xi(psi),",
26-
paste0("sig.level = ", alpha[i], ","),
27-
"power = NULL,",
28-
paste0("type = '", type, "'"),
29-
")$power",
30-
"}", sep = "\n")))
20+
for (i in 1:length(alpha)){
21+
eval(parse(text =
22+
paste(paste0("powFuns_t[[", paste0("'alpha", sub(".", "p", alpha[i], fixed = TRUE)), "']]", " <- function(psi)"),
23+
"{",
24+
"power.t.test(n = sse::n(psi)/2,",
25+
"delta = theta(psi),",
26+
"sd = xi(psi),",
27+
paste0("sig.level = ", alpha[i], ","),
28+
"power = NULL,",
29+
paste0("type = '", type, "'"),
30+
")$power",
31+
"}", sep = "\n")))
3132
}
32-
## evaulate power-function for all combinations of n, theta, xi and alpha
33+
## evaulates power function for all combinations of n, theta, xi and alpha
3334
calc_t <- map(powFuns_t, ~powCalc(psi_t, .))
3435
## save calcs to be used in the shiny app
3536
save_path <- file.path("inst", "extdata", paste0("calc_t_test_", type, ".rds"))

R/mod_app_intro_server.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
#'
33
#' @seealso \code{\link{app_intro}}
44
#'
5-
app_intro <- function(input, output, session){}
5+
app_intro <- function(input, output, session) {
6+
7+
}

R/mod_app_intro_ui.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ app_intro_ui <- function(id, label){
1414
p("This app is designed for demonstration purposes only,
1515
and cannot replace a well crafted statistical modelling performed by a skilled statistician."))),
1616
fluidRow(
17-
p("Sample size estimation is the process of estimating the number of replicates to include in a statistical study."),
17+
p("Sample size estimation is the process of estimating
18+
the number of replicates to include in a statistical study."),
1819
p("It crucially depends on several variables:"),
1920
tags$ul(
2021
tags$li("Chosen test statistics"),

R/mod_sse_prop_server.R

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ sse_prop <- function(input, output, session, calcs){
1212
sigLevel <- as.numeric(input$in_alpha)
1313
power <- as.numeric(input$in_power)
1414

15-
p_diff_val <- as.numeric(toString(max(c(p1,p2))-min(c(p1,p2))))
15+
p_diff_val <- as.numeric(toString(max(c(p1, p2)) - min(c(p1, p2))))
1616
validate({
17-
need(p_diff_val > 0, "Difference in probabilities in group 1 and 2 is outside of plottable range. It must be > 0 and <= 0.5")
18-
if(p_diff_val > 0.5){
17+
need(p_diff_val > 0,
18+
"Difference in probabilities in group 1 and 2 is outside of plottable range. It must be > 0 and <= 0.5")
19+
if (p_diff_val > 0.5){
1920
calcAppx <- power.prop.test(n = NULL,
2021
p1 = p1,
2122
p2 = p2,
2223
sig.level = sigLevel,
2324
power = power)
2425
need(p_diff_val <= 0.5,
2526
paste0("Difference in probabilities in group 1 and 2 is outside of plottable range. ",
26-
"It must be > 0 and <= 0.5. The estimated sample size is ", ceiling(calcAppx$n*2)))
27+
"It must be > 0 and <= 0.5. The estimated sample size is ", ceiling(calcAppx$n * 2)))
2728
}
2829
})
2930
p_diff_val
@@ -38,7 +39,8 @@ sse_prop <- function(input, output, session, calcs){
3839

3940
## validate
4041
validate({
41-
need(p_diff() > 0, "Difference in probabilities in group 1 and 2 is outside of plottable range. It must be > 0 and <= 0.5")
42+
need(p_diff() > 0,
43+
"Difference in probabilities in group 1 and 2 is outside of plottable range. It must be > 0 and <= 0.5")
4244
})
4345

4446
## calculate an example sample size for given parameters
@@ -48,15 +50,15 @@ sse_prop <- function(input, output, session, calcs){
4850

4951
## dynamically define x and y axis limits for a nicer plotting experience
5052
ylim <- c(0, 10000)
51-
if(calcN < 10) {
53+
if (calcN < 10) {
5254
ylim <- c(0, 20)
53-
} else if(calcN < 50) {
55+
} else if (calcN < 50) {
5456
ylim <- c(0, 100)
55-
} else if(calcN < 250) {
57+
} else if (calcN < 250) {
5658
ylim <- c(0, 500)
57-
} else if(calcN < 500) {
59+
} else if (calcN < 500) {
5860
ylim <- c(0, 1000)
59-
} else if(calcN < 2000) {
61+
} else if (calcN < 2000) {
6062
ylim <- c(0, 4000)
6163
}
6264

R/mod_sse_prop_ui.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
#' @seealso \code{\link{sse_prop}}
44
#'
55
sse_prop_ui <- function(id, label){
6-
box_width = 3
7-
box_height = 190
6+
box_width <- 3
7+
box_height <- 190
88
ns <- NS(id)
99
tabItem(label,
1010
br(), br(),
1111
h2("Proportion Test based sample size estimation"),
1212
fluidPage(
1313
fluidRow(
14-
br(),br(),
14+
br(), br(),
1515
p(""),
16-
br(),br()
16+
br(), br()
1717
),
1818
fluidRow(
1919
box(
@@ -43,9 +43,9 @@ sse_prop_ui <- function(id, label){
4343
),
4444
fluidRow(
4545
box(
46-
plotOutput(ns("out_plot1"), height = 250*2),
46+
plotOutput(ns("out_plot1"), height = 250 * 2),
4747
width = 12,
48-
height = 250*2+20
48+
height = 250 * 2 + 20
4949
),
5050
)
5151
)

R/mod_sse_ttest_plus_server.R

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ sse_ttest_plus <- function(input, output, session, calcs){
1111
m2 <- input$mean_g2
1212
effSize_val <- abs(m1 - m2)
1313
validate({
14-
need(((m1 %% 1) == 0) & ((m2 %% 1) == 0), "Only integers are allowed for group means")
15-
need((effSize_val >= 5) & (effSize_val <= 50), "The difference in expected means between group 1 and group 2 should be >=5 and <= 50.")
14+
need( ( (m1 %% 1) == 0) & ( (m2 %% 1) == 0),
15+
"Only integers are allowed for group means")
16+
need( (effSize_val >= 5) & (effSize_val <= 50),
17+
"The difference in expected means between group 1 and group 2 should be >=5 and <= 50.")
1618
})
1719
return(effSize_val)
1820
})
@@ -40,7 +42,8 @@ sse_ttest_plus <- function(input, output, session, calcs){
4042
panel.grid.minor = element_blank(),
4143
panel.border = element_blank())
4244
return(p)
43-
}, height = 270, width = 285)
45+
},
46+
height = 270, width = 285)
4447

4548

4649
## sse plot
@@ -57,34 +60,33 @@ sse_ttest_plus <- function(input, output, session, calcs){
5760
## validations
5861
validate({
5962
calcAppx <- list(n = calcN)
60-
if(is.na(calcN)){
63+
if (is.na(calcN)){
6164
calcAppx <- power.t.test(n = NULL,
6265
delta = effSize(),
6366
sd = sd,
6467
sig.level = sigLevel,
6568
power = power)
6669
}
67-
need(!is.na(calcN), paste0("Estimated sample size is ", ceiling(calcAppx$n*2), " , which is outside of plottable range."))
70+
need( !is.na(calcN),
71+
paste0("Estimated sample size is ", ceiling(calcAppx$n * 2), " , which is outside of plottable range."))
6872
})
6973
## dynamically define x and y axis limits for a nicer plotting experience
7074
ylim <- c(0, 2000)
71-
if(calcN < 10) {
75+
if (calcN < 10) {
7276
ylim <- c(0, 20)
73-
} else if(calcN < 50) {
77+
} else if (calcN < 50) {
7478
ylim <- c(0, 100)
75-
} else if(calcN < 250) {
79+
} else if (calcN < 250) {
7680
ylim <- c(0, 500)
77-
} else if(calcN < 500) {
81+
} else if (calcN < 500) {
7882
ylim <- c(0, 1000)
7983
}
8084

8185
p <- plot(example,
82-
# xi = sd, # this should come from radio button chosen sig lev
83-
at = c(0.7, 0.8, 0.9, 0.95), # 3 possible values for power
86+
at = c(0.7, 0.8, 0.9, 0.95),
8487
ylab = "sample size",
8588
xlab = "treatment effect",
8689
ylim = ylim # adjust dynamically
87-
# xlim = xlim # adjust dynamically
8890
)
8991
return(p)
9092
})

R/mod_sse_ttest_plus_ui.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
#' @seealso \code{\link{sse_ttest_plus}}
77
#'
88
sse_ttest_plus_ui <- function(id, label){
9-
box_width = 3
10-
box_height = 230
9+
box_width <- 3
10+
box_height <- 230
1111
ns <- NS(id)
1212
tabItem(label,
1313
br(), br(),
1414
h2("T - Test based sample size estimation with input"),
1515
fluidPage(
1616
fluidRow(
17-
br(),br(),
17+
br(), br(),
1818
p(""),
19-
br(),br()
19+
br(), br()
2020
),
2121
fluidRow(
2222
box(

R/mod_sse_ttest_server.R

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sse_ttest <- function(input, output, session, calcs_twosample, calcs_paired){
1212
effSize <- as.numeric(input$in_slider2)
1313
sd <- as.numeric(input$in_slider1)
1414

15-
if(input$in_type == "paired"){
15+
if (input$in_type == "paired"){
1616
calcs <- calcs_paired
1717
} else{
1818
calcs <- calcs_twosample
@@ -28,35 +28,34 @@ sse_ttest <- function(input, output, session, calcs_twosample, calcs_paired){
2828
## validations
2929
validate({
3030
calcAppx <- list(n = calcN)
31-
if(is.na(calcN)){
31+
if (is.na(calcN)){
3232
calcAppx <- power.t.test(n = NULL,
3333
delta = effSize,
3434
sd = sd,
3535
sig.level = sigLevel,
3636
power = power)
3737
}
38-
need(!is.na(calcN), paste0("Estimated sample size is ", ceiling(calcAppx$n*2), " , which is outside of plottable range."))
38+
need(!is.na(calcN),
39+
paste0("Estimated sample size is ", ceiling(calcAppx$n * 2), " , which is outside of plottable range."))
3940
})
4041

4142
## dynamically define x and y axis limits for a nicer plotting experience
4243
ylim <- c(0, 2000)
43-
if(calcN < 10) {
44+
if (calcN < 10) {
4445
ylim <- c(0, 20)
45-
} else if(calcN < 50) {
46+
} else if (calcN < 50) {
4647
ylim <- c(0, 100)
47-
} else if(calcN < 250) {
48+
} else if (calcN < 250) {
4849
ylim <- c(0, 500)
49-
} else if(calcN < 500) {
50+
} else if (calcN < 500) {
5051
ylim <- c(0, 1000)
5152
}
5253

5354
p <- plot(example,
54-
# xi = sd, # this should come from radio button chosen sig lev
55-
at = c(0.7, 0.8, 0.9, 0.95), # 3 possible values for power
55+
at = c(0.7, 0.8, 0.9, 0.95),
5656
ylab = "sample size",
5757
xlab = "treatment effect",
5858
ylim = ylim # adjust based on data
59-
#xlim = xlim # adjust based on input
6059
)
6160
par(bg = "blue")
6261
return(p)

0 commit comments

Comments
 (0)