Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Didier/fix merge data multi loc prep #47

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: FielDHub
Title: A Shiny App for Design of Experiments in Life Sciences
Version: 1.3.7
Version: 1.3.8
Authors@R:
c(person(given = "Didier",
family = "Murillo",
Expand Down
2 changes: 1 addition & 1 deletion R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ app_ui <- function(request) {
tagList(
golem_add_external_resources(),
fluidPage(theme = shinythemes::shinytheme("flatly"),
navbarPage(title = "FielDHub v1.3.7",
navbarPage(title = "FielDHub v1.3.8",
tabPanel(
" Welcome!", icon = icon("home", lib = "glyphicon"),
suppressWarnings(
Expand Down
17 changes: 9 additions & 8 deletions R/fct_do_optim.R
Original file line number Diff line number Diff line change
Expand Up @@ -680,18 +680,19 @@ merge_user_data <- function(
) |>
dplyr::select(USER_ENTRY, ENTRY, NAME) |>
dplyr::left_join(y = iter_loc, by = "ENTRY")

if (inherits(optim_out, "MultiPrep")) {
data_input_mutated <- data_input_mutated |>
dplyr::select(.data = ., USER_ENTRY, NAME.x, REPS) |>
dplyr::arrange(dplyr::desc(REPS)) |>
dplyr::rename(ENTRY = USER_ENTRY, NAME = NAME.x)
dplyr::select(USER_ENTRY, NAME.x, REPS) |> # Just specify columns directly
dplyr::arrange(dplyr::desc(REPS)) |> # Arrange rows
dplyr::rename(ENTRY = USER_ENTRY, NAME = NAME.x) # Rename columns
} else if (inherits(optim_out, "Sparse")) {
data_input_mutated <- data_input_mutated |>
dplyr::filter(.data = ., !is.na(NAME.y)) |>
dplyr::select(USER_ENTRY, NAME.x) |>
dplyr::rename(ENTRY = USER_ENTRY, NAME = NAME.x)
}
dplyr::filter(!is.na(NAME.y)) |> # Filter rows
dplyr::select(USER_ENTRY, NAME.x) |> # Select columns
dplyr::rename(ENTRY = USER_ENTRY, NAME = NAME.x) # Rename columns
}

# Store the number of plots (It does not include checks)
df_to_check <- data_input_mutated[(input_checks + 1):nrow(data_input_mutated), ]
if (inherits(optim_out, "MultiPrep")) {
Expand Down
34 changes: 11 additions & 23 deletions R/utils_diagonals_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,22 @@ total_elements <- function(alist) {
length(unlist(alist))
}

#' @title Split Matrix Into Blocks
#' @title Split matrix Into sub matrices
#'
#' @description
#' Splits a matrix into a list of blocks, either by rows or by columns, based on the specified sizes of the blocks.
#'
#' @param Matrix A matrix to be split.
#' @param matrix_object A matrix to be split.
#' @param blocks Either a list or a vector indicating the sizes of the blocks to be split into.
#' If \code{blocks} is a list of vectors, each vector's length defines the size of the blocks.
#' If \code{blocks} is a vector, each element represents the size of a block.
#' @param byrow A logical value. If \code{TRUE} (the default), the matrix is split
#' by rows; otherwise, it is split by columns.
#' @return A list of matrices, each representing a block.
#' @noRd
split_matrix_into_blocks <- function(Matrix, blocks, byrow = TRUE) {
split_matrix_into_blocks <- function(matrix_object, blocks, byrow = TRUE) {

if (!is.matrix(Matrix)) {
if (!is.matrix(matrix_object)) {
stop("Input must be a matrix.")
}

Expand All @@ -156,32 +156,20 @@ split_matrix_into_blocks <- function(Matrix, blocks, byrow = TRUE) {
blocks_list = vector(mode="list", length=num_blocks)

# Validate the total size against the matrix dimension before the loop
if (byrow && size != nrow(Matrix)) {
stop("Number of rows in 'Matrix' does not match 'blocks'")
} else if (!byrow && size != ncol(Matrix)) {
stop("Number of columns in 'Matrix' does not match 'blocks'")
if (byrow && size != nrow(matrix_object)) {
stop("Number of rows in 'matrix_object' does not match 'blocks'")
} else if (!byrow && size != ncol(matrix_object)) {
stop("Number of columns in 'matrix_object' does not match 'blocks'")
}

# Use a loop to populate the blocks_list based on the 'byrow' flag
for (k in 1:num_blocks) {
if (byrow) {
blocks_list[[k]] = Matrix[from[k]:to[k], , drop = FALSE] # Ensuring the result is always a matrix
blocks_list[[k]] = matrix_object[from[k]:to[k], , drop = FALSE] # Ensuring the result is always a matrix
} else {
blocks_list[[k]] = Matrix[, from[k]:to[k], drop = FALSE] # Ensuring the result is always a matrix
blocks_list[[k]] = matrix_object[, from[k]:to[k], drop = FALSE] # Ensuring the result is always a matrix
}
}

return(blocks_list)
}

# for (k in 1:num_blocks) {
# if (byrow) {
# if (size != nrow(Matrix))
# stop("\nNumber of rows in 'Matrix' doesn't match 'blocks'")
# blocks_list[[k]] = Matrix[from[k]:to[k],]
# } else {
# if (size != ncol(Matrix))
# stop("\nNumber of columns in 'Matrix' doesn't match 'blocks'")
# blocks_list[[k]] = Matrix[,from[k]:to[k]]
# }
# }
}
Loading