Skip to content

Commit

Permalink
Reduce tests that run on CRAN.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbailiss committed Oct 4, 2022
1 parent eefffc1 commit 23a4755
Show file tree
Hide file tree
Showing 24 changed files with 135 additions and 101 deletions.
8 changes: 4 additions & 4 deletions R/quickPivot.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ qpvt <- function(dataFrame, rows=NULL, columns=NULL, calculations=NULL,
#' @return A HTML widget.
#' @examples
#' qhpvt(bhmtrains, "TOC", "TrainCategory", "n()")
#' qhpvt(bhmtrains, "TOC", "TrainCategory",
#' \donttest{qhpvt(bhmtrains, "TOC", "TrainCategory",
#' c("Mean Speed"="mean(SchedSpeedMPH, na.rm=TRUE)",
#' "Std Dev Speed"="sd(SchedSpeedMPH, na.rm=TRUE)"),
#' formats=list("%.0f", "%.1f"),
#' totals=list("TOC"="All TOCs",
#' "TrainCategory"="All Categories"))
#' "TrainCategory"="All Categories"))}

qhpvt <- function(dataFrame, rows=NULL, columns=NULL, calculations=NULL,
theme=NULL, replaceExistingStyles=FALSE,
Expand Down Expand Up @@ -157,8 +157,8 @@ qhpvt <- function(dataFrame, rows=NULL, columns=NULL, calculations=NULL,
#' @return Latex.
#' @examples
#' qlpvt(bhmtrains, "TOC", "TrainCategory", "n()")
#' qlpvt(bhmtrains, "TOC", "TrainCategory", "n()",
#' caption="my caption", label="mylabel")
#' \donttest{qlpvt(bhmtrains, "TOC", "TrainCategory", "n()",
#' caption="my caption", label="mylabel")}

qlpvt <- function(dataFrame, rows=NULL, columns=NULL, calculations=NULL, ...) {
arguments <- list(...)
Expand Down
6 changes: 5 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
## Resubmission

The number of automated tests that run on CRAN has been significantly reduced - run-time is now 20% of previous run-time.

## Background

This package is written entirely in R with no external dependencies/components other than the packages listed in the DESCRIPTION file.
This update has not made any significant changes to the structure of the package or dependencies.
Development approach is aligned with practices described in:
http://r-pkgs.had.co.nz/
https://r-pkgs.org/

## Test environments

Expand Down
4 changes: 2 additions & 2 deletions man/qhpvt.Rd

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

4 changes: 2 additions & 2 deletions man/qlpvt.Rd

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

95 changes: 12 additions & 83 deletions tests/testthat/test-A-02-smokeTests.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ testScenarios <- function(description="test", releaseEvaluationMode="batch", rel
context("SMOKE TESTS")


scenarios <- testScenarios("smoke tests: bhmtrains basic pivot values", runAllForReleaseVersion=TRUE)
scenarios <- testScenarios("smoke tests: bhmtrains basic pivot")
for(i in 1:nrow(scenarios)) {
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
Expand All @@ -83,41 +83,17 @@ for(i in 1:nrow(scenarios)) {
pt$evaluatePivot()
# pt$renderPivot()
# cat(paste(as.vector(pt$cells$asMatrix()), sep=", ", collapse=", "))
res <- c(3079, 22865, 14487, 8594, 49025, 830, 63, 33792, NA, 34685, 3909, 22928, 48279, 8594, 83710)

expect_equal(pt$cells$asMatrix(), matrix(res, nrow=5))
})
}



scenarios <- testScenarios("smoke tests: bhmtrains basic pivot html", runAllForReleaseVersion=TRUE)
for(i in 1:nrow(scenarios)) {
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]

test_that(description, {

library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode,
compatibility=list(totalStyleIsCellStyle=TRUE))
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
# pt$renderPivot()
# prepStr(as.character(pt$getHtml()))
res <- c(3079, 22865, 14487, 8594, 49025, 830, 63, 33792, NA, 34685, 3909, 22928, 48279, 8594, 83710)
html <- "<table class=\"Table\">\n <tr>\n <th class=\"RowHeader\">&nbsp;</th>\n <th class=\"ColumnHeader\">Express Passenger</th>\n <th class=\"ColumnHeader\">Ordinary Passenger</th>\n <th class=\"ColumnHeader\">Total</th>\n </tr>\n <tr>\n <th class=\"RowHeader\">Arriva Trains Wales</th>\n <td class=\"Cell\">3079</td>\n <td class=\"Cell\">830</td>\n <td class=\"Cell\">3909</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">CrossCountry</th>\n <td class=\"Cell\">22865</td>\n <td class=\"Cell\">63</td>\n <td class=\"Cell\">22928</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">London Midland</th>\n <td class=\"Cell\">14487</td>\n <td class=\"Cell\">33792</td>\n <td class=\"Cell\">48279</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">Virgin Trains</th>\n <td class=\"Cell\">8594</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">8594</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">Total</th>\n <td class=\"Cell\">49025</td>\n <td class=\"Cell\">34685</td>\n <td class=\"Cell\">83710</td>\n </tr>\n</table>"

expect_equal(pt$cells$asMatrix(), matrix(res, nrow=5))
expect_identical(as.character(pt$getHtml()), html)
})
}


scenarios <- testScenarios("smoke tests: bhmtrains basic pivot values two levels")
scenarios <- testScenarios("smoke tests: bhmtrains basic pivot two levels")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
Expand All @@ -138,42 +114,17 @@ for(i in 1:nrow(scenarios)) {
pt$evaluatePivot()
# pt$renderPivot()
# cat(paste(as.vector(pt$cells$asMatrix()), sep=", ", collapse=", "))
res <- c(3079, 22133, 5638, 2137, 32987, NA, NA, 8849, 6457, 15306, NA, 732, NA, NA, 732, 3079, 22865, 14487, 8594, 49025, 830, 63, 5591, NA, 6484, NA, NA, 28201, NA, 28201, 830, 63, 33792, NA, 34685, 3909, 22928, 48279, 8594, 83710)

expect_equal(pt$cells$asMatrix(), matrix(res, nrow=5))
})
}


scenarios <- testScenarios("smoke tests: bhmtrains basic pivot html two levels")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]

test_that(description, {

library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode,
compatibility=list(totalStyleIsCellStyle=TRUE, noDataGroupNBSP=TRUE))
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addColumnDataGroups("PowerType")
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
# pt$renderPivot()
# prepStr(as.character(pt$getHtml()))
res <- c(3079, 22133, 5638, 2137, 32987, NA, NA, 8849, 6457, 15306, NA, 732, NA, NA, 732, 3079, 22865, 14487, 8594, 49025, 830, 63, 5591, NA, 6484, NA, NA, 28201, NA, 28201, 830, 63, 33792, NA, 34685, 3909, 22928, 48279, 8594, 83710)
html <- "<table class=\"Table\">\n <tr>\n <th class=\"RowHeader\" rowspan=\"2\">&nbsp;</th>\n <th class=\"ColumnHeader\" colspan=\"4\">Express Passenger</th>\n <th class=\"ColumnHeader\" colspan=\"3\">Ordinary Passenger</th>\n <th class=\"ColumnHeader\">Total</th>\n </tr>\n <tr>\n <th class=\"ColumnHeader\">DMU</th>\n <th class=\"ColumnHeader\">EMU</th>\n <th class=\"ColumnHeader\">HST</th>\n <th class=\"ColumnHeader\">Total</th>\n <th class=\"ColumnHeader\">DMU</th>\n <th class=\"ColumnHeader\">EMU</th>\n <th class=\"ColumnHeader\">Total</th>\n <th class=\"ColumnHeader\"></th>\n </tr>\n <tr>\n <th class=\"RowHeader\">Arriva Trains Wales</th>\n <td class=\"Cell\">3079</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">3079</td>\n <td class=\"Cell\">830</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">830</td>\n <td class=\"Cell\">3909</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">CrossCountry</th>\n <td class=\"Cell\">22133</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">732</td>\n <td class=\"Cell\">22865</td>\n <td class=\"Cell\">63</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">63</td>\n <td class=\"Cell\">22928</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">London Midland</th>\n <td class=\"Cell\">5638</td>\n <td class=\"Cell\">8849</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">14487</td>\n <td class=\"Cell\">5591</td>\n <td class=\"Cell\">28201</td>\n <td class=\"Cell\">33792</td>\n <td class=\"Cell\">48279</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">Virgin Trains</th>\n <td class=\"Cell\">2137</td>\n <td class=\"Cell\">6457</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">8594</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">8594</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">Total</th>\n <td class=\"Cell\">32987</td>\n <td class=\"Cell\">15306</td>\n <td class=\"Cell\">732</td>\n <td class=\"Cell\">49025</td>\n <td class=\"Cell\">6484</td>\n <td class=\"Cell\">28201</td>\n <td class=\"Cell\">34685</td>\n <td class=\"Cell\">83710</td>\n </tr>\n</table>"

expect_equal(pt$cells$asMatrix(), matrix(res, nrow=5))
expect_identical(as.character(pt$getHtml()), html)
})
}


scenarios <- testScenarios("smoke tests: bhmtrains basic pivot values two levels expanded")
scenarios <- testScenarios("smoke tests: bhmtrains basic pivot two levels expanded")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
Expand All @@ -183,33 +134,7 @@ for(i in 1:nrow(scenarios)) {

test_that(description, {

library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode,
compatibility=list(totalStyleIsCellStyle=TRUE))
pt$addData(bhmtrains)
pt$addColumnDataGroups("TrainCategory")
pt$addColumnDataGroups("PowerType", expandExistingTotals=TRUE)
pt$addRowDataGroups("TOC")
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
# pt$renderPivot()
# cat(paste(as.vector(pt$cells$asMatrix()), sep=", ", collapse=", "))
res <- c(3079, 22133, 5638, 2137, 32987, NA, NA, 8849, 6457, 15306, NA, 732, NA, NA, 732, 3079, 22865, 14487, 8594, 49025, 830, 63, 5591, NA, 6484, NA, NA, 28201, NA, 28201, 830, 63, 33792, NA, 34685, 3909, 22196, 11229, 2137, 39471, NA, NA, 37050, 6457, 43507, NA, 732, NA, NA, 732, 3909, 22928, 48279, 8594, 83710)

expect_equal(pt$cells$asMatrix(), matrix(res, nrow=5))
})
}


scenarios <- testScenarios("smoke tests: bhmtrains basic pivot html two levels expanded")
for(i in 1:nrow(scenarios)) {
if(!isDevelopmentVersion) break
evaluationMode <- scenarios$evaluationMode[i]
processingLibrary <- scenarios$processingLibrary[i]
description <- scenarios$description[i]
countFunction <- scenarios$countFunction[i]

test_that(description, {
skip_on_cran()

library(pivottabler)
pt <- PivotTable$new(processingLibrary=processingLibrary, evaluationMode=evaluationMode,
Expand All @@ -221,13 +146,17 @@ for(i in 1:nrow(scenarios)) {
pt$defineCalculation(calculationName="TotalTrains", summariseExpression=countFunction)
pt$evaluatePivot()
# pt$renderPivot()
# cat(paste(as.vector(pt$cells$asMatrix()), sep=", ", collapse=", "))
# prepStr(as.character(pt$getHtml()))
res <- c(3079, 22133, 5638, 2137, 32987, NA, NA, 8849, 6457, 15306, NA, 732, NA, NA, 732, 3079, 22865, 14487, 8594, 49025, 830, 63, 5591, NA, 6484, NA, NA, 28201, NA, 28201, 830, 63, 33792, NA, 34685, 3909, 22196, 11229, 2137, 39471, NA, NA, 37050, 6457, 43507, NA, 732, NA, NA, 732, 3909, 22928, 48279, 8594, 83710)
html <- "<table class=\"Table\">\n <tr>\n <th class=\"RowHeader\" rowspan=\"2\">&nbsp;</th>\n <th class=\"ColumnHeader\" colspan=\"4\">Express Passenger</th>\n <th class=\"ColumnHeader\" colspan=\"3\">Ordinary Passenger</th>\n <th class=\"ColumnHeader\" colspan=\"4\">Total</th>\n </tr>\n <tr>\n <th class=\"ColumnHeader\">DMU</th>\n <th class=\"ColumnHeader\">EMU</th>\n <th class=\"ColumnHeader\">HST</th>\n <th class=\"ColumnHeader\">Total</th>\n <th class=\"ColumnHeader\">DMU</th>\n <th class=\"ColumnHeader\">EMU</th>\n <th class=\"ColumnHeader\">Total</th>\n <th class=\"ColumnHeader\">DMU</th>\n <th class=\"ColumnHeader\">EMU</th>\n <th class=\"ColumnHeader\">HST</th>\n <th class=\"ColumnHeader\">Total</th>\n </tr>\n <tr>\n <th class=\"RowHeader\">Arriva Trains Wales</th>\n <td class=\"Cell\">3079</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">3079</td>\n <td class=\"Cell\">830</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">830</td>\n <td class=\"Cell\">3909</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">3909</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">CrossCountry</th>\n <td class=\"Cell\">22133</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">732</td>\n <td class=\"Cell\">22865</td>\n <td class=\"Cell\">63</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">63</td>\n <td class=\"Cell\">22196</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">732</td>\n <td class=\"Cell\">22928</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">London Midland</th>\n <td class=\"Cell\">5638</td>\n <td class=\"Cell\">8849</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">14487</td>\n <td class=\"Cell\">5591</td>\n <td class=\"Cell\">28201</td>\n <td class=\"Cell\">33792</td>\n <td class=\"Cell\">11229</td>\n <td class=\"Cell\">37050</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">48279</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">Virgin Trains</th>\n <td class=\"Cell\">2137</td>\n <td class=\"Cell\">6457</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">8594</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">2137</td>\n <td class=\"Cell\">6457</td>\n <td class=\"Cell\"></td>\n <td class=\"Cell\">8594</td>\n </tr>\n <tr>\n <th class=\"RowHeader\">Total</th>\n <td class=\"Cell\">32987</td>\n <td class=\"Cell\">15306</td>\n <td class=\"Cell\">732</td>\n <td class=\"Cell\">49025</td>\n <td class=\"Cell\">6484</td>\n <td class=\"Cell\">28201</td>\n <td class=\"Cell\">34685</td>\n <td class=\"Cell\">39471</td>\n <td class=\"Cell\">43507</td>\n <td class=\"Cell\">732</td>\n <td class=\"Cell\">83710</td>\n </tr>\n</table>"

expect_equal(pt$cells$asMatrix(), matrix(res, nrow=5))
expect_identical(as.character(pt$getHtml()), html)
})
}


if (requireNamespace("lubridate", quietly = TRUE)) {

scenarios <- testScenarios("smoke tests: calculation filters")
Expand Down
20 changes: 12 additions & 8 deletions tests/testthat/test-A-04-quickPivotTests.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ context("QUICK-PIVOT TESTS")

test_that("quick-pivot tests: qpvt pivot 1", {

skip_on_cran()

library(pivottabler)
pt <- qpvt(bhmtrains, "TOC", "TrainCategory", "n()", compatibility=list(totalStyleIsCellStyle=TRUE, explicitHeaderSpansOfOne=TRUE))
# pt$renderPivot()
Expand Down Expand Up @@ -166,16 +168,18 @@ if(isDevelopmentVersion) {
}


test_that("quick-pivot tests: qlpvt pivot 1", {
if(isDevelopmentVersion) {
test_that("quick-pivot tests: qlpvt pivot 1", {

library(pivottabler)
lchr <- qlpvt(bhmtrains, "TOC", "TrainCategory", "n()", caption="my caption", label="mylabel",
compatibility=list(totalStyleIsCellStyle=TRUE, explicitHeaderSpansOfOne=TRUE))
# prepStr(lchr)
latex <- "\\begin{table}[h!]\n \\centering\n \\caption{my caption}\n \\label{tab:mylabel}\n \\begin{tabular}{|l|rrr|}\n \\hline\n & Express Passenger & Ordinary Passenger & Total\\\\\n \\hline\n Arriva Trains Wales & 3079 & 830 & 3909\\\\\n CrossCountry & 22865 & 63 & 22928\\\\\n London Midland & 14487 & 33792 & 48279\\\\\n Virgin Trains & 8594 & & 8594\\\\\n Total & 49025 & 34685 & 83710\\\\\n \\hline\n \\end{tabular}\n\\end{table}"
library(pivottabler)
lchr <- qlpvt(bhmtrains, "TOC", "TrainCategory", "n()", caption="my caption", label="mylabel",
compatibility=list(totalStyleIsCellStyle=TRUE, explicitHeaderSpansOfOne=TRUE))
# prepStr(lchr)
latex <- "\\begin{table}[h!]\n \\centering\n \\caption{my caption}\n \\label{tab:mylabel}\n \\begin{tabular}{|l|rrr|}\n \\hline\n & Express Passenger & Ordinary Passenger & Total\\\\\n \\hline\n Arriva Trains Wales & 3079 & 830 & 3909\\\\\n CrossCountry & 22865 & 63 & 22928\\\\\n London Midland & 14487 & 33792 & 48279\\\\\n Virgin Trains & 8594 & & 8594\\\\\n Total & 49025 & 34685 & 83710\\\\\n \\hline\n \\end{tabular}\n\\end{table}"

expect_identical(lchr, latex)
})
expect_identical(lchr, latex)
})
}


if(isDevelopmentVersion) {
Expand Down
Loading

0 comments on commit 23a4755

Please sign in to comment.