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

Increase package test coverage #120

Merged
merged 4 commits into from
Apr 24, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions R/adat2eSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
adat2eSet <- function(adat) {

if ( !requireNamespace("Biobase", quietly = TRUE) ) {
# nocov start
stop(
"The `Biobase` package is required to use this function.\n",
"See ?adat2eSet for installation instructions.", call. = FALSE
)
# nocov end
}

stopifnot("`adat` must have intact attributes." = is_intact_attr(adat))
Expand Down
25 changes: 19 additions & 6 deletions R/groupGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,23 @@ Summary.soma_adat <- function(..., na.rm = FALSE) {
args <- lapply(list(...), function(x) {
if ( is.soma_adat(x) ) {
data.matrix(x[, getAnalytes(x)])
.apts <- getAnalytes(x)
rfu <- x[, .apts]
mode_ok <- vapply(rfu, function(.x) {
is.numeric(.x) || is.complex(.x) || is.logical(.x)
}, NA)
if ( !all(mode_ok) ) {
warning(
"Non-numeric variable(s) detected in `soma_adat` object ",
"where RFU values should be. Removing: ",
.value(names(rfu[, .apts])[!mode_ok]), ".", call. = FALSE
)
}
data.matrix(rfu[, mode_ok])
} else if ( !is.numeric(x) && !is.logical(x) && !is.complex(x) ) {
stop(deparse(.Generic),
" is only defined on a `soma_adat` with all numeric-alike variables.",
call. = FALSE
stop("`", .Generic, "()`",
" is only defined on a `soma_adat` with all numeric-alike variables.",
call. = FALSE
)
} else {
x
Expand Down Expand Up @@ -197,11 +210,11 @@ Summary.soma_adat <- function(..., na.rm = FALSE) {
#' @export
Math.soma.adat <- function(x, ...) {
.msg <- paste(
"The", .value("soma.adat"), "class is now", .value("soma_adat"),
"\nPlease either:\n",
"The", .value("soma.adat"), "class is now", .value("soma_adat"), ".\n",
"Please either:\n",
" 1) Re-class with x <- addClass(x, 'soma_adat')\n",
" 2) Re-call 'x <- read_adat(file)' to pick up the new 'soma_adat' class.\n"
)
cat(.msg)
deprecate_stop("2019-01-31", "SomaDataIO::Math.soma.adat()")
deprecate_stop("(2019-01-31)", "SomaDataIO::Math.soma.adat()")
}
2 changes: 2 additions & 0 deletions R/pivotExpressionSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
pivotExpressionSet <- function(eSet) {

if ( !requireNamespace("Biobase", quietly = TRUE) ) {
# nocov start
stop(
"The `Biobase` package is required to use this function.\n",
"See ?adat2eSet for installation instructions.", call. = FALSE
)
# nocov end
}

# samples (rows) x features (cols); move rn -> 1st column
Expand Down
4 changes: 2 additions & 2 deletions R/read-annotations.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @examples
#' \dontrun{
#' # for example
#' file <- "~/Desktop/SomaScan_V4.1_7K_Annotated_Content_20210616.xlsx"
#' file <- "~/Downloads/SomaScan_11K_Annotated_Content.xlsx"
#' anno_tbl <- read_annotations(file)
#' }
#' @importFrom readxl read_xlsx
Expand Down Expand Up @@ -48,7 +48,7 @@ read_annotations <- function(file) {
# file modified
if ( !identical(md5_file, md5_true) ) {
warning(
"Checksum mismatch.", .value(basename(file)), " may have been modified.",
"Checksum mismatch. ", .value(basename(file)), " may have been modified.",
call. = FALSE
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/utils-read-adat.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ catchDims <- function(x, y) {
cli_rule(cr_bold("Trailing 2 RFU features"), line_col = "magenta")
)
nc <- ncol(rfu)
print(rfu[1:6, (nc - 1):nc])
print(head(as_tibble(rfu[, (nc - 1L):nc])))
writeLines(cli_rule(line_col = "green", line = 2))
invisible(NULL)
}
2 changes: 2 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.onLoad <- function(libname, pkgname) {
# this is to make the active binding switch between
# UTF-8 and ASCII symbol encodings
# nocov start
`%enc%` <- function(utf, ascii) {
if ( getOption("cli.unicode", TRUE) && l10n_info()$`UTF-8` ) {
utf
Expand All @@ -17,6 +18,7 @@
makeActiveBinding("symb_warn", function() "\u26A0" %enc% "!", pkgenv)
makeActiveBinding("symb_point", function() "\u276F" %enc% ">", pkgenv)
makeActiveBinding("symb_info", function() "\u2139" %enc% "i", pkgenv)
# nocov end
}

.onAttach <- function(libname, pkgname) {
Expand Down
2 changes: 1 addition & 1 deletion man/read_annotations.Rd

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

10 changes: 5 additions & 5 deletions tests/testthat/_snaps/S3-print.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `soma_adat` S3 print method returns known output
# `soma_adat` S3 print method returns expected default output

== SomaScan Data ===============================================================
SomaScan version V4 (5k)
Expand Down Expand Up @@ -35,7 +35,7 @@
# SampleDescription <chr>, ...
================================================================================

---
# `soma_adat` S3 print method returns expected head output

== SomaScan Data ===============================================================
SomaScan version V4 (5k)
Expand Down Expand Up @@ -67,7 +67,7 @@
# SampleDescription <chr>, ...
================================================================================

---
# `soma_adat` S3 print method returns expected `show_header = TRUE` output

== SomaScan Data ===============================================================
SomaScan version V4 (5k)
Expand Down Expand Up @@ -105,7 +105,7 @@
# i 20 more rows
================================================================================

---
# `soma_adat` S3 print method returns expected `grouped_df` output

== SomaScan Data ===============================================================
SomaScan version V4 (5k)
Expand Down Expand Up @@ -143,7 +143,7 @@
# AssayNotes <lgl>, ...
================================================================================

---
# `soma_adat` S3 print method returns expected broken attributes output

== SomaScan Data ===============================================================
SomaScan version unknown (NA)
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/_snaps/groupGenerics.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@
Output
================================================================================

# error conditions generate the expected output for deprecated `soma.adat`

Code
readLines(catfile)
Output
[1] "The 'soma.adat' class is now 'soma_adat' ."
[2] " Please either:"
[3] " 1) Re-class with x <- addClass(x, 'soma_adat')"
[4] " 2) Re-call 'x <- read_adat(file)' to pick up the new 'soma_adat' class."

28 changes: 28 additions & 0 deletions tests/testthat/_snaps/parseCheck.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# `parseCheck()` prints expected output

Code
specs
Output
[1] "== Parsing Specs ==============================================================="
[2] "• Table Begin '45'"
[3] "• Col.Meta Start '46'"
[4] "• Col.Meta Shift '35'"
[5] "• Header Row '66'"
[6] "• Rows of the Col Meta '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65'"
[7] "-- Col Meta -------------------------------------------------------------- 20 --"
[8] "i SeqId, SeqIdVersion, SomaId, TargetFullName, Target, UniProt, EntrezGeneID,"
[9] "i EntrezGeneSymbol, Organism, Units, Type, Dilution, PlateScale_Reference,"
[10] "i CalReference, Cal_Example_Adat_Set001, ColCheck,"
[11] "i CalQcRatio_Example_Adat_Set001_170255, QcReference_170255,"
[12] "i Cal_Example_Adat_Set002, CalQcRatio_Example_Adat_Set002_170255"
[13] "-- Row Meta -------------------------------------------------------------- 34 --"
[14] "i PlateId, PlateRunDate, ScannerID, PlatePosition, SlideId, Subarray, SampleId,"
[15] "i SampleType, PercentDilution, SampleMatrix, Barcode, Barcode2d, SampleName,"
[16] "i SampleNotes, AliquotingNotes, SampleDescription, AssayNotes, TimePoint,"
[17] "i ExtIdentifier, SsfExtId, SampleGroup, SiteId, TubeUniqueID, CLI,"
[18] "i HybControlNormScale, RowCheck, NormScale_20, NormScale_0_005, NormScale_0_5,"
[19] "i ANMLFractionUsed_20, ANMLFractionUsed_0_005, ANMLFractionUsed_0_5, Age, Sex"
[20] "-- Empty Strings Detected in Col.Meta ------------------------------------- ! --"
[21] "i They may be missing in: [1] \"'Spuriomers', 'HybControls'\""
[22] "== Parse Diagnostic Complete ==================================================="

47 changes: 47 additions & 0 deletions tests/testthat/_snaps/utils-read-adat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# `checkHeader()` prints expected output

Code
checkHeader(header, verbose = TRUE)
Message
v Header passed checks and traps

# .verbosity()` prints expected output

Code
.verbosity(adat, header)
Output
== Parsing Diagnostics =========================================================
Message
v ADAT version > 1.2
v Header skip > 41
v Table begin > 20
v Col.Meta start > 21
v Col.Meta shift > 35
v Is old ADAT > FALSE
v no. clinical variables > 34
v no. RFU variables > 5284
v Dim data matrix > 1 x 5318
v Dim Col.Meta (annot.) > 5284 x 20
Output
-- Head Col Meta ---------------------------------------------------------------
# A tibble: 6 x 20
SeqId SeqIdVersion SomaId TargetFullName Target UniProt EntrezGeneID
<chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 10000-28 3 SL019233 Beta-crystallin B2 CRBB2 P43320 1415
2 10001-7 3 SL002564 RAF proto-oncogene~ c-Raf P04049 5894
3 10003-15 3 SL019245 Zinc finger protei~ ZNF41 P51814 7592
4 10006-25 3 SL019228 ETS domain-contain~ ELK1 P19419 2002
5 10008-43 3 SL019234 Guanylyl cyclase-a~ GUC1A P43080 2978
6 10011-65 3 SL019246 Inositol polyphosp~ OCRL Q01968 4952
# i 13 more variables: EntrezGeneSymbol <chr>, Organism <chr>, Units <chr>,
# Type <chr>, Dilution <chr>, PlateScale_Reference <chr>, CalReference <chr>,
# Cal_Example_Adat_Set001 <chr>, ColCheck <chr>,
# CalQcRatio_Example_Adat_Set001_170255 <chr>, QcReference_170255 <chr>,
# Cal_Example_Adat_Set002 <chr>, CalQcRatio_Example_Adat_Set002_170255 <chr>
-- Trailing 2 RFU features -----------------------------------------------------
# A tibble: 1 x 2
seq.9997.12 seq.9999.1
<dbl> <dbl>
1 11983. 1741.
================================================================================