Skip to content

Commit

Permalink
fix for check-r-package@v2
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsmechtel committed Feb 27, 2024
1 parent ae9c4f7 commit dae2575
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
23 changes: 10 additions & 13 deletions R/calculate_anova.R
Expand Up @@ -37,16 +37,17 @@
#' )
#' metalyzer_se <- filterMetaData(
#' metalyzer_se,
#' Tissue == "Drosophila"
#' Tissue == "Drosophila",
#' Extraction_Method %in% c(1,2,3)
#' )
#' metalyzer_se <- calculate_anova(
#' metalyzer_se,
#' categorical = "Extraction_Method",
#' groups = c("Metabolite"),
#' impute_perc_of_min = 0.2,
#' impute_NA = FALSE
#' impute_NA = TRUE
#' )
calculate_anova <- function(metalyzer_se, categorical, groups = NULL, impute_perc_of_min = 0.2, impute_NA = FALSE) {
calculate_anova <- function(metalyzer_se, categorical, groups = NULL, impute_perc_of_min = 0.2, impute_NA = TRUE) {
## Check for agricolae installation
# installed_packages <- utils::installed.packages()[, "Package"]
# if (! "agricolae" %in% installed_packages) {
Expand Down Expand Up @@ -88,8 +89,8 @@ calculate_anova <- function(metalyzer_se, categorical, groups = NULL, impute_per
paste(groups(anova_data), collapse = " * "), ")... "))
anova_data <- mutate(anova_data, ANOVA_Group = calc_anova(.data$Categorical,
.data$log2_Conc))
# c_vec <- filter(anova_data, Tissue == "Drosophila", Metabolite == "Nitro-Tyr")$Categorical
# d_vec <- filter(anova_data, Tissue == "Drosophila", Metabolite == "Nitro-Tyr")$log2_Conc
# c_vec <- filter(anova_data, Tissue == "Drosophila", Metabolite == "Cer(d18:1/23:0)")$Categorical
# d_vec <- filter(anova_data, Tissue == "Drosophila", Metabolite == "Cer(d18:1/23:0)")$log2_Conc
cat("finished!\n")

if (any(aggregated_data$Concentration != anova_data$Concentration, na.rm = TRUE)) {
Expand Down Expand Up @@ -122,14 +123,10 @@ calc_anova <- function(c_vec, d_vec) {
## -> no imputation
## -> log2 transformation = NA
## -> no ANOVA is calculated (output: NA)

## filter out NA
mask <- !is.na(d_vec)
# c_vec <- c_vec[mask]
# d_vec <- d_vec[mask]

if (sum(!is.na(d_vec)) == 0 | length(unique(c_vec[mask])) < 2) {
## less than two levels

# Check if all values in d_vec are NA or c_vec has less than two levels
if (any(is.na(d_vec)) | length(unique(c_vec)) < 2) {
# Return a placeholder value indicating ANOVA couldn't be performed
group_vec <- rep(NA, length(c_vec))
} else {
tmp_df <- data.frame(Categorical = as.character(c_vec),
Expand Down
7 changes: 4 additions & 3 deletions man/calculate_anova.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/MetAlyzer_User_Guide.Rmd
Expand Up @@ -187,7 +187,7 @@ metalyzer_se <- calculate_anova(
categorical = "Extraction_Method",
groups = c("Tissue", "Metabolite"),
impute_perc_of_min = 0.2,
impute_NA = FALSE
impute_NA = TRUE
)
aggregated_data <- aggregatedData(metalyzer_se) %>%
Expand Down

0 comments on commit dae2575

Please sign in to comment.