Skip to content

Commit

Permalink
Run styler on package
Browse files Browse the repository at this point in the history
  • Loading branch information
NeuroShepherd committed Nov 17, 2024
1 parent a54d0aa commit 98f5c6c
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 278 deletions.
4 changes: 2 additions & 2 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
source("renv/activate.R")
options(shiny.autoload.r=FALSE)
options(shiny.autoload.r = FALSE)
options(
list(
ordinalsimr.default_iterations = 20,
ordinalsimr.default_size_min = 30,
ordinalsimr.default_size_max = 35,
ordinalsimr.default_ratio = "50:50",
ordinalsimr.default_distributions = data.frame(c(0.4,0.3,0.3), c(0.8,0.1,0.1))
ordinalsimr.default_distributions = data.frame(c(0.4, 0.3, 0.3), c(0.8, 0.1, 0.1))
)
)
3 changes: 2 additions & 1 deletion R/mod_distributions_page.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ mod_distributions_page_ui <- function(id) {
h6("Confidence Intervals"),
!!!mod_plot_distributions_ui("plot_distributions_1")[["ci_inputs"]],
h6("Outlier Removal (Plot Only)"),
mod_plot_distributions_ui("plot_distributions_1")[["outlier_input"]]),
mod_plot_distributions_ui("plot_distributions_1")[["outlier_input"]]
),
nav_panel(
title = "Power",
mod_plot_distributions_ui("plot_distributions_1")[["output_plots"]][["power_plot"]]
Expand Down
4 changes: 1 addition & 3 deletions R/mod_plot_distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ mod_plot_distributions_server <- function(id, p_value_table, n) {
alpha = p_val_threshold(),
t1_error_confidence_int = input$t1_error_group1_confidence_int
)
}
}
})
output$t1_error_group1 <- DT::renderDataTable({
validate(
Expand All @@ -195,7 +195,6 @@ mod_plot_distributions_server <- function(id, p_value_table, n) {

# GROUP 2 TYPE 1 ERROR
group2_t1_reactive_table <- reactive({

if (!is.null(p_value_table$group2_results())) {
p_value_table$group2_results() %>%
bind_rows() %>%
Expand All @@ -212,7 +211,6 @@ mod_plot_distributions_server <- function(id, p_value_table, n) {
t1_error_confidence_int = input$t1_error_group2_confidence_int
)
}

})
output$t1_error_group2 <- DT::renderDataTable({
validate(
Expand Down
103 changes: 51 additions & 52 deletions R/mod_report_generator.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod_report_generator_server <- function(id, formatted_data, rng_info) {
run_info = formatted_data()$comparison_data$run_info,
distribution_statistics = formatted_data()$comparison_data$distribution_statistics,
distribution_plot = formatted_data()$comparison_data$distribution_plot
),
),
group1_data = list(
run_info = formatted_data()$group1_data$run_info,
group1_t1error = formatted_data()$group1_data$group1_t1error
Expand All @@ -62,60 +62,59 @@ mod_report_generator_server <- function(id, formatted_data, rng_info) {


download_counter_zip <- reactiveVal(1)
output$download_report <- downloadHandler(
filename = function() {
paste0("ordinalsimr_session_", strtrim(session$token, 8),
"_download_", download_counter_zip(),
".zip")
},
content = function(file) {

output_folder <- file.path(paste0("ordinalsimr_session_", strtrim(session$token, 8),
"_download_", download_counter_zip()))
dir.create(output_folder, showWarnings = FALSE)

try({
write(
custom_report(),
file.path(output_folder, "completed_report.html")
)
})
try({
saveRDS(
formatted_data(),
file.path(output_folder, "ordinalsimr_results.rds")
)
})
try({
write(
readLines(system.file("report_template.Rmd", package = "ordinalsimr")),
file.path(output_folder, "report_template.Rmd")
)
})

zip_files <- c(
file.path(output_folder, "completed_report.html"),
file.path(output_folder, "ordinalsimr_results.rds"),
file.path(output_folder, "report_template.Rmd")
)

try({
utils::zip(
zipfile = file,
files = zip_files
# flags = '-r9Xb'
)
})

unlink(output_folder, recursive = TRUE, force = TRUE)
download_counter_zip(download_counter_zip() + 1)

},
contentType = "application/zip"
)
output$download_report <- downloadHandler(
filename = function() {
paste0(
"ordinalsimr_session_", strtrim(session$token, 8),
"_download_", download_counter_zip(),
".zip"
)
},
content = function(file) {
output_folder <- file.path(paste0(
"ordinalsimr_session_", strtrim(session$token, 8),
"_download_", download_counter_zip()
))
dir.create(output_folder, showWarnings = FALSE)

try({
write(
custom_report(),
file.path(output_folder, "completed_report.html")
)
})
try({
saveRDS(
formatted_data(),
file.path(output_folder, "ordinalsimr_results.rds")
)
})
try({
write(
readLines(system.file("report_template.Rmd", package = "ordinalsimr")),
file.path(output_folder, "report_template.Rmd")
)
})

zip_files <- c(
file.path(output_folder, "completed_report.html"),
file.path(output_folder, "ordinalsimr_results.rds"),
file.path(output_folder, "report_template.Rmd")
)

try({
utils::zip(
zipfile = file,
files = zip_files
# flags = '-r9Xb'
)
})

unlink(output_folder, recursive = TRUE, force = TRUE)
download_counter_zip(download_counter_zip() + 1)
},
contentType = "application/zip"
)
})
}

Expand Down
2 changes: 1 addition & 1 deletion R/mod_sample_probabilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod_sample_probabilities_ui <- function(id) {
ns <- NS(id)

default_ratio <- tryCatch(
getOption("ordinalsimr.default_ratio", default = "50:50") ,
getOption("ordinalsimr.default_ratio", default = "50:50"),
error = function(e) {
"50:50"
}
Expand Down
51 changes: 28 additions & 23 deletions R/mod_save_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,39 @@ mod_save_data_server <- function(id, input_data, processed_data, rng_info, input
h5("Excel Download:"),
p("Please install the {writexl} package.")
)
}
})
}
})

download_counter_excel <- reactiveVal(1)
output$save_xlsx <- downloadHandler(
filename = function() {
paste0("data-", Sys.Date(), "-", strtrim(session$token, 6), "-", download_counter_excel(), ".xlsx")
},
content = function(file) {
writexl::write_xlsx(
list(
distribution_statistics = data_to_save()$comparison_data$distribution_statistics,
comparison_run_info = data_to_save()$comparison_data$run_info,
group1_type1_error = data_to_save()$group1_data$group1_t1error,
group1_run_info = data_to_save()$group1_data$run_info,
group2_type1_error = data_to_save()$group2_data$group2_t1error,
group2_run_info = data_to_save()$group2_data$run_info
) %>%
lapply(function(x) {if (is.null(x)) {data.frame()} else {x}}),
path = file
)
# increment download number
download_counter_excel(download_counter_excel() + 1)
}
)
filename = function() {
paste0("data-", Sys.Date(), "-", strtrim(session$token, 6), "-", download_counter_excel(), ".xlsx")
},
content = function(file) {
writexl::write_xlsx(
list(
distribution_statistics = data_to_save()$comparison_data$distribution_statistics,
comparison_run_info = data_to_save()$comparison_data$run_info,
group1_type1_error = data_to_save()$group1_data$group1_t1error,
group1_run_info = data_to_save()$group1_data$run_info,
group2_type1_error = data_to_save()$group2_data$group2_t1error,
group2_run_info = data_to_save()$group2_data$run_info
) %>%
lapply(function(x) {
if (is.null(x)) {
data.frame()
} else {
x
}
}),
path = file
)
# increment download number
download_counter_excel(download_counter_excel() + 1)
}
)

return(data_to_save)

})
}

Expand Down
19 changes: 8 additions & 11 deletions R/mod_simulation_inputs_page.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ mod_simulation_inputs_page_ui <- function(id) {
layout_columns(
fill = TRUE,
fillable = TRUE,
col_widths = c(-1,10,-1,-1,10,-1),
col_widths = c(-1, 10, -1, -1, 10, -1),
row_heights = c(9, 7),

card(
card_header("Data Entry", class = "bg-dark"),
layout_sidebar(
Expand All @@ -37,29 +36,27 @@ mod_simulation_inputs_page_ui <- function(id) {
"Core Inputs",
card_title("Iterations, Samples, and Tests"),
layout_column_wrap(
width = 1/3,
mod_iterations_ui("iterations_1"),
mod_sample_size_ui("sample_size_1"),
mod_sample_probabilities_ui("sample_probabilities_1")
width = 1 / 3,
mod_iterations_ui("iterations_1"),
mod_sample_size_ui("sample_size_1"),
mod_sample_probabilities_ui("sample_probabilities_1")
),
layout_column_wrap(
width = 1,
mod_select_tests_ui("select_tests_1")
)
mod_select_tests_ui("select_tests_1")
)
),

nav_panel(
"Type I Erorr",
card_title("TI Error by Group"),
mod_type_one_error_ui("type_one_error_1")
),

nav_panel(
"RNG Options",
card_title("Advanced: Random Number Generator Adjustments"),
markdown("These Random Number Generators are advanced options, and they use the default values employed by R as of version 4.4. Run `?RNGkind` in an R session to see the associated help file."),
layout_column_wrap(
width = 1/3,
width = 1 / 3,
!!!mod_rng_option_ui("rng_option_1")
)
)
Expand Down
2 changes: 1 addition & 1 deletion R/mod_start_simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod_start_simulation_ui <- function(id) {
ns <- NS(id)
tagList(
actionButton(ns("run_button"), "Run Tests") %>%
tagAppendAttributes(class="btn btn-success")
tagAppendAttributes(class = "btn btn-success")
)
}

Expand Down
69 changes: 34 additions & 35 deletions R/run_simulations.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,42 @@ run_simulations <- function(sample_size, sample_prob, prob0, prob1, niter, inclu
)


lapply(sample_size, function(x) {
sample_size_nested <- x
initial_groups <- lapply(1:niter, function(x) {
assign_groups(
sample_size = sample_size_nested,
sample_prob = sample_prob,
prob0 = prob0, prob1 = prob1,
seed = x,
.rng_kind = .rng_kind,
.rng_normal_kind = .rng_normal_kind,
.rng_sample_kind = .rng_sample_kind
)
})
lapply(sample_size, function(x) {
sample_size_nested <- x
initial_groups <- lapply(1:niter, function(x) {
assign_groups(
sample_size = sample_size_nested,
sample_prob = sample_prob,
prob0 = prob0, prob1 = prob1,
seed = x,
.rng_kind = .rng_kind,
.rng_normal_kind = .rng_normal_kind,
.rng_sample_kind = .rng_sample_kind
)
})

p_values <- initial_groups %>%
sapply(., function(x) ordinal_tests(x[["x"]], x[["y"]], included = included)) %>%
t()
p_values <- initial_groups %>%
sapply(., function(x) ordinal_tests(x[["x"]], x[["y"]], included = included)) %>%
t()

initial_groups_formatted <- lapply(initial_groups, function(groups) {
tibble(
y = list(groups[["y"]]), x = list(groups[["x"]]),
n_null = groups[["n_null"]], n_intervene = groups[["n_intervene"]],
sample_size = groups[["sample_size"]], K = groups[["K"]]
)
}) %>%
bind_rows() %>%
mutate(run = row_number(), .before = .data$y)

if (shiny::isRunning()) {
incProgress(
1/(max(sample_size)-min(sample_size)),
detail = paste("Sample size", sample_size_nested, "completed.")
)
}

return(sim_results_table = bind_cols(p_values, initial_groups_formatted))
initial_groups_formatted <- lapply(initial_groups, function(groups) {
tibble(
y = list(groups[["y"]]), x = list(groups[["x"]]),
n_null = groups[["n_null"]], n_intervene = groups[["n_intervene"]],
sample_size = groups[["sample_size"]], K = groups[["K"]]
)
}) %>%
magrittr::set_names(paste0("sample_size_", sample_size))
bind_rows() %>%
mutate(run = row_number(), .before = .data$y)

if (shiny::isRunning()) {
incProgress(
1 / (max(sample_size) - min(sample_size)),
detail = paste("Sample size", sample_size_nested, "completed.")
)
}

return(sim_results_table = bind_cols(p_values, initial_groups_formatted))
}) %>%
magrittr::set_names(paste0("sample_size_", sample_size))
}
Loading

0 comments on commit 98f5c6c

Please sign in to comment.