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

Refactored tcplPlot and auxiliary functions to support any number of curves on a comparison plot #325

Open
wants to merge 102 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
e78590f
215 add in changes from pr #275 return ggplot obj
cthunes Dec 5, 2024
6dc2e09
fixed title bug with truncation, arrangeGrob bug in compare (temp fix)
cthunes Dec 6, 2024
adac4b9
added sc test cases with verbose = FALSE after discovering bug
cthunes Dec 6, 2024
d8b902e
solved arrangeGrob bug, now compare plots can be returned as ggplot ob
cthunes Dec 9, 2024
4812a9a
add ggplot output test cases
cthunes Dec 9, 2024
b879acc
293 removed tcplggplot and tcplggplotCompare functions
cthunes Jan 13, 2025
c22ca7f
293 add tcplggplot2 function alongside various utility functions
cthunes Jan 13, 2025
4f89329
293 update tcplPlotLoadData to include flag_count for tcplggplot2
cthunes Jan 13, 2025
1b91aa3
293 update tcplPlotLoadData to pull wllts down for missing chem info
cthunes Jan 13, 2025
2c5d80a
293 updated tcplPlotLoadData to replace nulls and flip bmr and cutoff
cthunes Jan 13, 2025
bcfcb60
293 updated validation for new and old parameters for tcplPlot update
cthunes Jan 13, 2025
4fe13ee
293 add function tcplPlotCalcAspectRatio to determine w/h/nrow/ncol
cthunes Jan 13, 2025
7234133
293 updated tcplPlot to handle new dat structure and compare parameter
cthunes Jan 13, 2025
c4b1639
293 updated tcplPlotlyPlot to work with single or dual plots, or stop
cthunes Jan 13, 2025
e957555
293 added stop to legacyplot since it didn't work and it def won't now
cthunes Jan 13, 2025
6e5a053
293 update all documentation and imports
cthunes Jan 13, 2025
db31596
293 fix bug with importing well types when none are missing
cthunes Jan 15, 2025
3a983f5
293 updated data_raw/sc_test.R for refactored tcplPlot
cthunes Jan 15, 2025
5ddf2e0
293 updated data_raw/mc_test.R for refactored tcplPlot
cthunes Jan 15, 2025
95464ae
293 updated existing tests in test-tcplPlot.R for refactored tcplPlot
cthunes Jan 15, 2025
c97b60f
293 fix coff overwrite bug in 'sc' if hitc/max_med both < 0
cthunes Jan 16, 2025
3e44717
293 updated 'compare' param documentation for 'sc' default
cthunes Jan 17, 2025
2fce037
293 added small validation that 'output' cannot be NULL
cthunes Jan 17, 2025
1dfb874
293 removed other files' tests
cthunes Jan 17, 2025
99b15a8
293 test multiple length compare
cthunes Jan 17, 2025
b64162e
293 updated standalone plot tests to reflect how they work now
cthunes Jan 17, 2025
79ec0b7
293 add case for validating 'compare' and 'by' as actual col names
cthunes Jan 17, 2025
28ae030
293 moved tcplPlotLoadData tests into new file and added expectations
cthunes Jan 17, 2025
884681f
293 moved tcplPlotUtils tests into new file, expanded tcplPlotValidate
cthunes Jan 17, 2025
600b58c
293 create new files for testing tcplggplot2.R and tcplggplot2Utils.R
cthunes Jan 17, 2025
f8be7bd
293 remove suppressWarnings from tcplPlot tests
cthunes Jan 21, 2025
9456088
293 update conc_resp in tcplggplot2 to resolve warnings with NA concs
cthunes Jan 21, 2025
c3b2d43
293 reduce list in tcplPlotValidate to only potentially updated ones
cthunes Jan 21, 2025
e77019b
293 update mc_test with missing chem test case for new LoadWllt test
cthunes Jan 23, 2025
61f07e6
293 add tcplPlotCalcAspectRatio tests and related small bug fix
cthunes Jan 23, 2025
a09f74f
removed the 'mocked$compare.<some id>' in test which now aren't stored
cthunes Jan 23, 2025
366f840
293 add group.fld/threshold tests, fix related group.fld bug in sc
cthunes Jan 23, 2025
0f5029b
293 add tcplggplot2 tests, add warning for comparing if !verbose,flags
cthunes Jan 23, 2025
5c0678c
293 add tests for tcplggplot2Utils MORELETTERS, tcplfit2_fun, round_n
cthunes Jan 23, 2025
2fe4806
293 add tcplggplot2Utils tests for rest of functions
cthunes Jan 24, 2025
cf4d137
Update docs for verbose = TRUE default changes
cthunes Jan 24, 2025
3907264
293 variable binding and imports for devtools::check()
cthunes Jan 24, 2025
0a6464b
311 plotting update for loec data, for mc single, small, large compare
cthunes Jan 29, 2025
e1680ae
311 add unit tests for loec for single, small/large and mixed compare
cthunes Jan 29, 2025
b4ffd1d
311 GH actions failed mac and linux r cmd check, attempting fix
cthunes Jan 29, 2025
e849642
117 add limitsize = FALSE to ggsave for large plots
cthunes Feb 5, 2025
fe1ca0d
215 add in changes from pr #275 return ggplot obj
cthunes Dec 5, 2024
ed00650
fixed title bug with truncation, arrangeGrob bug in compare (temp fix)
cthunes Dec 6, 2024
d43669d
added sc test cases with verbose = FALSE after discovering bug
cthunes Dec 6, 2024
9b797e2
solved arrangeGrob bug, now compare plots can be returned as ggplot ob
cthunes Dec 9, 2024
ed3eaab
add ggplot output test cases
cthunes Dec 9, 2024
d9403a2
293 removed tcplggplot and tcplggplotCompare functions
cthunes Jan 13, 2025
8b5e255
new files for git rebase
cthunes Jan 13, 2025
23cf610
293 update tcplPlotLoadData to include flag_count for tcplggplot2
cthunes Jan 13, 2025
0caa00c
293 update tcplPlotLoadData to pull wllts down for missing chem info
cthunes Jan 13, 2025
b75e1af
293 updated tcplPlotLoadData to replace nulls and flip bmr and cutoff
cthunes Jan 13, 2025
4e98bad
293 updated validation for new and old parameters for tcplPlot update
cthunes Jan 13, 2025
28d3f70
293 add function tcplPlotCalcAspectRatio to determine w/h/nrow/ncol
cthunes Jan 13, 2025
4a0c933
293 updated tcplPlot to handle new dat structure and compare parameter
cthunes Jan 13, 2025
d062f16
293 updated tcplPlotlyPlot to work with single or dual plots, or stop
cthunes Jan 13, 2025
3f89b70
293 added stop to legacyplot since it didn't work and it def won't now
cthunes Jan 13, 2025
301a1a9
293 update all documentation and imports
cthunes Jan 13, 2025
a82ff8d
293 fix bug with importing well types when none are missing
cthunes Jan 15, 2025
47a3e91
293 updated data_raw/sc_test.R for refactored tcplPlot
cthunes Jan 15, 2025
8dd2984
293 updated data_raw/mc_test.R for refactored tcplPlot
cthunes Jan 15, 2025
be2f0fe
293 updated existing tests in test-tcplPlot.R for refactored tcplPlot
cthunes Jan 15, 2025
32abdd3
293 fix coff overwrite bug in 'sc' if hitc/max_med both < 0
cthunes Jan 16, 2025
07d6c72
some of the commits for git rebase
cthunes Jan 17, 2025
4159767
293 added small validation that 'output' cannot be NULL
cthunes Jan 17, 2025
749cfa9
293 removed other files' tests
cthunes Jan 17, 2025
224c597
293 test multiple length compare
cthunes Jan 17, 2025
f320e70
293 updated standalone plot tests to reflect how they work now
cthunes Jan 17, 2025
c20d59f
293 add case for validating 'compare' and 'by' as actual col names
cthunes Jan 17, 2025
840a869
293 moved tcplPlotLoadData tests into new file and added expectations
cthunes Jan 17, 2025
c2c218e
293 moved tcplPlotUtils tests into new file, expanded tcplPlotValidate
cthunes Jan 17, 2025
cd47876
293 create new files for testing tcplggplot2.R and tcplggplot2Utils.R
cthunes Jan 17, 2025
6195e12
293 remove suppressWarnings from tcplPlot tests
cthunes Jan 21, 2025
3f75a6d
293 update conc_resp in tcplggplot2 to resolve warnings with NA concs
cthunes Jan 21, 2025
f348a76
293 reduce list in tcplPlotValidate to only potentially updated ones
cthunes Jan 21, 2025
17cb647
some more commits from rebase
cthunes Jan 23, 2025
30d9b27
293 add tcplPlotCalcAspectRatio tests and related small bug fix
cthunes Jan 23, 2025
b2c636a
removed the 'mocked$compare.<some id>' in test which now aren't stored
cthunes Jan 23, 2025
6104036
293 add group.fld/threshold tests, fix related group.fld bug in sc
cthunes Jan 23, 2025
f803673
293 add tcplggplot2 tests, add warning for comparing if !verbose,flags
cthunes Jan 23, 2025
63a32c3
293 add tests for tcplggplot2Utils MORELETTERS, tcplfit2_fun, round_n
cthunes Jan 23, 2025
cf22b43
293 add tcplggplot2Utils tests for rest of functions
cthunes Jan 24, 2025
eb681d0
more commits for rebase
cthunes Jan 24, 2025
a9f785e
293 variable binding and imports for devtools::check()
cthunes Jan 24, 2025
cab30bd
more commits for rebase
cthunes Jan 29, 2025
c76d1e8
311 add unit tests for loec for single, small/large and mixed compare
cthunes Jan 29, 2025
9b83614
311 GH actions failed mac and linux r cmd check, attempting fix
cthunes Jan 29, 2025
ccb6de6
117 add limitsize = FALSE to ggsave for large plots
cthunes Feb 5, 2025
189a5a4
Rebase dev onto 311-update-tcplPlot-for-loec for actions update
cthunes Feb 6, 2025
b99a1e8
Merge branch 'dev' into 311-update-tcplPlot-for-loec
cthunes Feb 10, 2025
4e613f8
296 add examples to tcplPlot documentation for all new and old params
cthunes Feb 11, 2025
eac51d8
296 shortened lines to be under 100 characters for examples created
cthunes Feb 13, 2025
dba62ee
293 removed order code for compare.val, meaning updates to mc/sc_test
cthunes Feb 13, 2025
3969b83
improve plotting docs, especially tcplPlot details
cthunes Mar 4, 2025
57feafb
removed response points when style is for >= group.threshold
cthunes Mar 4, 2025
98f845a
improve temp pdf creation and counting in test-tcplPlot
cthunes Mar 5, 2025
f91cd8f
336 add parameter to tcplPlot hide_losing_models
cthunes Mar 5, 2025
fb13ad1
336 update tcplPlotlyPlot docs
cthunes Mar 5, 2025
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
Prev Previous commit
Next Next commit
add ggplot output test cases
cthunes committed Dec 9, 2024
commit 4812a9a2dd104b31547e0d246659f0514a355e93
103 changes: 103 additions & 0 deletions tests/testthat/test-tcplPlot.R
Original file line number Diff line number Diff line change
@@ -746,6 +746,109 @@ test_that("standalone advanced comparison plotting works in sc", {
file.remove(fn) # clean up
})

# "ggplot" output tests
test_that("ggplot output works in mc", {
data("mc_test")
mocked <- mc_test$plot_single_m4id
local_mocked_bindings(
tcplQuery = function(query, db, tbl) {
if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery
else mocked[query][[1]]
}
)
tcplConf(drvr = "MySQL", db = "invitrodb") # must include both
expect_no_error(suppressWarnings(otpt <- tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, output = "ggplot", flags = TRUE, fileprefix = "temp_tcplPlot")))
expect_true(ggplot2::is.ggplot(otpt))
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
expect_length(fn, 0) # no files should be generated
expect_no_error(suppressWarnings(otpt <- tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, output = "pdf", flags = TRUE, fileprefix = "temp_tcplPlot")))
expect_true(ggplot2::is.ggplot(otpt)) # single outputs now return ggplot as well
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
expect_length(fn, 1) # exactly one file created
file.remove(fn) # clean up
})

test_that("ggplot output comparison plotting works in mc", {
data("mc_test")
mocked <- mc_test$plot_single_m4id_compare
local_mocked_bindings(
tcplQuery = function(query, db, tbl) {
if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery
else mocked[query][[1]]
}
)
tcplConf(drvr = "MySQL", db = "invitrodb") # must include both
expect_no_error(suppressWarnings(otpt <- tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, compare.val = mocked$compare.m4id, output = "ggplot", flags = TRUE, fileprefix = "temp_tcplPlot")))
expect_true(ggplot2::is.ggplot(otpt))
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
expect_length(fn, 0) # no files should be generated
expect_no_error(suppressWarnings(otpt <- tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, compare.val = mocked$compare.m4id, output = "pdf", flags = TRUE, fileprefix = "temp_tcplPlot")))
expect_true(ggplot2::is.ggplot(otpt)) # single outputs now return ggplot as well
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
expect_length(fn, 1) # exactly one file created
file.remove(fn) # clean up
})

test_that("ggplot output works in sc", {
data("sc_test")
mocked <- sc_test$plot_single_s2id
local_mocked_bindings(
tcplQuery = function(query, db, tbl) {
if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery
else mocked[query][[1]]
}
)
tcplConf(drvr = "MySQL", db = "invitrodb") # must include both
expect_no_error(suppressWarnings(otpt <- tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, output = "ggplot", fileprefix = "temp_tcplPlot")))
expect_true(ggplot2::is.ggplot(otpt))
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
expect_length(fn, 0) # no files should be generated
expect_no_error(suppressWarnings(otpt <- tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, output = "pdf", fileprefix = "temp_tcplPlot")))
expect_true(ggplot2::is.ggplot(otpt)) # single outputs now return ggplot as well
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
expect_length(fn, 1) # exactly one file created
file.remove(fn) # clean up
})

test_that("ggplot output comparison plotting works in sc", {
data("sc_test")
mocked <- sc_test$plot_single_s2id_compare
local_mocked_bindings(
tcplQuery = function(query, db, tbl) {
if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery
else mocked[query][[1]]
}
)
tcplConf(drvr = "MySQL", db = "invitrodb") # must include both
expect_no_error(suppressWarnings(otpt <- tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, compare.val = mocked$compare.s2id, output = "ggplot", fileprefix = "temp_tcplPlot")))
expect_true(ggplot2::is.ggplot(otpt))
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
expect_length(fn, 0) # no files should be generated
expect_no_error(suppressWarnings(otpt <- tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, compare.val = mocked$compare.s2id, output = "pdf", fileprefix = "temp_tcplPlot")))
expect_true(ggplot2::is.ggplot(otpt)) # single outputs now return ggplot as well
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
expect_length(fn, 1) # exactly one file created
file.remove(fn) # clean up
})

test_that("ggplot output returns specific warnings and errors", {
data("mc_test")
mocked <- mc_test$plot_multiple_m4id
local_mocked_bindings(
tcplQuery = function(query, db, tbl) {
if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery
else mocked[query][[1]]
}
)
tcplConf(drvr = "MySQL", db = "invitrodb") # must include both
expect_error(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, output = "ggplot", flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"),
"More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of plots to 1. Current number of individual plots: 2")
mocked <- mc_test$plot_single_m4id
expect_message(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, output = "ggplot", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot")),
"ggplot object and verbose table arranged into gtable object. To work with a simple ggplot object, set `verbose = FALSE`.")
fn <- stringr::str_subset(list.files(), "^temp_tcplPlot")
expect_length(fn, 0) # no files should be generated
})


#-------------------------------------------------------------------------------