Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JTPetter committed Nov 27, 2024
1 parent 3320c18 commit 515543a
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions R/processCapabilityStudies.R
Original file line number Diff line number Diff line change
Expand Up @@ -1315,15 +1315,15 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
if (nStages > 1) {
currentTableDf1 <- data.frame("Stage" = c(stageTitle, "", ""),
"Source" = c("ppm < LSL", "ppm > USL", "ppm total"),
"Observed" = format(round(observed, nDecimals), scientific = FALSE),
"Expected Overall" = format(round(expOverall, nDecimals), scientific = FALSE),
"Expected Within" = format(round(expWithin, nDecimals), scientific = FALSE))
"Observed" = .pcTableFormatNumbers(observed),
"Expected Overall" = .pcTableFormatNumbers(expOverall),
"Expected Within" = .pcTableFormatNumbers(expWithin))

} else {
currentTableDf1 <- data.frame("Source" = c("ppm < LSL", "ppm > USL", "ppm total"),
"Observed" = format(round(observed, nDecimals), scientific = FALSE),
"Expected Overall" = format(round(expOverall, nDecimals), scientific = FALSE),
"Expected Within" = format(round(expWithin, nDecimals), scientific = FALSE))
"Observed" = .pcTableFormatNumbers(observed),
"Expected Overall" = .pcTableFormatNumbers(expOverall),
"Expected Within" = .pcTableFormatNumbers(expWithin))
}

tableDf2 <- rbind(tableDf2, currentTableDf1)
Expand All @@ -1341,11 +1341,12 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {

currentTableDf2 <- data.frame("Stage" = c(gettextf("%s vs. BL", stage),"", "") ,
"Source" = c("ppm < LSL", "ppm > USL", "ppm total"),
"Observed" = format(round(observedComparison, nDecimals), scientific = FALSE),
"Expected Overall" = format(round(expOverallComparison, nDecimals), scientific = FALSE),
"Expected Within" = format(round(expWithinComparison, nDecimals), scientific = FALSE))
"Observed" = .pcTableFormatNumbers(observedComparison),
"Expected Overall" = .pcTableFormatNumbers(expOverallComparison),
"Expected Within" = .pcTableFormatNumbers(expWithinComparison))
tableDf2 <- rbind(tableDf2, currentTableDf2)


}
tableList2[[observedColName]] <- round(observed, nDecimals)
tableList2[[expOverallColName]] <- round(expOverall, nDecimals)
Expand Down Expand Up @@ -1864,13 +1865,13 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
if (nStages > 1) {
currentTableDf1 <- data.frame("Stage" = c(stageTitle, "", ""),
"Source" = c("ppm < LSL", "ppm > USL", "ppm total"),
"Observed" = format(round(observed, nDecimals), scientific = FALSE),
"Expected Overall" = format(round(expOverall, nDecimals), scientific = FALSE))
"Observed" = .pcTableFormatNumbers(observed),
"Expected Overall" = .pcTableFormatNumbers(expOverall))

} else {
currentTableDf1 <- data.frame("Source" = c("ppm < LSL", "ppm > USL", "ppm total"),
"Observed" = format(round(observed, nDecimals), scientific = FALSE),
"Expected Overall" = format(round(expOverall, nDecimals), scientific = FALSE))
"Observed" = .pcTableFormatNumbers(observed),
"Expected Overall" = .pcTableFormatNumbers(expOverall))
}

tableDf3 <- rbind(tableDf3, currentTableDf1)
Expand Down Expand Up @@ -2393,5 +2394,15 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
return(plotList)
}



.pcTableFormatNumbers <- function(number) {
if (all(is.na(number)) || all(is.null(number))) {
return(rep(NA, length(number)))
}
output <- formatC(number, format = "f", digits = .numDecimals)
output <- sub("\\.?0+$", "", output)
if (any(is.na(number)) || any(is.null(number))) {
naNumbers <- which(is.na(number) | is.null(number))
output[naNumbers] <- NA
}
return(output)
}

0 comments on commit 515543a

Please sign in to comment.