From 7934950d7b3a2ca2388ee5c67bcb015c1400027f Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Thu, 16 Apr 2026 18:57:48 +0200 Subject: [PATCH 01/38] refactor: batch-10 server-side splines, tables, misc functions --- R/elsplineDS.R | 2 +- R/getWGSRDS.R | 10 +++++---- R/hetcorDS.R | 2 +- R/lexisDS1.R | 2 +- R/lexisDS2.R | 24 +++++++++++++-------- R/lsplineDS.R | 2 +- R/metadataDS.R | 2 +- R/nsDS.R | 2 +- R/qlsplineDS.R | 2 +- R/rowColCalcDS.R | 14 +++++++------ R/tableDS.R | 8 +++---- R/tableDS.assign.R | 6 +++--- R/tableDS2.R | 10 ++++----- R/tapplyDS.R | 12 ++++++----- R/tapplyDS.assign.R | 29 +++++++++++++------------- man/rowColCalcDS.Rd | 4 ++-- tests/testthat/test-smk-rowColCalcDS.R | 8 +++---- 17 files changed, 75 insertions(+), 64 deletions(-) diff --git a/R/elsplineDS.R b/R/elsplineDS.R index c4dcfda8..7b30dd7e 100644 --- a/R/elsplineDS.R +++ b/R/elsplineDS.R @@ -54,7 +54,7 @@ elsplineDS <- function(x = x, n = n, marginal = FALSE, names = NULL){ structure(rval, knots = knots, marginal = marginal, class = c("lspline", "matrix")) } - x <- eval(parse(text=x), envir = parent.frame()) + x <- .loadServersideObject(x) stopifnot(n >= 2) k <- seq(min(x, na.rm = TRUE), max(x, na.rm = TRUE), length.out = n + 1)[-c(1, n + 1)] diff --git a/R/getWGSRDS.R b/R/getWGSRDS.R index 225ce433..7b27a35c 100644 --- a/R/getWGSRDS.R +++ b/R/getWGSRDS.R @@ -53,11 +53,13 @@ #' getWGSRDS <- function(sex, firstPart, secondPart, index, standing=NA, thirdPart=NA){ - sex <- eval(parse(text=sex), envir = parent.frame()) - firstPart <- eval(parse(text=firstPart), envir = parent.frame()) - secondPart <- eval(parse(text=secondPart), envir = parent.frame()) + sex <- .loadServersideObject(sex) + firstPart <- .loadServersideObject(firstPart) + if (!is.na(secondPart)){ + secondPart <- .loadServersideObject(secondPart) + } if (!is.na(thirdPart)){ - thirdPart <- eval(parse(text=thirdPart), envir = parent.frame()) + thirdPart <- .loadServersideObject(thirdPart) } # access the internal reference data diff --git a/R/hetcorDS.R b/R/hetcorDS.R index d561ce30..61b4f4cf 100644 --- a/R/hetcorDS.R +++ b/R/hetcorDS.R @@ -28,7 +28,7 @@ #' hetcorDS <- function(data, ML, std.err, bins, pd, use){ - data <- eval(parse(text=data), envir = parent.frame()) + data <- .loadServersideObject(data) out <- polycor::hetcor(data = data, ML = ML, std.err = std.err, bins = bins, pd = pd, use = use) diff --git a/R/lexisDS1.R b/R/lexisDS1.R index 6c0f8de7..8a1aac9c 100644 --- a/R/lexisDS1.R +++ b/R/lexisDS1.R @@ -28,7 +28,7 @@ lexisDS1 <- function(exitCol=NULL){ stop(errorMessage, call. = FALSE) } - exposure <- eval(parse(text=exitCol), envir = parent.frame()) + exposure <- .loadServersideObject(exitCol) max.time <- max(exposure, na.rm=TRUE) random.multiplier <- stats::runif(1,1.01,1.05) diff --git a/R/lexisDS2.R b/R/lexisDS2.R index d63989d2..02f8168f 100644 --- a/R/lexisDS2.R +++ b/R/lexisDS2.R @@ -46,10 +46,10 @@ lexisDS2 <- function(datatext=NULL, intervalWidth, maxmaxtime, idCol, entryCol, #nfilter.string<-as.numeric(thr$nfilter.string) ############################################################# - starttime <- eval(parse(text=entryCol), envir = parent.frame()) - endtime <- eval(parse(text=exitCol), envir = parent.frame()) - cens <- eval(parse(text=statusCol), envir = parent.frame()) - id.orig <- eval(parse(text=idCol), envir = parent.frame()) + starttime <- .loadServersideObject(entryCol) + endtime <- .loadServersideObject(exitCol) + cens <- .loadServersideObject(statusCol) + id.orig <- .loadServersideObject(idCol) starttime <- as.numeric(starttime) endtime <- as.numeric(endtime) @@ -74,13 +74,19 @@ lexisDS2 <- function(datatext=NULL, intervalWidth, maxmaxtime, idCol, entryCol, #IDENTIFY VARIABLES TO BE CARRIED WITH THE EXPANDED SURVIVAL DATA if(is.null(vartext)){ - datatext2<-paste0("data.frame(",datatext,")") - DF <- eval(parse(text=datatext2), envir = parent.frame()) + col.names <- unlist(strsplit(datatext, split=",")) + col.list <- vector("list", length(col.names)) + for(i in seq_along(col.names)) col.list[[i]] <- .loadServersideObject(col.names[i]) + DF <- data.frame(col.list) + colnames(DF) <- col.names } - + if(!is.null(vartext)){ - vartext2<-paste0("data.frame(",vartext,")") - DF<-eval(parse(text=vartext2), envir = parent.frame()) + col.names <- unlist(strsplit(vartext, split=",")) + col.list <- vector("list", length(col.names)) + for(i in seq_along(col.names)) col.list[[i]] <- .loadServersideObject(col.names[i]) + DF <- data.frame(col.list) + colnames(DF) <- col.names } if(is.null(datatext)&&is.null(vartext)){ diff --git a/R/lsplineDS.R b/R/lsplineDS.R index 86475bba..d8dbce8c 100644 --- a/R/lsplineDS.R +++ b/R/lsplineDS.R @@ -51,7 +51,7 @@ lsplineDS <- function(x = x, knots = NULL, marginal = FALSE, names = NULL){ structure(rval, knots = knots, marginal = marginal, class = c("lspline", "matrix")) } - x <- eval(parse(text=x), envir = parent.frame()) + x <- .loadServersideObject(x) out <- lspline_copy(x = x, knots = knots, marginal = marginal, names = names) diff --git a/R/metadataDS.R b/R/metadataDS.R index a416ed61..3c303176 100644 --- a/R/metadataDS.R +++ b/R/metadataDS.R @@ -16,7 +16,7 @@ metadataDS <- function(x) if ((! is.character(x)) || (length(x) != 1)) stop("Variable's name isn't be single character vector", call. = FALSE) - x.var <- eval(parse(text=x), envir = parent.frame()) + x.var <- .loadServersideObject(x) if (is.null(x.var)) stop("Variable can't be NULL", call. = FALSE) diff --git a/R/nsDS.R b/R/nsDS.R index 6314c4b8..a12227c6 100644 --- a/R/nsDS.R +++ b/R/nsDS.R @@ -33,7 +33,7 @@ nsDS <- function(x, df, knots, intercept, Boundary.knots){ thr <- dsBase::listDisclosureSettingsDS() nfilter.tab <- as.numeric(thr$nfilter.tab) - x <- eval(parse(text=x), envir = parent.frame()) + x <- .loadServersideObject(x) if(is.null(Boundary.knots)){ Boundary.knots <- range(x, na.rm=TRUE) diff --git a/R/qlsplineDS.R b/R/qlsplineDS.R index 3df267f8..254b09c9 100644 --- a/R/qlsplineDS.R +++ b/R/qlsplineDS.R @@ -59,7 +59,7 @@ qlsplineDS <- function(x = x, q = q, na.rm = TRUE, marginal = FALSE, names = NUL structure(rval, knots = knots, marginal = marginal, class = c("lspline", "matrix")) } - x <- eval(parse(text=x), envir = parent.frame()) + x <- .loadServersideObject(x) if (length(q) == 1 && q >= 2) { q <- seq(0, 1, length.out = q + 1)[-c(1, q + 1)] diff --git a/R/rowColCalcDS.R b/R/rowColCalcDS.R index e7a35832..396f8d9f 100644 --- a/R/rowColCalcDS.R +++ b/R/rowColCalcDS.R @@ -4,15 +4,17 @@ #' 'rowMeans' and 'colMeans'. #' @details the output is returned to the user only the number of entries in the #' output vector is greater or equal to the allowed size. -#' @param dataset an array of two or more dimensions. +#' @param dataset.name a character string providing the name of a server-side array of two or more dimensions. #' @param operation an integer that indicates the operation to carry out: #' 1 for 'rowSums', 2 for 'colSums', 3 for 'rowMeans' or 4 for 'colMeans' #' @return a numeric vector #' @export #' @author Gaye, A. #' -rowColCalcDS <- function (dataset, operation) { - +rowColCalcDS <- function (dataset.name, operation) { + + dataset <- .loadServersideObject(dataset.name) + if(operation == 1){ result <- rowSums(dataset, na.rm=TRUE) } @@ -25,7 +27,7 @@ rowColCalcDS <- function (dataset, operation) { if(operation == 4){ result <- colMeans(dataset, na.rm=TRUE) } - + # check if the output is valid (i.e. meets DataSHIELD criteria) check <- isValidDS(result) if(check){ @@ -34,7 +36,7 @@ rowColCalcDS <- function (dataset, operation) { resultNA <- rep(NA, length(result)) return(resultNA) } - + return(result) - + } \ No newline at end of file diff --git a/R/tableDS.R b/R/tableDS.R index c190ffc3..6f059f52 100644 --- a/R/tableDS.R +++ b/R/tableDS.R @@ -55,7 +55,7 @@ nfilter.tab<-as.numeric(thr$nfilter.tab) # if(!is.null(force.nfilter.transmit)) { -force.nfilter.active<-eval(parse(text=force.nfilter.transmit), envir = parent.frame()) +force.nfilter.active<-.loadServersideObject(force.nfilter.transmit) if(force.nfilter.active Date: Thu, 16 Apr 2026 19:26:54 +0200 Subject: [PATCH 02/38] refactor: add server-side .checkClass for getWGSRDS, rowColCalcDS --- R/getWGSRDS.R | 7 +++++++ R/rowColCalcDS.R | 1 + 2 files changed, 8 insertions(+) diff --git a/R/getWGSRDS.R b/R/getWGSRDS.R index 7b27a35c..c308d6d8 100644 --- a/R/getWGSRDS.R +++ b/R/getWGSRDS.R @@ -53,13 +53,20 @@ #' getWGSRDS <- function(sex, firstPart, secondPart, index, standing=NA, thirdPart=NA){ + sex.name <- sex + firstPart.name <- firstPart sex <- .loadServersideObject(sex) firstPart <- .loadServersideObject(firstPart) + .checkClass(obj = firstPart, obj_name = firstPart.name, permitted_classes = c("numeric", "integer")) if (!is.na(secondPart)){ + secondPart.name <- secondPart secondPart <- .loadServersideObject(secondPart) + .checkClass(obj = secondPart, obj_name = secondPart.name, permitted_classes = c("numeric", "integer")) } if (!is.na(thirdPart)){ + thirdPart.name <- thirdPart thirdPart <- .loadServersideObject(thirdPart) + .checkClass(obj = thirdPart, obj_name = thirdPart.name, permitted_classes = c("numeric", "integer")) } # access the internal reference data diff --git a/R/rowColCalcDS.R b/R/rowColCalcDS.R index 396f8d9f..bbc0c9e7 100644 --- a/R/rowColCalcDS.R +++ b/R/rowColCalcDS.R @@ -14,6 +14,7 @@ rowColCalcDS <- function (dataset.name, operation) { dataset <- .loadServersideObject(dataset.name) + .checkClass(obj = dataset, obj_name = dataset.name, permitted_classes = c("data.frame", "matrix")) if(operation == 1){ result <- rowSums(dataset, na.rm=TRUE) From cbbfb0aa26dcb9b990709a9610559e85a0c48176 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Thu, 16 Apr 2026 19:50:10 +0200 Subject: [PATCH 03/38] docs: updated authorship --- R/elsplineDS.R | 1 + R/getWGSRDS.R | 1 + R/hetcorDS.R | 1 + R/lexisDS1.R | 1 + R/lexisDS2.R | 1 + R/lsplineDS.R | 1 + R/metadataDS.R | 1 + R/nsDS.R | 1 + R/qlsplineDS.R | 1 + R/rowColCalcDS.R | 1 + R/tableDS.R | 1 + R/tableDS.assign.R | 1 + R/tableDS2.R | 1 + R/tapplyDS.R | 1 + R/tapplyDS.assign.R | 1 + 15 files changed, 15 insertions(+) diff --git a/R/elsplineDS.R b/R/elsplineDS.R index 7b30dd7e..4248a044 100644 --- a/R/elsplineDS.R +++ b/R/elsplineDS.R @@ -18,6 +18,7 @@ #' @return an object of class "lspline" and "matrix", which its name is specified by the #' \code{newobj} argument (or its default name "elspline.newobj"), is assigned on the serverside. #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export #' elsplineDS <- function(x = x, n = n, marginal = FALSE, names = NULL){ diff --git a/R/getWGSRDS.R b/R/getWGSRDS.R index c308d6d8..619b66af 100644 --- a/R/getWGSRDS.R +++ b/R/getWGSRDS.R @@ -49,6 +49,7 @@ #' @return \code{ds.getWGSR} assigns a numeric vector that includes the z-scores for the #' specified index. #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export #' getWGSRDS <- function(sex, firstPart, secondPart, index, standing=NA, thirdPart=NA){ diff --git a/R/hetcorDS.R b/R/hetcorDS.R index 61b4f4cf..1dd26dae 100644 --- a/R/hetcorDS.R +++ b/R/hetcorDS.R @@ -24,6 +24,7 @@ #' any missing data were handled: "complete.obs" or "pairwise.complete.obs"; TRUE for ML estimates, #' FALSE for two-step estimates. #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export #' hetcorDS <- function(data, ML, std.err, bins, pd, use){ diff --git a/R/lexisDS1.R b/R/lexisDS1.R index 8a1aac9c..45bea015 100644 --- a/R/lexisDS1.R +++ b/R/lexisDS1.R @@ -7,6 +7,7 @@ #' @param exitCol a character string specifying the variable holding the time that each individual is censored or fails #' #' @author Burton PR +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' #' @return List with `max.time` #' @export diff --git a/R/lexisDS2.R b/R/lexisDS2.R index 02f8168f..69a2367b 100644 --- a/R/lexisDS2.R +++ b/R/lexisDS2.R @@ -31,6 +31,7 @@ #' 'data' argument is set the full data.frame will be expanded and carried forward #' #' @author Burton PR +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' #' @return List with `expanded.table` #' @export diff --git a/R/lsplineDS.R b/R/lsplineDS.R index d8dbce8c..22d8bdae 100644 --- a/R/lsplineDS.R +++ b/R/lsplineDS.R @@ -15,6 +15,7 @@ #' @return an object of class "lspline" and "matrix", which its name is specified by the #' \code{newobj} argument (or its default name "lspline.newobj"), is assigned on the serverside. #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export #' lsplineDS <- function(x = x, knots = NULL, marginal = FALSE, names = NULL){ diff --git a/R/metadataDS.R b/R/metadataDS.R index 3c303176..95f22866 100644 --- a/R/metadataDS.R +++ b/R/metadataDS.R @@ -6,6 +6,7 @@ #' @return a list containing the metadata. The elements of the list will depend #' on the metadata available. #' @author Stuart Wheater, for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export #' metadataDS <- function(x) diff --git a/R/nsDS.R b/R/nsDS.R index a12227c6..0c12d7ae 100644 --- a/R/nsDS.R +++ b/R/nsDS.R @@ -25,6 +25,7 @@ #' arguments to ns, and explicitly give the knots, Boundary.knots etc for use by predict.ns(). #' The object is assigned at each serverside. #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export #' nsDS <- function(x, df, knots, intercept, Boundary.knots){ diff --git a/R/qlsplineDS.R b/R/qlsplineDS.R index 254b09c9..55a56abf 100644 --- a/R/qlsplineDS.R +++ b/R/qlsplineDS.R @@ -23,6 +23,7 @@ #' @return an object of class "lspline" and "matrix", which its name is specified by the #' \code{newobj} argument (or its default name "qlspline.newobj"), is assigned on the serverside. #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export #' qlsplineDS <- function(x = x, q = q, na.rm = TRUE, marginal = FALSE, names = NULL){ diff --git a/R/rowColCalcDS.R b/R/rowColCalcDS.R index bbc0c9e7..b1f865dd 100644 --- a/R/rowColCalcDS.R +++ b/R/rowColCalcDS.R @@ -10,6 +10,7 @@ #' @return a numeric vector #' @export #' @author Gaye, A. +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' rowColCalcDS <- function (dataset.name, operation) { diff --git a/R/tableDS.R b/R/tableDS.R index 6f059f52..f524cfbe 100644 --- a/R/tableDS.R +++ b/R/tableDS.R @@ -33,6 +33,7 @@ #' of \code{ds.table}. Fully specified by argument of \code{ds.table} #' @return For information see help for \code{ds.table} #' @author Paul Burton for DataSHIELD Development Team, 13/11/2019 +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export tableDS<-function(rvar.transmit, cvar.transmit, stvar.transmit, rvar.all.unique.levels.transmit, cvar.all.unique.levels.transmit, stvar.all.unique.levels.transmit, exclude.transmit, useNA.transmit, force.nfilter.transmit){ diff --git a/R/tableDS.assign.R b/R/tableDS.assign.R index 01d41805..ab676367 100644 --- a/R/tableDS.assign.R +++ b/R/tableDS.assign.R @@ -33,6 +33,7 @@ #' of \code{ds.table}. Fully specified by argument of \code{ds.table} #' @return For information see help for \code{ds.table} #' @author Paul Burton for DataSHIELD Development Team, 13/11/2019 +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export tableDS.assign<-function(rvar.transmit, cvar.transmit, stvar.transmit, rvar.all.unique.levels.transmit, cvar.all.unique.levels.transmit, stvar.all.unique.levels.transmit, exclude.transmit, useNA.transmit){ diff --git a/R/tableDS2.R b/R/tableDS2.R index 3f58dccd..81886679 100644 --- a/R/tableDS2.R +++ b/R/tableDS2.R @@ -28,6 +28,7 @@ #' For more information see help for \code{ds.table} #' @return For information see help for \code{ds.table} #' @author Paul Burton for DataSHIELD Development Team, 13/11/2019 +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export tableDS2 <- function(newobj,rvar.transmit,cvar.transmit,stvar.transmit){ diff --git a/R/tapplyDS.R b/R/tapplyDS.R index 3da0a3a3..5b620144 100644 --- a/R/tapplyDS.R +++ b/R/tapplyDS.R @@ -13,6 +13,7 @@ #' @return an array of the summarized values created by the tapplyDS function. This array #' is returned to the clientside. It has the same number of dimensions as INDEX. #' @author Paul Burton, Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export tapplyDS <- function(X.name, INDEX.names.transmit, FUN.name){ diff --git a/R/tapplyDS.assign.R b/R/tapplyDS.assign.R index 2983f31f..a3917973 100644 --- a/R/tapplyDS.assign.R +++ b/R/tapplyDS.assign.R @@ -13,6 +13,7 @@ #' @return an array of the summarized values created by the \code{tapplyDS.assign} function. This #' array is written as a newobj on the serverside. It has the same number of dimensions as INDEX. #' @author Paul Burton, Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export tapplyDS.assign <- function(X.name, INDEX.names.transmit, FUN.name){ From 5fb83af613e5d7da0c4053aca4a41c88f1a74acf Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Thu, 16 Apr 2026 19:50:52 +0200 Subject: [PATCH 04/38] docs: redocumented --- man/elsplineDS.Rd | 2 ++ man/getWGSRDS.Rd | 2 ++ man/hetcorDS.Rd | 2 ++ man/lexisDS1.Rd | 2 ++ man/lexisDS2.Rd | 2 ++ man/lsplineDS.Rd | 2 ++ man/metadataDS.Rd | 2 ++ man/nsDS.Rd | 2 ++ man/qlsplineDS.Rd | 2 ++ man/rowColCalcDS.Rd | 2 ++ man/tableDS.Rd | 2 ++ man/tableDS.assign.Rd | 2 ++ man/tableDS2.Rd | 2 ++ man/tapplyDS.Rd | 2 ++ man/tapplyDS.assign.Rd | 2 ++ 15 files changed, 30 insertions(+) diff --git a/man/elsplineDS.Rd b/man/elsplineDS.Rd index 1d0c7fd5..d3a81fe5 100644 --- a/man/elsplineDS.Rd +++ b/man/elsplineDS.Rd @@ -36,4 +36,6 @@ range of x into n equal-width intervals. } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/getWGSRDS.Rd b/man/getWGSRDS.Rd index 4ecc45b2..98aa2f36 100644 --- a/man/getWGSRDS.Rd +++ b/man/getWGSRDS.Rd @@ -69,4 +69,6 @@ data. } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/hetcorDS.Rd b/man/hetcorDS.Rd index 2745ce65..5c558936 100644 --- a/man/hetcorDS.Rd +++ b/man/hetcorDS.Rd @@ -44,4 +44,6 @@ variables, and polychoric correlations between ordinal variables. } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/lexisDS1.Rd b/man/lexisDS1.Rd index da419723..9b560add 100644 --- a/man/lexisDS1.Rd +++ b/man/lexisDS1.Rd @@ -21,4 +21,6 @@ For more details see the extensive header for ds.lexis. } \author{ Burton PR + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/lexisDS2.Rd b/man/lexisDS2.Rd index 51ca6851..6b9ca122 100644 --- a/man/lexisDS2.Rd +++ b/man/lexisDS2.Rd @@ -62,4 +62,6 @@ For more details see the extensive header for ds.lexis. } \author{ Burton PR + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/lsplineDS.Rd b/man/lsplineDS.Rd index 23445b51..af17aa0f 100644 --- a/man/lsplineDS.Rd +++ b/man/lsplineDS.Rd @@ -33,4 +33,6 @@ in slope as compared to the previous segment. } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/metadataDS.Rd b/man/metadataDS.Rd index f7749090..5851b7a3 100644 --- a/man/metadataDS.Rd +++ b/man/metadataDS.Rd @@ -21,4 +21,6 @@ The function returns the metadata, obtained from attributes function. } \author{ Stuart Wheater, for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/nsDS.Rd b/man/nsDS.Rd index 302bd919..060ff5a3 100644 --- a/man/nsDS.Rd +++ b/man/nsDS.Rd @@ -44,4 +44,6 @@ A primary use is in modeling formula to directly specify a natural spline term i } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/qlsplineDS.Rd b/man/qlsplineDS.Rd index aa14326a..63c81831 100644 --- a/man/qlsplineDS.Rd +++ b/man/qlsplineDS.Rd @@ -42,4 +42,6 @@ probabilities directly (the vector is passed to argument probs of quantile). } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/rowColCalcDS.Rd b/man/rowColCalcDS.Rd index 260a4011..aaf4c93d 100644 --- a/man/rowColCalcDS.Rd +++ b/man/rowColCalcDS.Rd @@ -25,4 +25,6 @@ output vector is greater or equal to the allowed size. } \author{ Gaye, A. + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/tableDS.Rd b/man/tableDS.Rd index 752eb815..7314c2ee 100644 --- a/man/tableDS.Rd +++ b/man/tableDS.Rd @@ -67,4 +67,6 @@ in native R. } \author{ Paul Burton for DataSHIELD Development Team, 13/11/2019 + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/tableDS.assign.Rd b/man/tableDS.assign.Rd index 8214ab3d..4989ec5d 100644 --- a/man/tableDS.assign.Rd +++ b/man/tableDS.assign.Rd @@ -65,4 +65,6 @@ in native R. } \author{ Paul Burton for DataSHIELD Development Team, 13/11/2019 + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/tableDS2.Rd b/man/tableDS2.Rd index 86e27027..1538d621 100644 --- a/man/tableDS2.Rd +++ b/man/tableDS2.Rd @@ -47,4 +47,6 @@ in DataSHIELD and the \code{table} function in native R. } \author{ Paul Burton for DataSHIELD Development Team, 13/11/2019 + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/tapplyDS.Rd b/man/tapplyDS.Rd index b72ed2f5..c7d62d84 100644 --- a/man/tapplyDS.Rd +++ b/man/tapplyDS.Rd @@ -31,4 +31,6 @@ see details for \code{ds.tapply} function } \author{ Paul Burton, Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/tapplyDS.assign.Rd b/man/tapplyDS.assign.Rd index f57d4f03..7beac224 100644 --- a/man/tapplyDS.assign.Rd +++ b/man/tapplyDS.assign.Rd @@ -31,4 +31,6 @@ see details for \code{ds.tapply.assign} function } \author{ Paul Burton, Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } From f7b5267bb69c0f43084a7919c3cf801c2fd4414e Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Tue, 15 Sep 2026 21:27:28 +0200 Subject: [PATCH 05/38] tidied up refactor --- R/lexisDS2.R | 34 ++++++--- R/rowColCalcDS.R | 13 ++-- R/tapplyDS.assign.R | 16 ++--- tests/testthat/test-smk-elsplineDS.R | 49 +++++++++++++ tests/testthat/test-smk-getWGSRDS.R | 31 +++++++++ tests/testthat/test-smk-lexisDS1.R | 50 ++++++++++++++ tests/testthat/test-smk-lexisDS2.R | 88 ++++++++++++++++++++++++ tests/testthat/test-smk-lsplineDS.R | 49 +++++++++++++ tests/testthat/test-smk-nsDS.R | 48 +++++++++++++ tests/testthat/test-smk-qlsplineDS.R | 48 +++++++++++++ tests/testthat/test-smk-rowColCalcDS.R | 15 ++++ tests/testthat/test-smk-tableDS.R | 60 ++++++++++++++++ tests/testthat/test-smk-tableDS.assign.R | 50 ++++++++++++++ tests/testthat/test-smk-tableDS2.R | 54 +++++++++++++++ 14 files changed, 581 insertions(+), 24 deletions(-) create mode 100644 tests/testthat/test-smk-elsplineDS.R create mode 100644 tests/testthat/test-smk-lexisDS1.R create mode 100644 tests/testthat/test-smk-lexisDS2.R create mode 100644 tests/testthat/test-smk-lsplineDS.R create mode 100644 tests/testthat/test-smk-nsDS.R create mode 100644 tests/testthat/test-smk-qlsplineDS.R create mode 100644 tests/testthat/test-smk-tableDS.R create mode 100644 tests/testthat/test-smk-tableDS.assign.R create mode 100644 tests/testthat/test-smk-tableDS2.R diff --git a/R/lexisDS2.R b/R/lexisDS2.R index 69a2367b..5696636d 100644 --- a/R/lexisDS2.R +++ b/R/lexisDS2.R @@ -73,23 +73,39 @@ lexisDS2 <- function(datatext=NULL, intervalWidth, maxmaxtime, idCol, entryCol, length.collapseDF <- length(idSeq) #IDENTIFY VARIABLES TO BE CARRIED WITH THE EXPANDED SURVIVAL DATA - - if(is.null(vartext)){ + + # loads each comma-separated name; whole data.frame names are unpacked into + # their own columns (matching data.frame()'s handling of a data.frame argument), + # single columns are added under their make.names()-sanitised name (matching + # data.frame()'s default naming for a non-symbol argument such as D$var) + if(is.null(vartext) && !is.null(datatext)){ col.names <- unlist(strsplit(datatext, split=",")) - col.list <- vector("list", length(col.names)) - for(i in seq_along(col.names)) col.list[[i]] <- .loadServersideObject(col.names[i]) + col.list <- list() + for(nm in col.names){ + obj <- .loadServersideObject(nm) + if(is.data.frame(obj)){ + col.list <- c(col.list, as.list(obj)) + }else{ + col.list[[make.names(nm)]] <- obj + } + } DF <- data.frame(col.list) - colnames(DF) <- col.names } if(!is.null(vartext)){ col.names <- unlist(strsplit(vartext, split=",")) - col.list <- vector("list", length(col.names)) - for(i in seq_along(col.names)) col.list[[i]] <- .loadServersideObject(col.names[i]) + col.list <- list() + for(nm in col.names){ + obj <- .loadServersideObject(nm) + if(is.data.frame(obj)){ + col.list <- c(col.list, as.list(obj)) + }else{ + col.list[[make.names(nm)]] <- obj + } + } DF <- data.frame(col.list) - colnames(DF) <- col.names } - + if(is.null(datatext)&&is.null(vartext)){ DF<-data.frame(SURVTIME,CENS) } diff --git a/R/rowColCalcDS.R b/R/rowColCalcDS.R index b1f865dd..68f6d339 100644 --- a/R/rowColCalcDS.R +++ b/R/rowColCalcDS.R @@ -30,13 +30,12 @@ rowColCalcDS <- function (dataset.name, operation) { result <- colMeans(dataset, na.rm=TRUE) } - # check if the output is valid (i.e. meets DataSHIELD criteria) - check <- isValidDS(result) - if(check){ - return(result) - }else{ - resultNA <- rep(NA, length(result)) - return(resultNA) + # check if the output is valid (i.e. meets DataSHIELD criteria); result is + # always numeric, so only the numeric-vector branch of isValidDS applies + thr <- dsBase::listDisclosureSettingsDS() + nfilter.tab <- as.numeric(thr$nfilter.tab) + if(length(result) > 0 && length(result) < nfilter.tab){ + result <- rep(NA, length(result)) } return(result) diff --git a/R/tapplyDS.assign.R b/R/tapplyDS.assign.R index a3917973..5f2978ff 100644 --- a/R/tapplyDS.assign.R +++ b/R/tapplyDS.assign.R @@ -28,29 +28,29 @@ tapplyDS.assign <- function(X.name, INDEX.names.transmit, FUN.name){ studysideMessage <- "ERROR: X.name must be specified as a character string" stop(studysideMessage, call. = FALSE) } - + INDEX.factors <- unlist(strsplit(INDEX.names.transmit, split=",")) - + num.factors <- length(INDEX.factors) - + # test that output vector and indexing factor all have the same length length.2.test <- length(X) - + length.test.vector <- rep(NA, num.factors) - + for(g in 1:num.factors){ active.factor.name <- INDEX.factors[g] active.factor <- .loadServersideObject(active.factor.name) length.test.vector[g] <- length(active.factor) } - + for(h in 1:num.factors){ if(length.2.test!=length.test.vector[h]){ return.message <- "Error: the output variable and all indexing factors must be of equal length" stop(return.message, call. = FALSE) - } + } } - + # convert INDEX.names format from transmittable to actionable form (a list of vectors) INDEX <- vector("list", num.factors) for(g in 1:num.factors){ diff --git a/tests/testthat/test-smk-elsplineDS.R b/tests/testthat/test-smk-elsplineDS.R new file mode 100644 index 00000000..abc895c1 --- /dev/null +++ b/tests/testthat/test-smk-elsplineDS.R @@ -0,0 +1,49 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. +# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. +# +# This program and the accompanying materials +# are made available under the terms of the GNU Public License v3.0. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- + +# +# Set up +# + +# context("elsplineDS::smk::setup") + +set.standard.disclosure.settings() + +# +# Tests +# + +# context("elsplineDS::smk") +test_that("simple elsplineDS", { + input <- seq(1, 30, by = 1) + + res <- elsplineDS("input", 3) + + expect_equal(class(res), c("lspline", "matrix")) + expect_equal(dim(res), c(30, 3)) + expect_equal(unname(res[1, ]), c(1, 0, 0)) + expect_equal(unname(res[30, ]), c(10.66667, 9.666667, 9.666667), tolerance = 1e-6) +}) + +test_that("elsplineDS throws error when object does not exist", { + expect_error( + elsplineDS("nonexistent_object", 3), + regexp = "does not exist" + ) +}) + +# +# Done +# + +# context("elsplineDS::smk::shutdown") + +# context("elsplineDS::smk::done") diff --git a/tests/testthat/test-smk-getWGSRDS.R b/tests/testthat/test-smk-getWGSRDS.R index 73d0eda1..439f994c 100644 --- a/tests/testthat/test-smk-getWGSRDS.R +++ b/tests/testthat/test-smk-getWGSRDS.R @@ -149,6 +149,37 @@ test_that("simple getWGSRDS - mfa", { expect_true(is.na(res[10])) }) +test_that("getWGSRDS throws error when firstPart does not exist", { + expect_error( + getWGSRDS("data$sex", "nonexistent_object", "data$age", "hfa", NA, NA), + regexp = "does not exist" + ) +}) + +test_that("getWGSRDS throws error when firstPart is not numeric or integer", { + bad_input <- factor(c("a", "b")) + expect_error( + getWGSRDS("data$sex", "bad_input", "data$age", "hfa", NA, NA), + regexp = "must be of type numeric or integer" + ) +}) + +test_that("getWGSRDS throws error when secondPart is not numeric or integer", { + bad_input <- factor(c("a", "b")) + expect_error( + getWGSRDS("data$sex", "data$height", "bad_input", "hfa", NA, NA), + regexp = "must be of type numeric or integer" + ) +}) + +test_that("getWGSRDS throws error when thirdPart is not numeric or integer", { + bad_input <- factor(c("a", "b")) + expect_error( + getWGSRDS("data$sex", "data$weight", "data$height", "bfa", NA, "bad_input"), + regexp = "must be of type numeric or integer" + ) +}) + # # Done # diff --git a/tests/testthat/test-smk-lexisDS1.R b/tests/testthat/test-smk-lexisDS1.R new file mode 100644 index 00000000..d5539611 --- /dev/null +++ b/tests/testthat/test-smk-lexisDS1.R @@ -0,0 +1,50 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. +# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. +# +# This program and the accompanying materials +# are made available under the terms of the GNU Public License v3.0. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- + +# +# Set up +# + +# context("lexisDS1::smk::setup") + +set.standard.disclosure.settings() + +# +# Tests +# + +# context("lexisDS1::smk") +test_that("simple lexisDS1", { + input <- c(1, 5, 3, 9, 2) + + res <- lexisDS1("input") + + expect_equal(class(res), "list") + expect_equal(names(res), "max.time") + # max.time is the max exposure time masked by a random +1%-5% increment + expect_gte(res$max.time, 9 * 1.01) + expect_lte(res$max.time, 9 * 1.05) +}) + +test_that("lexisDS1 throws error when object does not exist", { + expect_error( + lexisDS1("nonexistent_object"), + regexp = "does not exist" + ) +}) + +# +# Done +# + +# context("lexisDS1::smk::shutdown") + +# context("lexisDS1::smk::done") diff --git a/tests/testthat/test-smk-lexisDS2.R b/tests/testthat/test-smk-lexisDS2.R new file mode 100644 index 00000000..8e0c10fc --- /dev/null +++ b/tests/testthat/test-smk-lexisDS2.R @@ -0,0 +1,88 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. +# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. +# +# This program and the accompanying materials +# are made available under the terms of the GNU Public License v3.0. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- + +# +# Set up +# + +# context("lexisDS2::smk::setup") + +set.standard.disclosure.settings() + +# +# Tests +# + +# context("lexisDS2::smk::datatext") +test_that("simple lexisDS2, datatext names a whole data.frame", { + D <- data.frame(id = 1:6, start = rep(0, 6), end = rep(5, 6), status = rep(1, 6), extra = 101:106) + + res <- lexisDS2( + datatext = "D", intervalWidth = "10", maxmaxtime = 10, + idCol = "D$id", entryCol = "D$start", exitCol = "D$end", statusCol = "D$status", vartext = NULL + ) + + expect_equal(class(res), "list") + # carried-forward columns must keep D's own column names, not be corrupted + # or misaligned by the data.frame construction (see lexisDS2 datatext/vartext handling) + expect_true(all(c("id", "start", "end", "status", "extra") %in% names(res$expanded.table))) + expect_equal(res$expanded.table$extra, 101:106) + expect_equal(nrow(res$expanded.table), 6) +}) + +# context("lexisDS2::smk::vartext") +test_that("simple lexisDS2, vartext names individual $-qualified columns", { + D <- data.frame(id = 1:6, start = rep(0, 6), end = rep(5, 6), status = rep(1, 6), extra = 101:106, extra2 = 201:206) + + res <- lexisDS2( + datatext = NULL, intervalWidth = "10", maxmaxtime = 10, + idCol = "D$id", entryCol = "D$start", exitCol = "D$end", statusCol = "D$status", + vartext = "D$extra,D$extra2" + ) + + expect_equal(class(res), "list") + expect_true(all(c("D.extra", "D.extra2") %in% names(res$expanded.table))) + expect_equal(res$expanded.table$D.extra, 101:106) + expect_equal(res$expanded.table$D.extra2, 201:206) +}) + +# context("lexisDS2::smk::no.carry.forward") +test_that("simple lexisDS2, no datatext or vartext", { + D <- data.frame(id = 1:6, start = rep(0, 6), end = rep(5, 6), status = rep(1, 6)) + + res <- lexisDS2( + datatext = NULL, intervalWidth = "10", maxmaxtime = 10, + idCol = "D$id", entryCol = "D$start", exitCol = "D$end", statusCol = "D$status", vartext = NULL + ) + + expect_equal(class(res), "list") + expect_equal(nrow(res$expanded.table), 6) +}) + +test_that("lexisDS2 throws error when object does not exist", { + D <- data.frame(id = 1:6, start = rep(0, 6), end = rep(5, 6), status = rep(1, 6)) + + expect_error( + lexisDS2( + datatext = NULL, intervalWidth = "10", maxmaxtime = 10, + idCol = "D$id", entryCol = "D$start", exitCol = "nonexistent_object", statusCol = "D$status", vartext = NULL + ), + regexp = "does not exist" + ) +}) + +# +# Done +# + +# context("lexisDS2::smk::shutdown") + +# context("lexisDS2::smk::done") diff --git a/tests/testthat/test-smk-lsplineDS.R b/tests/testthat/test-smk-lsplineDS.R new file mode 100644 index 00000000..2d52ca57 --- /dev/null +++ b/tests/testthat/test-smk-lsplineDS.R @@ -0,0 +1,49 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. +# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. +# +# This program and the accompanying materials +# are made available under the terms of the GNU Public License v3.0. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- + +# +# Set up +# + +# context("lsplineDS::smk::setup") + +set.standard.disclosure.settings() + +# +# Tests +# + +# context("lsplineDS::smk") +test_that("simple lsplineDS", { + input <- seq(1, 30, by = 1) + + res <- lsplineDS("input", knots = c(10, 20)) + + expect_equal(class(res), c("lspline", "matrix")) + expect_equal(dim(res), c(30, 3)) + expect_equal(unname(res[1, ]), c(1, 0, 0)) + expect_equal(unname(res[30, ]), c(10, 10, 10)) +}) + +test_that("lsplineDS throws error when object does not exist", { + expect_error( + lsplineDS("nonexistent_object", knots = c(10, 20)), + regexp = "does not exist" + ) +}) + +# +# Done +# + +# context("lsplineDS::smk::shutdown") + +# context("lsplineDS::smk::done") diff --git a/tests/testthat/test-smk-nsDS.R b/tests/testthat/test-smk-nsDS.R new file mode 100644 index 00000000..07badac9 --- /dev/null +++ b/tests/testthat/test-smk-nsDS.R @@ -0,0 +1,48 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. +# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. +# +# This program and the accompanying materials +# are made available under the terms of the GNU Public License v3.0. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- + +# +# Set up +# + +# context("nsDS::smk::setup") + +set.standard.disclosure.settings() + +# +# Tests +# + +# context("nsDS::smk") +test_that("simple nsDS", { + input <- seq(1, 30, by = 1) + + res <- nsDS("input", df = 3, knots = NULL, intercept = FALSE, Boundary.knots = NULL) + + expect_equal(class(res), c("ns", "basis", "matrix")) + expect_equal(dim(res), c(30, 3)) + expect_equal(unname(res[1, ]), c(0, 0, 0)) +}) + +test_that("nsDS throws error when object does not exist", { + expect_error( + nsDS("nonexistent_object", df = 3, knots = NULL, intercept = FALSE, Boundary.knots = NULL), + regexp = "does not exist" + ) +}) + +# +# Done +# + +# context("nsDS::smk::shutdown") + +# context("nsDS::smk::done") diff --git a/tests/testthat/test-smk-qlsplineDS.R b/tests/testthat/test-smk-qlsplineDS.R new file mode 100644 index 00000000..42066853 --- /dev/null +++ b/tests/testthat/test-smk-qlsplineDS.R @@ -0,0 +1,48 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. +# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. +# +# This program and the accompanying materials +# are made available under the terms of the GNU Public License v3.0. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- + +# +# Set up +# + +# context("qlsplineDS::smk::setup") + +set.standard.disclosure.settings() + +# +# Tests +# + +# context("qlsplineDS::smk") +test_that("simple qlsplineDS", { + input <- seq(1, 30, by = 1) + + res <- qlsplineDS("input", q = 3, na.rm = TRUE, marginal = FALSE) + + expect_equal(class(res), c("lspline", "matrix")) + expect_equal(dim(res), c(30, 3)) + expect_equal(unname(res[1, ]), c(1, 0, 0)) +}) + +test_that("qlsplineDS throws error when object does not exist", { + expect_error( + qlsplineDS("nonexistent_object", q = 3, na.rm = TRUE, marginal = FALSE), + regexp = "does not exist" + ) +}) + +# +# Done +# + +# context("qlsplineDS::smk::shutdown") + +# context("qlsplineDS::smk::done") diff --git a/tests/testthat/test-smk-rowColCalcDS.R b/tests/testthat/test-smk-rowColCalcDS.R index aa1a3276..d7b89470 100644 --- a/tests/testthat/test-smk-rowColCalcDS.R +++ b/tests/testthat/test-smk-rowColCalcDS.R @@ -74,6 +74,21 @@ test_that("simple rowColCalcDS, operation 4", { expect_equal(res[4], 6.5) }) +test_that("rowColCalcDS throws error when object does not exist", { + expect_error( + rowColCalcDS("nonexistent_object", 1), + regexp = "does not exist" + ) +}) + +test_that("rowColCalcDS throws error when object is not data.frame or matrix", { + bad_input <- list(a = 1:3, b = 4:6) + expect_error( + rowColCalcDS("bad_input", 1), + regexp = "must be of type data.frame or matrix" + ) +}) + # # Done # diff --git a/tests/testthat/test-smk-tableDS.R b/tests/testthat/test-smk-tableDS.R new file mode 100644 index 00000000..6ffdb46c --- /dev/null +++ b/tests/testthat/test-smk-tableDS.R @@ -0,0 +1,60 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. +# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. +# +# This program and the accompanying materials +# are made available under the terms of the GNU Public License v3.0. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- + +# +# Set up +# + +# context("tableDS::smk::setup") + +set.standard.disclosure.settings() + +# +# Tests +# + +# context("tableDS::smk::1D") +test_that("simple tableDS, 1D", { + input <- factor(rep(c("a", "b"), each = 5)) + + res <- tableDS("input", NULL, NULL, "a,b", NULL, NULL, NULL, "no", NULL) + + expect_equal(class(res), "table") + expect_equal(as.vector(res), c(5, 5)) + expect_equal(names(res), c("a", "b")) +}) + +# context("tableDS::smk::2D") +test_that("simple tableDS, 2D", { + rvar <- factor(rep(c("a", "b"), each = 10)) + cvar <- factor(rep(rep(c("x", "y"), each = 5), 2)) + + res <- tableDS("rvar", "cvar", NULL, "a,b", "x,y", NULL, NULL, "no", NULL) + + expect_equal(class(res), "table") + expect_equal(dim(res), c(2L, 2L)) + expect_equal(as.vector(res), c(5, 5, 5, 5)) +}) + +test_that("tableDS throws error when object does not exist", { + expect_error( + tableDS("nonexistent_object", NULL, NULL, "a,b", NULL, NULL, NULL, "no", NULL), + regexp = "does not exist" + ) +}) + +# +# Done +# + +# context("tableDS::smk::shutdown") + +# context("tableDS::smk::done") diff --git a/tests/testthat/test-smk-tableDS.assign.R b/tests/testthat/test-smk-tableDS.assign.R new file mode 100644 index 00000000..a284ed28 --- /dev/null +++ b/tests/testthat/test-smk-tableDS.assign.R @@ -0,0 +1,50 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. +# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. +# +# This program and the accompanying materials +# are made available under the terms of the GNU Public License v3.0. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- + +# +# Set up +# + +# context("tableDS.assign::smk::setup") + +set.standard.disclosure.settings() + +# +# Tests +# + +# context("tableDS.assign::smk") +test_that("simple tableDS.assign", { + rvar <- factor(rep(c("a", "b"), each = 10)) + cvar <- factor(rep(rep(c("x", "y"), each = 5), 2)) + + res <- tableDS.assign("rvar", "cvar", NULL, "a,b", "x,y", NULL, NULL, "no") + + expect_equal(class(res), "list") + expect_equal(names(res), c("table", "counts", "dim", "dimnames")) + expect_equal(res$dim, c(2L, 2L)) + expect_equal(res$counts, c(5, 5, 5, 5)) +}) + +test_that("tableDS.assign throws error when object does not exist", { + expect_error( + tableDS.assign("nonexistent_object", NULL, NULL, "a,b", NULL, NULL, NULL, "no"), + regexp = "does not exist" + ) +}) + +# +# Done +# + +# context("tableDS.assign::smk::shutdown") + +# context("tableDS.assign::smk::done") diff --git a/tests/testthat/test-smk-tableDS2.R b/tests/testthat/test-smk-tableDS2.R new file mode 100644 index 00000000..7f842297 --- /dev/null +++ b/tests/testthat/test-smk-tableDS2.R @@ -0,0 +1,54 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. +# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. +# +# This program and the accompanying materials +# are made available under the terms of the GNU Public License v3.0. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- + +# +# Set up +# + +# context("tableDS2::smk::setup") + +set.standard.disclosure.settings() + +# +# Tests +# + +# context("tableDS2::smk") +test_that("simple tableDS2", { + rvar <- factor(rep(c("a", "b"), each = 10)) + cvar <- factor(rep(rep(c("x", "y"), each = 5), 2)) + res.assign <- tableDS.assign("rvar", "cvar", NULL, "a,b", "x,y", NULL, NULL, "no") + + res <- tableDS2("res.assign", "rvar", "cvar", NULL) + + expect_equal(class(res), "list") + expect_equal( + names(res), + c("table.cell.IDs", "table.dim", "table.dimnames", "table.structure_and_cell.order") + ) + expect_equal(res$table.dim, c(2L, 2L)) + expect_equal(res$table.cell.IDs, 1:4) +}) + +test_that("tableDS2 throws error when object does not exist", { + expect_error( + tableDS2("nonexistent_object", "rvar", "cvar", NULL), + regexp = "does not exist" + ) +}) + +# +# Done +# + +# context("tableDS2::smk::shutdown") + +# context("tableDS2::smk::done") From 754f3352856259fca55a9da228ccab1d71f62b58 Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Fri, 18 Sep 2026 14:35:48 +0100 Subject: [PATCH 06/38] Remove skip --- tests/testthat/test-perf-meanDS.R | 4 ++-- tests/testthat/test-perf-varDS.R | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-perf-meanDS.R b/tests/testthat/test-perf-meanDS.R index 53e4c7af..3cb30a2e 100644 --- a/tests/testthat/test-perf-meanDS.R +++ b/tests/testthat/test-perf-meanDS.R @@ -13,8 +13,8 @@ # # avoid performance tests on CRAN and GitHub Actions -testthat::skip_on_cran() -testthat::skip_on_ci() +# testthat::skip_on_cran() +# testthat::skip_on_ci() # context("meanDS::perf::setup") diff --git a/tests/testthat/test-perf-varDS.R b/tests/testthat/test-perf-varDS.R index 9df6c0f6..3870f0f3 100644 --- a/tests/testthat/test-perf-varDS.R +++ b/tests/testthat/test-perf-varDS.R @@ -13,8 +13,8 @@ # # avoid performance tests on CRAN and GitHub Actions -testthat::skip_on_cran() -testthat::skip_on_ci() +# testthat::skip_on_cran() +# testthat::skip_on_ci() # context("varDS::perf::setup") From a77ac736691f4469b7e8596139bffae6d2ae7194 Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 10:39:02 +0100 Subject: [PATCH 07/38] Removal of testthat 'skip's --- tests/testthat/test-perf-meanDS.R | 4 ++-- tests/testthat/test-perf-varDS.R | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-perf-meanDS.R b/tests/testthat/test-perf-meanDS.R index 3cb30a2e..d6355336 100644 --- a/tests/testthat/test-perf-meanDS.R +++ b/tests/testthat/test-perf-meanDS.R @@ -26,7 +26,7 @@ set.standard.disclosure.settings() # context("meanDS::perf::numeric") test_that("numeric meanDS - performance", { - skip_on_cran() +# skip_on_cran() input <- c(0.0, 1.0, 2.0, 3.0, 4.0) @@ -61,7 +61,7 @@ test_that("numeric meanDS - performance", { # context("meanDS::perf::numeric with NA") test_that("numeric meanDS, with NA - performance", { - skip_on_cran() +# skip_on_cran() input <- c(0.0, NA, 2.0, NA, 4.0) diff --git a/tests/testthat/test-perf-varDS.R b/tests/testthat/test-perf-varDS.R index 3870f0f3..d7e2131c 100644 --- a/tests/testthat/test-perf-varDS.R +++ b/tests/testthat/test-perf-varDS.R @@ -26,7 +26,7 @@ set.standard.disclosure.settings() # context("varDS::perf::numeric") test_that("numeric varDS - performance", { - skip_on_cran() +# skip_on_cran() input <- c(0.0, 1.0, 2.0, 3.0, 4.0) @@ -61,7 +61,7 @@ test_that("numeric varDS - performance", { # context("varDS::perf::numeric with NA") test_that("numeric varDS, with NA - performance", { - skip_on_cran() +# skip_on_cran() input <- c(0.0, NA, 2.0, NA, 4.0) From 648d72b0c87717e4a5d7137079e117371a2158aa Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 11:37:27 +0100 Subject: [PATCH 08/38] Update perfence profile --- tests/testthat/perf_files/azure-pipeline_perf-profile.csv | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/perf_files/azure-pipeline_perf-profile.csv b/tests/testthat/perf_files/azure-pipeline_perf-profile.csv index 77f556bc..43418639 100644 --- a/tests/testthat/perf_files/azure-pipeline_perf-profile.csv +++ b/tests/testthat/perf_files/azure-pipeline_perf-profile.csv @@ -1,5 +1,5 @@ "refer_name","rate","lower_tolerance","upper_tolerance" -"meanDS::perf::numeric::0","2998.9844","0.5","2" -"meanDS::perf::numberAndNA::0","3027.3963","0.5","2" -"varDS::perf::numeric::0","3124.4088","0.5","2" -"varDS::perf::numberAndNA::0","3146.532","0.5","2" +"meanDS::perf::numeric::0","4497.0","0.5","2" +"meanDS::perf::numberAndNA::0","4542.0","0.5","2" +"varDS::perf::numeric::0","4584.0","0.5","2" +"varDS::perf::numberAndNA::0","4590.0","0.5","2" From d8d79695593170850fc5d3021656ccad4f608797 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Mon, 21 Sep 2026 13:20:29 +0200 Subject: [PATCH 09/38] refactor: tidied up PR --- R/getWGSRDS.R | 9 +- R/isValidDS.R | 27 +++- R/lexisDS2.R | 35 ++--- R/quantileMeanDS.R | 2 +- R/rangeDS.R | 8 +- R/recodeLevelsDS.R | 2 +- R/replaceNaDS.R | 2 +- R/rowColCalcDS.R | 25 +-- R/tableDS.R | 6 +- R/tableDS.assign.R | 4 +- R/tapplyDS.R | 1 - man/isValidDS.Rd | 11 +- man/rangeDS.Rd | 6 +- tests/testthat/test-perf-meanDS.R | 4 +- tests/testthat/test-perf-varDS.R | 4 +- tests/testthat/test-smk-elsplineDS.R | 11 -- tests/testthat/test-smk-getWGSRDS.R | 12 +- tests/testthat/test-smk-hetcorDS.R | 7 + tests/testthat/test-smk-isValidDS.R | 182 +++++++++------------- tests/testthat/test-smk-lexisDS1.R | 11 -- tests/testthat/test-smk-lexisDS2.R | 25 +-- tests/testthat/test-smk-lsplineDS.R | 11 -- tests/testthat/test-smk-metadataDS.R | 10 ++ tests/testthat/test-smk-nsDS.R | 11 -- tests/testthat/test-smk-qlsplineDS.R | 11 -- tests/testthat/test-smk-rangeDS.R | 14 +- tests/testthat/test-smk-rowColCalcDS.R | 6 + tests/testthat/test-smk-tableDS.R | 50 ++++-- tests/testthat/test-smk-tableDS.assign.R | 11 -- tests/testthat/test-smk-tableDS2.R | 11 -- tests/testthat/test-smk-tapplyDS.R | 12 ++ tests/testthat/test-smk-tapplyDS.assign.R | 12 ++ 32 files changed, 277 insertions(+), 276 deletions(-) diff --git a/R/getWGSRDS.R b/R/getWGSRDS.R index 619b66af..c23f13d0 100644 --- a/R/getWGSRDS.R +++ b/R/getWGSRDS.R @@ -54,20 +54,21 @@ #' getWGSRDS <- function(sex, firstPart, secondPart, index, standing=NA, thirdPart=NA){ - sex.name <- sex firstPart.name <- firstPart sex <- .loadServersideObject(sex) firstPart <- .loadServersideObject(firstPart) - .checkClass(obj = firstPart, obj_name = firstPart.name, permitted_classes = c("numeric", "integer")) + .checkClass(obj = firstPart, obj_name = firstPart.name, permitted_classes = "numeric") if (!is.na(secondPart)){ secondPart.name <- secondPart secondPart <- .loadServersideObject(secondPart) - .checkClass(obj = secondPart, obj_name = secondPart.name, permitted_classes = c("numeric", "integer")) + .checkClass(obj = secondPart, obj_name = secondPart.name, permitted_classes = "numeric") } if (!is.na(thirdPart)){ thirdPart.name <- thirdPart thirdPart <- .loadServersideObject(thirdPart) - .checkClass(obj = thirdPart, obj_name = thirdPart.name, permitted_classes = c("numeric", "integer")) + if (index == "bfa"){ + .checkClass(obj = thirdPart, obj_name = thirdPart.name, permitted_classes = "numeric") + } } # access the internal reference data diff --git a/R/isValidDS.R b/R/isValidDS.R index f45ccae7..3d5127a9 100644 --- a/R/isValidDS.R +++ b/R/isValidDS.R @@ -2,12 +2,33 @@ #' @title Checks if an input is valid #' @description Tells if an object on the server side is valid. #' @details This function checks if an object is valid. -#' @param obj, a vector (numeric, integer, factor, character), data.frame or matrix -#' @return a boolean, TRUE if input is valid or FALSE if not. +#' @param x a character string, the name of a vector (numeric, integer, factor, character, +#' logical), data.frame or matrix +#' @return a list with \code{valid}, a boolean that is TRUE if the input is valid or FALSE +#' if not, and \code{class}, the class of the input object for client-side consistency +#' checking #' @author Gaye, A. +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #'@export #' -isValidDS <- function(obj) { +isValidDS <- function(x) { + + obj <- .loadServersideObject(x) + .checkClass( + obj = obj, + obj_name = x, + permitted_classes = c("character", "factor", "integer", "logical", "numeric", "data.frame", "matrix") + ) + + list(valid = .checkDisclosureSize(obj), class = class(obj)) +} + +#' Check a Server-Side Object Meets the Disclosure Size Threshold +#' +#' @param obj The object to check: a vector, data.frame or matrix. +#' @return A boolean, TRUE if the object meets the threshold or FALSE if not. +#' @noRd +.checkDisclosureSize <- function(obj) { # this filter sets the minimum number of observations that are allowed diff --git a/R/lexisDS2.R b/R/lexisDS2.R index 5696636d..d4366720 100644 --- a/R/lexisDS2.R +++ b/R/lexisDS2.R @@ -47,8 +47,8 @@ lexisDS2 <- function(datatext=NULL, intervalWidth, maxmaxtime, idCol, entryCol, #nfilter.string<-as.numeric(thr$nfilter.string) ############################################################# - starttime <- .loadServersideObject(entryCol) endtime <- .loadServersideObject(exitCol) + starttime <- if(is.null(entryCol)) rep(0, length(endtime)) else .loadServersideObject(entryCol) cens <- .loadServersideObject(statusCol) id.orig <- .loadServersideObject(idCol) @@ -73,39 +73,24 @@ lexisDS2 <- function(datatext=NULL, intervalWidth, maxmaxtime, idCol, entryCol, length.collapseDF <- length(idSeq) #IDENTIFY VARIABLES TO BE CARRIED WITH THE EXPANDED SURVIVAL DATA - - # loads each comma-separated name; whole data.frame names are unpacked into - # their own columns (matching data.frame()'s handling of a data.frame argument), - # single columns are added under their make.names()-sanitised name (matching - # data.frame()'s default naming for a non-symbol argument such as D$var) - if(is.null(vartext) && !is.null(datatext)){ - col.names <- unlist(strsplit(datatext, split=",")) - col.list <- list() - for(nm in col.names){ - obj <- .loadServersideObject(nm) - if(is.data.frame(obj)){ - col.list <- c(col.list, as.list(obj)) - }else{ - col.list[[make.names(nm)]] <- obj - } - } - DF <- data.frame(col.list) - } - - if(!is.null(vartext)){ - col.names <- unlist(strsplit(vartext, split=",")) + + # 'vartext' takes precedence over 'datatext'. A data.frame name is unpacked into its + # columns and a single column such as D$var is named make.names("D$var"), matching + # how data.frame() named them when the names were parsed as R code. + carried.text <- if(is.null(vartext)) datatext else vartext + if(!is.null(carried.text)){ col.list <- list() - for(nm in col.names){ + for(nm in unlist(strsplit(carried.text, split=","))){ obj <- .loadServersideObject(nm) if(is.data.frame(obj)){ col.list <- c(col.list, as.list(obj)) }else{ - col.list[[make.names(nm)]] <- obj + col.list <- c(col.list, stats::setNames(list(obj), make.names(nm))) } } DF <- data.frame(col.list) } - + if(is.null(datatext)&&is.null(vartext)){ DF<-data.frame(SURVTIME,CENS) } diff --git a/R/quantileMeanDS.R b/R/quantileMeanDS.R index b6a54e91..e5358f46 100644 --- a/R/quantileMeanDS.R +++ b/R/quantileMeanDS.R @@ -16,7 +16,7 @@ quantileMeanDS <- function (x) { .checkClass(obj = xvect, obj_name = x, permitted_classes = c("numeric", "integer")) # check if the input vector is valid (i.e. meets DataSHIELD criteria) - check <- isValidDS(xvect) + check <- .checkDisclosureSize(xvect) if(check){ # if the input vector is valid diff --git a/R/rangeDS.R b/R/rangeDS.R index ec9183ea..6d87d83f 100644 --- a/R/rangeDS.R +++ b/R/rangeDS.R @@ -2,12 +2,16 @@ #' @title returns the minimum and maximum of a numeric vector #' @description this function is similar to R function \code{range} but instead to not return #' the real minimum and maximum, the computed values are multiplied by a very small random number. -#' @param xvect a numerical +#' @param x a character string, the name of a numeric or integer vector #' @return a numeric vector which contains the minimum and the maximum values of the vector #' @author Amadou Gaye, Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export #' -rangeDS <- function(xvect) { +rangeDS <- function(x) { + xvect <- .loadServersideObject(x) + .checkClass(obj = xvect, obj_name = x, permitted_classes = c("numeric", "integer")) + # back-up current .Random.seed and revert on.exit if (exists(x = ".Random.seed", envir = globalenv())) { assign(x = ".old_seed", value = .Random.seed, envir = parent.frame()); diff --git a/R/recodeLevelsDS.R b/R/recodeLevelsDS.R index 6878faa6..b4c47998 100644 --- a/R/recodeLevelsDS.R +++ b/R/recodeLevelsDS.R @@ -14,7 +14,7 @@ recodeLevelsDS <- function (x=NULL, classes=NULL){ dsBase::checkPermissivePrivacyControlLevel(c('permissive', 'banana', 'carrot')) # check if the input vector is valid (i.e. meets DataSHIELD criteria) - check <- isValidDS(x) + check <- .checkDisclosureSize(x) if(check){ # generate the new variable with the specified levels diff --git a/R/replaceNaDS.R b/R/replaceNaDS.R index 62b91f99..707db8f6 100644 --- a/R/replaceNaDS.R +++ b/R/replaceNaDS.R @@ -21,7 +21,7 @@ replaceNaDS <- function(x, replacements){ xvect <- .loadServersideObject(x) # check if the input vector is valid (i.e. meets DataSHIELD criteria) - check <- dsBase::isValidDS(xvect) + check <- .checkDisclosureSize(xvect) # if the input vector is a factor convert it to numeric cls <- class(xvect) diff --git a/R/rowColCalcDS.R b/R/rowColCalcDS.R index 68f6d339..ad09ed60 100644 --- a/R/rowColCalcDS.R +++ b/R/rowColCalcDS.R @@ -13,9 +13,13 @@ #' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' rowColCalcDS <- function (dataset.name, operation) { - + dataset <- .loadServersideObject(dataset.name) .checkClass(obj = dataset, obj_name = dataset.name, permitted_classes = c("data.frame", "matrix")) + column.classes <- lapply(as.data.frame(dataset), class) + if(!all(vapply(column.classes, function(cls) any(cls %in% c("numeric", "integer")), logical(1)))){ + stop("One or more columns of '", dataset.name, "' are not of numeric type", call. = FALSE) + } if(operation == 1){ result <- rowSums(dataset, na.rm=TRUE) @@ -29,15 +33,16 @@ rowColCalcDS <- function (dataset.name, operation) { if(operation == 4){ result <- colMeans(dataset, na.rm=TRUE) } - - # check if the output is valid (i.e. meets DataSHIELD criteria); result is - # always numeric, so only the numeric-vector branch of isValidDS applies - thr <- dsBase::listDisclosureSettingsDS() - nfilter.tab <- as.numeric(thr$nfilter.tab) - if(length(result) > 0 && length(result) < nfilter.tab){ - result <- rep(NA, length(result)) + + # check if the output is valid (i.e. meets DataSHIELD criteria) + check <- .checkDisclosureSize(result) + if(check){ + return(result) + }else{ + resultNA <- rep(NA, length(result)) + return(resultNA) } - + return(result) - + } \ No newline at end of file diff --git a/R/tableDS.R b/R/tableDS.R index f524cfbe..8f62c773 100644 --- a/R/tableDS.R +++ b/R/tableDS.R @@ -56,7 +56,7 @@ nfilter.tab<-as.numeric(thr$nfilter.tab) # if(!is.null(force.nfilter.transmit)) { -force.nfilter.active<-.loadServersideObject(force.nfilter.transmit) +force.nfilter.active<-as.numeric(force.nfilter.transmit) if(force.nfilter.active. -#------------------------------------------------------------------------------- - # # Set up # diff --git a/tests/testthat/test-smk-getWGSRDS.R b/tests/testthat/test-smk-getWGSRDS.R index 439f994c..dab37f42 100644 --- a/tests/testthat/test-smk-getWGSRDS.R +++ b/tests/testthat/test-smk-getWGSRDS.R @@ -156,27 +156,27 @@ test_that("getWGSRDS throws error when firstPart does not exist", { ) }) -test_that("getWGSRDS throws error when firstPart is not numeric or integer", { +test_that("getWGSRDS throws error when firstPart is not numeric", { bad_input <- factor(c("a", "b")) expect_error( getWGSRDS("data$sex", "bad_input", "data$age", "hfa", NA, NA), - regexp = "must be of type numeric or integer" + regexp = "must be of type numeric\\." ) }) -test_that("getWGSRDS throws error when secondPart is not numeric or integer", { +test_that("getWGSRDS throws error when secondPart is not numeric", { bad_input <- factor(c("a", "b")) expect_error( getWGSRDS("data$sex", "data$height", "bad_input", "hfa", NA, NA), - regexp = "must be of type numeric or integer" + regexp = "must be of type numeric\\." ) }) -test_that("getWGSRDS throws error when thirdPart is not numeric or integer", { +test_that("getWGSRDS throws error when thirdPart is not numeric", { bad_input <- factor(c("a", "b")) expect_error( getWGSRDS("data$sex", "data$weight", "data$height", "bfa", NA, "bad_input"), - regexp = "must be of type numeric or integer" + regexp = "must be of type numeric\\." ) }) diff --git a/tests/testthat/test-smk-hetcorDS.R b/tests/testthat/test-smk-hetcorDS.R index fd5ca14e..168f1084 100644 --- a/tests/testthat/test-smk-hetcorDS.R +++ b/tests/testthat/test-smk-hetcorDS.R @@ -83,6 +83,13 @@ test_that("hetcorDS", { }) +test_that("hetcorDS throws error when object does not exist", { + expect_error( + hetcorDS(data = "nonexistent_object", ML = FALSE, std.err = TRUE, bins = 2, pd = TRUE, use = "complete.obs"), + regexp = "does not exist" + ) +}) + # # Done # diff --git a/tests/testthat/test-smk-isValidDS.R b/tests/testthat/test-smk-isValidDS.R index 81fc5ade..83937374 100644 --- a/tests/testthat/test-smk-isValidDS.R +++ b/tests/testthat/test-smk-isValidDS.R @@ -15,6 +15,8 @@ # context("isValidDS::smk::setup") +set.standard.disclosure.settings() + # # Tests # @@ -23,229 +25,195 @@ test_that("simple isValidDS, character", { input <- "value" - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, FALSE) }) test_that("simple isValidDS, character vector", { input <- c("value1", "value2", "value3", "value4") - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, TRUE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, TRUE) }) # context("isValidDS::smk::integer") test_that("simple isValidDS, integer", { input <- 1L - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, FALSE) }) test_that("simple isValidDS, integer vector", { input <- c(1L, 2L, 3L, 4L) - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, TRUE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, TRUE) }) # context("isValidDS::smk::numeric") test_that("simple isValidDS, numeric", { input <- 1.1 - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, FALSE) }) test_that("simple isValidDS, numeric vector", { input <- c(1.1, 2.1, 3.1, 4.1) - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, TRUE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, TRUE) }) # context("isValidDS::smk::logical") test_that("simple isValidDS, logical, FALSE", { input <- FALSE - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, FALSE) }) test_that("simple isValidDS, logical, TRUE", { input <- TRUE - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, FALSE) }) test_that("simple isValidDS, logical vector", { input <- c(FALSE, TRUE, FALSE, TRUE) - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, TRUE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, TRUE) }) test_that("simple isValidDS, factor", { input <- as.factor("a") - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, FALSE) }) test_that("simple isValidDS, factor vector", { input <- as.factor(c("a", "a", "a", "a", "b", "b", "b", "b")) - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, TRUE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, TRUE) }) test_that("simple isValidDS, factor vector", { input <- as.factor(c("a", "b", "c", "d", "e", "f")) - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, FALSE) }) # context("isValidDS::smk::data.frame") test_that("simple isValidDS, data.frame", { input <- data.frame(v1 = c(0.0, 1.0, 2.0, 3.0, 4.0), v2 = c(4.0, 3.0, 2.0, 1.0, 0.0)) - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, TRUE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, TRUE) }) # context("isValidDS::smk::array") -test_that("simple isValidDS, array", { +test_that("isValidDS throws error for a 1-d array", { input <- array(c(0.0, 1.0, 2.0, 3.0, 4.0)) - res <- isValidDS(input) - - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_error(isValidDS("input"), regexp = "must be of type") }) # context("isValidDS::smk::matrix") test_that("simple isValidDS, matrix", { input <- matrix(c(0.0, 1.0, 2.0, 3.0, 4.0)) - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, TRUE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, TRUE) }) # context("isValidDS::smk::data.matrix") test_that("simple isValidDS, data.matrix", { input <- data.matrix(data.frame(v1 = c(0.0, 1.0, 2.0, 3.0, 4.0), v2 = c(4.0, 3.0, 2.0, 1.0, 0.0))) - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, TRUE) + expect_equal(class(res$valid), "logical") + expect_length(res$valid, 1) + expect_equal(res$valid, TRUE) }) # context("isValidDS::smk::date") -test_that("simple isValidDS, date", { +test_that("isValidDS throws error for a date", { input <- Sys.Date() - res <- isValidDS(input) - - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_error(isValidDS("input"), regexp = "must be of type") }) -# context("isValidDS::smk::formula") -test_that("simple isValidDS, formula", { - input <- X ~ A + B +test_that("isValidDS returns the class of the input", { + input <- c(1.1, 2.1, 3.1, 4.1) - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_equal(res$class, "numeric") }) -# context("isValidDS::smk::environment") -test_that("simple isValidDS, environment", { - input <- environment() - - res <- isValidDS(input) - - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) +test_that("isValidDS throws error when object does not exist", { + expect_error(isValidDS("nonexistent_object"), regexp = "does not exist") }) -# context("isValidDS::smk::NA") test_that("special isValidDS, NA", { input <- NA - res <- isValidDS(input) + res <- isValidDS("input") - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_equal(res$valid, FALSE) }) -# context("isValidDS::smk::NULL") test_that("special isValidDS, NULL", { input <- NULL - res <- isValidDS(input) - - expect_equal(class(res), "logical") - expect_length(res, 1) - expect_equal(res, FALSE) + expect_error(isValidDS("input"), regexp = "must be of type") }) - -# -# Done -# - -# context("isValidDS::smk::shutdown") - -# context("isValidDS::smk::done") diff --git a/tests/testthat/test-smk-lexisDS1.R b/tests/testthat/test-smk-lexisDS1.R index d5539611..c0453a77 100644 --- a/tests/testthat/test-smk-lexisDS1.R +++ b/tests/testthat/test-smk-lexisDS1.R @@ -1,14 +1,3 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - # # Set up # diff --git a/tests/testthat/test-smk-lexisDS2.R b/tests/testthat/test-smk-lexisDS2.R index 8e0c10fc..b29655cb 100644 --- a/tests/testthat/test-smk-lexisDS2.R +++ b/tests/testthat/test-smk-lexisDS2.R @@ -1,14 +1,3 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - # # Set up # @@ -79,6 +68,20 @@ test_that("lexisDS2 throws error when object does not exist", { ) }) +# context("lexisDS2::smk::no.entryCol") +test_that("simple lexisDS2, entryCol not given defaults entry times to 0", { + D <- data.frame(id = 1:6, end = rep(5, 6), status = rep(1, 6)) + + res <- lexisDS2( + datatext = NULL, intervalWidth = "10", maxmaxtime = 10, + idCol = "D$id", entryCol = NULL, exitCol = "D$end", statusCol = "D$status", vartext = NULL + ) + + expect_equal(class(res), "list") + expect_equal(nrow(res$expanded.table), 6) + expect_true(all(res$expanded.table$SURVTIME == 5)) +}) + # # Done # diff --git a/tests/testthat/test-smk-lsplineDS.R b/tests/testthat/test-smk-lsplineDS.R index 2d52ca57..88aa44e1 100644 --- a/tests/testthat/test-smk-lsplineDS.R +++ b/tests/testthat/test-smk-lsplineDS.R @@ -1,14 +1,3 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - # # Set up # diff --git a/tests/testthat/test-smk-metadataDS.R b/tests/testthat/test-smk-metadataDS.R index 4b0ab042..12cf94e5 100644 --- a/tests/testthat/test-smk-metadataDS.R +++ b/tests/testthat/test-smk-metadataDS.R @@ -46,6 +46,16 @@ test_that("simple metadataDS, list of vectors", { expect_length(res, 0) }) +test_that("metadataDS throws error when object does not exist", { + expect_error(metadataDS("nonexistent_object"), regexp = "does not exist") +}) + +test_that("metadataDS throws error when column does not exist", { + input <- list(v1 = c(0.0, 1.0, 2.0)) + + expect_error(metadataDS("input$nonexistent_column"), regexp = "not found in 'input'") +}) + # # Done # diff --git a/tests/testthat/test-smk-nsDS.R b/tests/testthat/test-smk-nsDS.R index 07badac9..1f21383a 100644 --- a/tests/testthat/test-smk-nsDS.R +++ b/tests/testthat/test-smk-nsDS.R @@ -1,14 +1,3 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - # # Set up # diff --git a/tests/testthat/test-smk-qlsplineDS.R b/tests/testthat/test-smk-qlsplineDS.R index 42066853..4eea279c 100644 --- a/tests/testthat/test-smk-qlsplineDS.R +++ b/tests/testthat/test-smk-qlsplineDS.R @@ -1,14 +1,3 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - # # Set up # diff --git a/tests/testthat/test-smk-rangeDS.R b/tests/testthat/test-smk-rangeDS.R index c59c9d32..31f58566 100644 --- a/tests/testthat/test-smk-rangeDS.R +++ b/tests/testthat/test-smk-rangeDS.R @@ -25,7 +25,7 @@ set.random.seed.setting(1234) test_that("numeric rangeDS", { input <- c(0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 3.0, 2.0, 1.0, 0.0) - res <- rangeDS(input) + res <- rangeDS("input") expect_length(res, 2) expect_equal(class(res), "numeric") @@ -37,7 +37,7 @@ test_that("numeric rangeDS", { test_that("character rangeDS", { input <- c(0.0, NA, 2.0, NA, 4.0, NA, 3.0, NA, 1.0, NA) - res <- rangeDS(input) + res <- rangeDS("input") expect_length(res, 2) expect_equal(class(res), "numeric") @@ -45,6 +45,16 @@ test_that("character rangeDS", { expect_equal(res[2], 4.12446, tolerance = 1e-6) }) +test_that("rangeDS throws error when object does not exist", { + expect_error(rangeDS("nonexistent_object"), regexp = "does not exist") +}) + +test_that("rangeDS throws error when object is not numeric", { + input <- c("a", "b", "c") + + expect_error(rangeDS("input"), regexp = "must be of type numeric or integer") +}) + # # Done # diff --git a/tests/testthat/test-smk-rowColCalcDS.R b/tests/testthat/test-smk-rowColCalcDS.R index d7b89470..f0d563b6 100644 --- a/tests/testthat/test-smk-rowColCalcDS.R +++ b/tests/testthat/test-smk-rowColCalcDS.R @@ -89,6 +89,12 @@ test_that("rowColCalcDS throws error when object is not data.frame or matrix", { ) }) +test_that("rowColCalcDS throws error when a column is not numeric", { + input <- data.frame(v1 = c(1.0, 2.0, 3.0, 4.0), v2 = c("a", "b", "c", "d")) + + expect_error(rowColCalcDS("input", 1), regexp = "are not of numeric type") +}) + # # Done # diff --git a/tests/testthat/test-smk-tableDS.R b/tests/testthat/test-smk-tableDS.R index 6ffdb46c..bcb77d76 100644 --- a/tests/testthat/test-smk-tableDS.R +++ b/tests/testthat/test-smk-tableDS.R @@ -1,14 +1,3 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - # # Set up # @@ -51,6 +40,45 @@ test_that("tableDS throws error when object does not exist", { ) }) +test_that("tableDS accepts a forced nfilter given as a number", { + input <- factor(rep(c("a", "b"), each = 5)) + + res <- tableDS("input", NULL, NULL, "a,b", NULL, NULL, NULL, "no", "3") + + expect_equal(class(res), "table") + expect_equal(as.vector(res), c(5, 5)) +}) + +test_that("tableDS throws error when forced nfilter is below nfilter.tab", { + input <- factor(rep(c("a", "b"), each = 5)) + + expect_error( + tableDS("input", NULL, NULL, "a,b", NULL, NULL, NULL, "no", "1"), + regexp = "force.nfilter is non-null it must be >= to nfilter.tab" + ) +}) + +test_that("tableDS excludes levels given as literal values", { + input <- factor(rep(c("a", "b", "c"), each = 5)) + + res <- tableDS("input", NULL, NULL, "a,b,c", NULL, NULL, "a", "no", NULL) + + expect_equal(names(res), c("b", "c")) + expect_equal(as.vector(res), c(5, 5)) +}) + +test_that("tableDS treats NA in a list of excluded values as missing", { + input <- factor(c(rep(c("a", "b"), each = 5), rep(NA, 5))) + + expect_warning( + res <- tableDS("input", NULL, NULL, "a,b", NULL, NULL, "a,NA", "always", NULL), + regexp = "'exclude' containing NA" + ) + + expect_equal(names(res), "b") + expect_equal(as.vector(res), 5) +}) + # # Done # diff --git a/tests/testthat/test-smk-tableDS.assign.R b/tests/testthat/test-smk-tableDS.assign.R index a284ed28..c20b5e01 100644 --- a/tests/testthat/test-smk-tableDS.assign.R +++ b/tests/testthat/test-smk-tableDS.assign.R @@ -1,14 +1,3 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - # # Set up # diff --git a/tests/testthat/test-smk-tableDS2.R b/tests/testthat/test-smk-tableDS2.R index 7f842297..c787816c 100644 --- a/tests/testthat/test-smk-tableDS2.R +++ b/tests/testthat/test-smk-tableDS2.R @@ -1,14 +1,3 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - # # Set up # diff --git a/tests/testthat/test-smk-tapplyDS.R b/tests/testthat/test-smk-tapplyDS.R index 7925b49a..32f2ae14 100644 --- a/tests/testthat/test-smk-tapplyDS.R +++ b/tests/testthat/test-smk-tapplyDS.R @@ -158,6 +158,18 @@ test_that("simple tapplyDS, quantile", { expect_equal(res[[2]][[15]], 2.0) }) +test_that("tapplyDS throws error when X does not exist", { + index <- as.factor(c(1, 2, 1, 2, 1, 2, 1, 2)) + + expect_error(tapplyDS("nonexistent_object", "index", "mean"), regexp = "does not exist") +}) + +test_that("tapplyDS throws error when INDEX does not exist", { + x <- c(1, 2, 1, 2, 1, 2, 1, 2) + + expect_error(tapplyDS("x", "nonexistent_object", "mean"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-tapplyDS.assign.R b/tests/testthat/test-smk-tapplyDS.assign.R index 7d899a2e..abb155a7 100644 --- a/tests/testthat/test-smk-tapplyDS.assign.R +++ b/tests/testthat/test-smk-tapplyDS.assign.R @@ -51,6 +51,18 @@ test_that("simple tapplyDS.assign", { expect_equal(res$N[[2]], 4) }) +test_that("tapplyDS.assign throws error when X does not exist", { + index <- factor(c(1, 2, 1, 2, 1, 2, 1, 2)) + + expect_error(tapplyDS.assign("nonexistent_object", "index", "mean"), regexp = "does not exist") +}) + +test_that("tapplyDS.assign throws error when INDEX does not exist", { + x <- c(1, 2, 1, 2, 1, 2, 1, 2) + + expect_error(tapplyDS.assign("x", "nonexistent_object", "mean"), regexp = "does not exist") +}) + # # Done # From 6dbf845d68924b636377ad23dfbd5bd681b6ad34 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Mon, 21 Sep 2026 13:21:13 +0200 Subject: [PATCH 10/38] chore: ignore plots --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f4edd3a2..dba745c0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ .Rapp.history .claude .idea +tests/testthat/Rplots.pdf From 41046bd043eb742738571860264702bdefd08960 Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 12:34:49 +0100 Subject: [PATCH 11/38] Fix setting of PERF.PROFILE env variable --- azure-pipelines.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 94c767e9..3d412045 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -27,8 +27,7 @@ variables: branchName: $(Build.SourceBranchName) test_filter: '*' _r_check_system_clock_: 0 - PERF_PROFILE: 'azure-pipeline' - + perf.profile: 'azure-pipeline' ######################################################################################### @@ -184,7 +183,7 @@ jobs: # R output and messages are redirected by sink() to test_console_output.txt # junit reporter output is to test_results.xml - sudo R -q -e ' + sudo env PERF_PROFILE=$PERF_PROFILE R -q -e ' library(covr); write.csv( coverage_to_list( From 1923a11d90f111bf09170c997fd9328aa5ed18b1 Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 13:36:03 +0100 Subject: [PATCH 12/38] Update to Circle CI code coverage --- .circleci/config.yml | 22 ++++++---------------- azure-pipelines.yml | 4 ++-- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ec6d40e9..f944e3ab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,22 +26,12 @@ jobs: - run: command: | echo "options(Ncpus=4)" >> ~/.Rprofile - sudo Rscript -e "install.packages('RANN', dependencies=TRUE)" - sudo Rscript -e "install.packages('stringr', dependencies=TRUE)" - sudo Rscript -e "install.packages('lme4', dependencies=TRUE)" - sudo Rscript -e "install.packages('dplyr', dependencies=TRUE)" - sudo Rscript -e "install.packages('reshape2', dependencies=TRUE)" - sudo Rscript -e "install.packages('polycor', dependencies=TRUE)" - sudo Rscript -e "install.packages('splines', dependencies=TRUE)" - sudo Rscript -e "install.packages('gamlss', dependencies=TRUE)" - sudo Rscript -e "install.packages('gamlss.dist', dependencies=TRUE)" - sudo Rscript -e "install.packages('mice', dependencies=TRUE)" - sudo Rscript -e "install.packages('childsds', dependencies=TRUE)" - sudo Rscript -e "install.packages('xml2', dependencies=TRUE)" - sudo Rscript -e "install.packages('covr', dependencies=TRUE)" - sudo Rscript -e "install.packages('devtools', dependencies=TRUE)" - sudo Rscript -e "install.packages('DSI', dependencies=TRUE)" - sudo Rscript -e "install.packages('DSLite', dependencies=TRUE)" + + # Use Posit Public Package Manager, which serves precompiled binary packages + # for this Ubuntu release instead of source - so dependencies are downloaded + # rather than compiled (the slow part). The HTTPUserAgent option is what makes + # the manager hand back binaries. + sudo R -q -e "options(repos=c(CRAN=paste0('https://packagemanager.posit.co/cran/__linux__/', system('lsb_release -cs', intern=TRUE), '/latest')), HTTPUserAgent=sprintf('R/%s> - run: command: | sudo Rscript -e 'library(covr); covr::codecov(token = "'$CODECOV_TOKEN'")' diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3d412045..77679f06 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -49,13 +49,13 @@ schedules: displayName: Weekly build - latest release branches: include: - - 6.3.4 + - 6.3.5 always: true - cron: "0 1 * * *" displayName: Nightly build - development branchs branches: include: - - v6.3.5-dev + - v6.3.6-dev - v6.4.0-dev - v7.0.0-dev always: true From f670258ea21afdb6692417c29a056266b1bebc38 Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 13:40:36 +0100 Subject: [PATCH 13/38] Fixed Comments, I hope --- .circleci/config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f944e3ab..278e2716 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,10 +27,10 @@ jobs: command: | echo "options(Ncpus=4)" >> ~/.Rprofile - # Use Posit Public Package Manager, which serves precompiled binary packages - # for this Ubuntu release instead of source - so dependencies are downloaded - # rather than compiled (the slow part). The HTTPUserAgent option is what makes - # the manager hand back binaries. +# Use Posit Public Package Manager, which serves precompiled binary packages +# for this Ubuntu release instead of source - so dependencies are downloaded +# rather than compiled (the slow part). The HTTPUserAgent option is what makes +# the manager hand back binaries. sudo R -q -e "options(repos=c(CRAN=paste0('https://packagemanager.posit.co/cran/__linux__/', system('lsb_release -cs', intern=TRUE), '/latest')), HTTPUserAgent=sprintf('R/%s> - run: command: | From eec1ebe5cb8f935b0cbad5ea9b6c2928db86cc72 Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 13:42:57 +0100 Subject: [PATCH 14/38] Fixed Comments --- .circleci/config.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 278e2716..404c595c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,11 +26,6 @@ jobs: - run: command: | echo "options(Ncpus=4)" >> ~/.Rprofile - -# Use Posit Public Package Manager, which serves precompiled binary packages -# for this Ubuntu release instead of source - so dependencies are downloaded -# rather than compiled (the slow part). The HTTPUserAgent option is what makes -# the manager hand back binaries. sudo R -q -e "options(repos=c(CRAN=paste0('https://packagemanager.posit.co/cran/__linux__/', system('lsb_release -cs', intern=TRUE), '/latest')), HTTPUserAgent=sprintf('R/%s> - run: command: | From c867e6e0130667d72d3c11d63945f5248f3940bb Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 14:07:24 +0100 Subject: [PATCH 15/38] Fixed Comments --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 404c595c..7ee4e084 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,8 @@ jobs: - run: command: | echo "options(Ncpus=4)" >> ~/.Rprofile - sudo R -q -e "options(repos=c(CRAN=paste0('https://packagemanager.posit.co/cran/__linux__/', system('lsb_release -cs', intern=TRUE), '/latest')), HTTPUserAgent=sprintf('R/%s> + + sudo R -q -e "options(repos=c(CRAN=paste0('https://packagemanager.posit.co/cran/__linux__/', system('lsb_release -cs', intern=TRUE), '/latest')), HTTPUserAgent=sprintf('R/%s R (%s)', getRversion(), paste(getRversion(), R.version\$platform, R.version\$arch, R.version\$os)), Ncpus=4); install.packages(c('devtools','RANN','stringr','lme4','dplyr','reshape2','polycor','splines','gamlss','gamlss.dist','mice','data.table','childsds'), dependencies=TRUE)" - run: command: | sudo Rscript -e 'library(covr); covr::codecov(token = "'$CODECOV_TOKEN'")' From 824fb5dc2f6ba6c37ecb98a3d5120b157728edeb Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 14:38:07 +0100 Subject: [PATCH 16/38] Fix CircleCI performance --- tests/testthat/perf_files/azure-pipeline_perf-profile.csv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/perf_files/azure-pipeline_perf-profile.csv b/tests/testthat/perf_files/azure-pipeline_perf-profile.csv index 43418639..7b8753a1 100644 --- a/tests/testthat/perf_files/azure-pipeline_perf-profile.csv +++ b/tests/testthat/perf_files/azure-pipeline_perf-profile.csv @@ -1,5 +1,5 @@ "refer_name","rate","lower_tolerance","upper_tolerance" "meanDS::perf::numeric::0","4497.0","0.5","2" "meanDS::perf::numberAndNA::0","4542.0","0.5","2" -"varDS::perf::numeric::0","4584.0","0.5","2" -"varDS::perf::numberAndNA::0","4590.0","0.5","2" +"varDS::perf::numeric::0","6220.0","0.5","2" +"varDS::perf::numberAndNA::0","6250.0","0.5","2" From 45778954b86d59c12ee13a3830ffbb0ee5afe166 Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 15:15:43 +0100 Subject: [PATCH 17/38] Added debugging output --- tests/testthat/test-perf-varDS.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/testthat/test-perf-varDS.R b/tests/testthat/test-perf-varDS.R index d7e2131c..daffd00b 100644 --- a/tests/testthat/test-perf-varDS.R +++ b/tests/testthat/test-perf-varDS.R @@ -51,6 +51,8 @@ test_that("numeric varDS - performance", { print(paste("varDS::perf::numeric::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = '')) } + write(.current.rate, stderr()) + .reference.rate <- perf.reference.rate("varDS::perf::numeric::0") .reference.tolerance.lower <- perf.reference.tolerance.lower("varDS::perf::numeric::0") .reference.tolerance.upper <- perf.reference.tolerance.upper("varDS::perf::numeric::0") @@ -86,10 +88,16 @@ test_that("numeric varDS, with NA - performance", { print(paste("varDS::perf::numberAndNA::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = '')) } + write(.current.rate, stderr()) + .reference.rate <- perf.reference.rate("varDS::perf::numberAndNA::0") .reference.tolerance.lower <- perf.reference.tolerance.lower("varDS::perf::numberAndNA::0") .reference.tolerance.upper <- perf.reference.tolerance.upper("varDS::perf::numberAndNA::0") + write(.current.rate, stderr()) + write(.reference.rate * .reference.tolerance.lower, stderr()) + write(.reference.rate * .reference.tolerance.upper, stderr()) + expect_gt(.current.rate, .reference.rate * .reference.tolerance.lower, label = "Observed rate", expected.label = "lower threshold on rate") expect_lt(.current.rate, .reference.rate * .reference.tolerance.upper, label = "Observed rate", expected.label = "upper threshold on rate") }) From cfead15bef74ed047b8bfa145c6ce1be98b10e2e Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 15:34:39 +0100 Subject: [PATCH 18/38] Added debugging output --- tests/testthat/test-perf-varDS.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-perf-varDS.R b/tests/testthat/test-perf-varDS.R index daffd00b..3b7b0fac 100644 --- a/tests/testthat/test-perf-varDS.R +++ b/tests/testthat/test-perf-varDS.R @@ -51,7 +51,7 @@ test_that("numeric varDS - performance", { print(paste("varDS::perf::numeric::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = '')) } - write(.current.rate, stderr()) + expect_equal(.current.rate, 0.0) .reference.rate <- perf.reference.rate("varDS::perf::numeric::0") .reference.tolerance.lower <- perf.reference.tolerance.lower("varDS::perf::numeric::0") @@ -88,15 +88,15 @@ test_that("numeric varDS, with NA - performance", { print(paste("varDS::perf::numberAndNA::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = '')) } - write(.current.rate, stderr()) + expect_equal(.current.rate, 0.0) .reference.rate <- perf.reference.rate("varDS::perf::numberAndNA::0") .reference.tolerance.lower <- perf.reference.tolerance.lower("varDS::perf::numberAndNA::0") .reference.tolerance.upper <- perf.reference.tolerance.upper("varDS::perf::numberAndNA::0") - write(.current.rate, stderr()) - write(.reference.rate * .reference.tolerance.lower, stderr()) - write(.reference.rate * .reference.tolerance.upper, stderr()) + expect_equal(.current.rate, 0.0) + expect_equal(.reference.rate * .reference.tolerance.lower, 0.0) + expect_equal(.reference.rate * .reference.tolerance.upper, 0.0) expect_gt(.current.rate, .reference.rate * .reference.tolerance.lower, label = "Observed rate", expected.label = "lower threshold on rate") expect_lt(.current.rate, .reference.rate * .reference.tolerance.upper, label = "Observed rate", expected.label = "upper threshold on rate") From a3540d1b0aef77930f600f674cd5b66d3f83aa77 Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 15:59:42 +0100 Subject: [PATCH 19/38] Remove debug code and adjust perf profile --- tests/testthat/perf_files/azure-pipeline_perf-profile.csv | 4 ++-- tests/testthat/test-perf-varDS.R | 8 -------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/testthat/perf_files/azure-pipeline_perf-profile.csv b/tests/testthat/perf_files/azure-pipeline_perf-profile.csv index 7b8753a1..d1fcd743 100644 --- a/tests/testthat/perf_files/azure-pipeline_perf-profile.csv +++ b/tests/testthat/perf_files/azure-pipeline_perf-profile.csv @@ -1,5 +1,5 @@ "refer_name","rate","lower_tolerance","upper_tolerance" "meanDS::perf::numeric::0","4497.0","0.5","2" "meanDS::perf::numberAndNA::0","4542.0","0.5","2" -"varDS::perf::numeric::0","6220.0","0.5","2" -"varDS::perf::numberAndNA::0","6250.0","0.5","2" +"varDS::perf::numeric::0","6373.0","0.5","2" +"varDS::perf::numberAndNA::0","25090.0","0.5","2" diff --git a/tests/testthat/test-perf-varDS.R b/tests/testthat/test-perf-varDS.R index 3b7b0fac..d7e2131c 100644 --- a/tests/testthat/test-perf-varDS.R +++ b/tests/testthat/test-perf-varDS.R @@ -51,8 +51,6 @@ test_that("numeric varDS - performance", { print(paste("varDS::perf::numeric::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = '')) } - expect_equal(.current.rate, 0.0) - .reference.rate <- perf.reference.rate("varDS::perf::numeric::0") .reference.tolerance.lower <- perf.reference.tolerance.lower("varDS::perf::numeric::0") .reference.tolerance.upper <- perf.reference.tolerance.upper("varDS::perf::numeric::0") @@ -88,16 +86,10 @@ test_that("numeric varDS, with NA - performance", { print(paste("varDS::perf::numberAndNA::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = '')) } - expect_equal(.current.rate, 0.0) - .reference.rate <- perf.reference.rate("varDS::perf::numberAndNA::0") .reference.tolerance.lower <- perf.reference.tolerance.lower("varDS::perf::numberAndNA::0") .reference.tolerance.upper <- perf.reference.tolerance.upper("varDS::perf::numberAndNA::0") - expect_equal(.current.rate, 0.0) - expect_equal(.reference.rate * .reference.tolerance.lower, 0.0) - expect_equal(.reference.rate * .reference.tolerance.upper, 0.0) - expect_gt(.current.rate, .reference.rate * .reference.tolerance.lower, label = "Observed rate", expected.label = "lower threshold on rate") expect_lt(.current.rate, .reference.rate * .reference.tolerance.upper, label = "Observed rate", expected.label = "upper threshold on rate") }) From 68f60165685482336b98711231b4743111e1ce91 Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 17:00:43 +0100 Subject: [PATCH 20/38] Update logging --- tests/testthat/test-perf-meanDS.R | 8 ++++---- tests/testthat/test-perf-varDS.R | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-perf-meanDS.R b/tests/testthat/test-perf-meanDS.R index d6355336..617b0481 100644 --- a/tests/testthat/test-perf-meanDS.R +++ b/tests/testthat/test-perf-meanDS.R @@ -45,10 +45,10 @@ test_that("numeric meanDS - performance", { .current.rate <- .count / (difftime(.current.time, .start.time, units = "secs")[[1]]) .reference.rate <- perf.reference.rate("meanDS::perf::numeric::0") if (any(length(.reference.rate) == 0) || any(is.null(.reference.rate))) { - print(paste("meanDS::perf::numeric::0 ", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper())) + write(paste("meanDS::perf::numeric::0 ", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper()), stderr()) perf.reference.save("meanDS::perf::numeric::0", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper()) } else { - print(paste("meanDS::perf::numeric::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = '')) + write(paste("meanDS::perf::numeric::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = ''), stderr()) } .reference.rate <- perf.reference.rate("meanDS::perf::numeric::0") @@ -80,10 +80,10 @@ test_that("numeric meanDS, with NA - performance", { .current.rate <- .count / (difftime(.current.time, .start.time, units = "secs")[[1]]) .reference.rate <- perf.reference.rate("meanDS::perf::numberAndNA::0") if (any(length(.reference.rate) == 0) || any(is.null(.reference.rate))) { - print(paste("meanDS::perf::numberAndNA::0 ", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper())) + write(paste("meanDS::perf::numberAndNA::0 ", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper()), stderr()) perf.reference.save("meanDS::perf::numberAndNA::0", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper()) } else { - print(paste("meanDS::perf::numberAndNA::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = '')) + write(paste("meanDS::perf::numberAndNA::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = ''), stderr()) } .reference.rate <- perf.reference.rate("meanDS::perf::numberAndNA::0") diff --git a/tests/testthat/test-perf-varDS.R b/tests/testthat/test-perf-varDS.R index d7e2131c..2bb8205d 100644 --- a/tests/testthat/test-perf-varDS.R +++ b/tests/testthat/test-perf-varDS.R @@ -45,10 +45,10 @@ test_that("numeric varDS - performance", { .current.rate <- .count / (difftime(.current.time, .start.time, units = "secs")[[1]]) .reference.rate <- perf.reference.rate("varDS::perf::numeric::0") if (any(length(.reference.rate) == 0) || any(is.null(.reference.rate))) { - print(paste("varDS::perf::numeric::0 ", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper())) + write(paste("varDS::perf::numeric::0 ", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper()), stderr()) perf.reference.save("varDS::perf::numeric::0", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper()) } else { - print(paste("varDS::perf::numeric::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = '')) + write((paste("varDS::perf::numeric::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = ''), stderr()) } .reference.rate <- perf.reference.rate("varDS::perf::numeric::0") @@ -80,10 +80,10 @@ test_that("numeric varDS, with NA - performance", { .current.rate <- .count / (difftime(.current.time, .start.time, units = "secs")[[1]]) .reference.rate <- perf.reference.rate("varDS::perf::numberAndNA::0") if (any(length(.reference.rate) == 0) || any(is.null(.reference.rate))) { - print(paste("varDS::perf::numberAndNA::0 ", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper())) + write(paste("varDS::perf::numberAndNA::0 ", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper()), stderr()) perf.reference.save("varDS::perf::numberAndNA::0", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper()) } else { - print(paste("varDS::perf::numberAndNA::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = '')) + write(paste("varDS::perf::numberAndNA::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = ''), stderr()) } .reference.rate <- perf.reference.rate("varDS::perf::numberAndNA::0") From fd3db55e55839b83685337cc1959f0d891d8cb0f Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 17:15:10 +0100 Subject: [PATCH 21/38] Fix code typo --- tests/testthat/test-perf-varDS.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-perf-varDS.R b/tests/testthat/test-perf-varDS.R index 2bb8205d..4f1f18e0 100644 --- a/tests/testthat/test-perf-varDS.R +++ b/tests/testthat/test-perf-varDS.R @@ -48,7 +48,7 @@ test_that("numeric varDS - performance", { write(paste("varDS::perf::numeric::0 ", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper()), stderr()) perf.reference.save("varDS::perf::numeric::0", .current.rate, perf.profile.tolerance.lower(), perf.profile.tolerance.upper()) } else { - write((paste("varDS::perf::numeric::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = ''), stderr()) + write(paste("varDS::perf::numeric::0 ", format(.current.rate, digits = 8), ", ", format(100.0 * .current.rate / .reference.rate, digits = 4), "%", sep = ''), stderr()) } .reference.rate <- perf.reference.rate("varDS::perf::numeric::0") From 59d76dec279903cda453b6a3b2e6f0f8664aef30 Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Mon, 21 Sep 2026 17:33:20 +0100 Subject: [PATCH 22/38] Fix perf profile --- tests/testthat/perf_files/azure-pipeline_perf-profile.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/perf_files/azure-pipeline_perf-profile.csv b/tests/testthat/perf_files/azure-pipeline_perf-profile.csv index d1fcd743..5267505e 100644 --- a/tests/testthat/perf_files/azure-pipeline_perf-profile.csv +++ b/tests/testthat/perf_files/azure-pipeline_perf-profile.csv @@ -2,4 +2,4 @@ "meanDS::perf::numeric::0","4497.0","0.5","2" "meanDS::perf::numberAndNA::0","4542.0","0.5","2" "varDS::perf::numeric::0","6373.0","0.5","2" -"varDS::perf::numberAndNA::0","25090.0","0.5","2" +"varDS::perf::numberAndNA::0","4500.0","0.5","2" From 4ad51ebf76538c7daa1708649c590571f1e579ed Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Tue, 22 Sep 2026 12:33:51 +0200 Subject: [PATCH 23/38] refactor last functions --- R/aucDS.R | 9 +++------ R/bp_standardsDS.R | 17 +++++------------ R/igb_standardsDS.R | 13 +++++-------- R/mdPatternDS.R | 25 ++++++------------------- man/aucDS.Rd | 2 ++ man/bp_standardsDS.Rd | 2 ++ man/igb_standardsDS.Rd | 2 ++ man/mdPatternDS.Rd | 3 +++ 8 files changed, 28 insertions(+), 45 deletions(-) diff --git a/R/aucDS.R b/R/aucDS.R index 6afda830..7229212c 100644 --- a/R/aucDS.R +++ b/R/aucDS.R @@ -8,16 +8,13 @@ #' the complete cases that are used in the regression model. #' @return returns the AUC and its standard error #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export #' aucDS <- function(pred=pred, y=y){ - if(is.character(pred)){ - pred <- eval(parse(text = pred), envir = parent.frame()) - } - if(is.character(y)){ - y <- eval(parse(text = y), envir = parent.frame()) - } + pred <- .loadServersideObject(pred) + y <- .loadServersideObject(y) y <- as.numeric(as.character(y)) diff --git a/R/bp_standardsDS.R b/R/bp_standardsDS.R index f90e683e..8d6baec7 100644 --- a/R/bp_standardsDS.R +++ b/R/bp_standardsDS.R @@ -20,23 +20,16 @@ #' @note The z-scores of height based on CDC growth charts are calculated #' by the sds function from the childsds R package. #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @import childsds #' @export #' bp_standardsDS <- function(sex=sex, age=age, height=height, bp=bp, systolic=systolic){ - if(is.character(sex)){ - sex <- eval(parse(text = sex), envir = parent.frame()) - } - if(is.character(age)){ - age <- eval(parse(text = age), envir = parent.frame()) - } - if(is.character(height)){ - height <- eval(parse(text = height), envir = parent.frame()) - } - if(is.character(bp)){ - bp <- eval(parse(text = bp), envir = parent.frame()) - } + sex <- .loadServersideObject(sex) + age <- .loadServersideObject(age) + height <- .loadServersideObject(height) + bp <- .loadServersideObject(bp) # convert height to a Z-score relative to age and sex based on CDC growth charts Zht <- sds(value=height, age=age, sex=sex, male="1", female="2", diff --git a/R/igb_standardsDS.R b/R/igb_standardsDS.R index e30247cb..13a19afc 100644 --- a/R/igb_standardsDS.R +++ b/R/igb_standardsDS.R @@ -17,6 +17,7 @@ #' standard is used. #' @return assigns the converted measurement as a new object on the server-side #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @import dplyr #' @importFrom gamlss.dist qST3 pST3 #' @export @@ -228,15 +229,11 @@ igb_standardsDS <- function(gagebrth=gagebrth, z=z, p=p, val=val, var=var, sex=s # Start the analysis - if(is.character(gagebrth)){ - gagebrth <- eval(parse(text = gagebrth), envir = parent.frame()) - } - if(is.character(val)){ - val <- eval(parse(text = val), envir = parent.frame()) - } - if(is.character(sex)){ - sex <- eval(parse(text = sex), envir = parent.frame()) + gagebrth <- .loadServersideObject(gagebrth) + if(!is.null(val)){ + val <- .loadServersideObject(val) } + sex <- .loadServersideObject(sex) x.out <- rep(NA, t=length(sex)) idx.males <- which(sex=="Male") diff --git a/R/mdPatternDS.R b/R/mdPatternDS.R index 0f817034..66dbaaba 100644 --- a/R/mdPatternDS.R +++ b/R/mdPatternDS.R @@ -36,7 +36,9 @@ #' \item{pattern}{The missing data pattern matrix with disclosure control applied} #' \item{valid}{Logical indicating if all patterns meet disclosure requirements} #' \item{message}{A message describing the validity status} +#' \item{class}{The class of the input object, for client-side consistency checking} #' @author Xavier Escribà montagut for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @import mice #' @export #' @@ -48,24 +50,8 @@ mdPatternDS <- function(x){ nfilter.tab <- as.numeric(thr$nfilter.tab) ############################################################# - # Parse the input data name with error handling - x.val <- tryCatch( - { - eval(parse(text=x), envir = parent.frame()) - }, - error = function(e) { - stop(paste0("Object '", x, "' does not exist on the server"), call. = FALSE) - } - ) - - # Check object class - typ <- class(x.val) - - # Check that input is a data frame or matrix - if(!("data.frame" %in% typ || "matrix" %in% typ)){ - stop(paste0("The input object must be of type 'data.frame' or 'matrix'. Current type: ", - paste(typ, collapse = ", ")), call. = FALSE) - } + x.val <- .loadServersideObject(x) + .checkClass(obj = x.val, obj_name = x, permitted_classes = c("data.frame", "matrix")) # Use x.val for further processing x <- x.val @@ -113,7 +99,8 @@ mdPatternDS <- function(x){ message = ifelse(validity == "valid", "Valid: all pattern counts meet disclosure requirements", paste0("Invalid: some pattern counts below threshold (", - nfilter.tab, ") have been suppressed")) + nfilter.tab, ") have been suppressed")), + class = class(x.val) )) } diff --git a/man/aucDS.Rd b/man/aucDS.Rd index 567f2e38..b1d4cb30 100644 --- a/man/aucDS.Rd +++ b/man/aucDS.Rd @@ -24,4 +24,6 @@ The AUC determines the discriminative ability of a model. } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/bp_standardsDS.Rd b/man/bp_standardsDS.Rd index 1b26b9f5..cfafb344 100644 --- a/man/bp_standardsDS.Rd +++ b/man/bp_standardsDS.Rd @@ -45,4 +45,6 @@ by the sds function from the childsds R package. } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/igb_standardsDS.Rd b/man/igb_standardsDS.Rd index 99fd30e0..4eed445d 100644 --- a/man/igb_standardsDS.Rd +++ b/man/igb_standardsDS.Rd @@ -46,4 +46,6 @@ standard is used. } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/mdPatternDS.Rd b/man/mdPatternDS.Rd index 1084565e..6295c024 100644 --- a/man/mdPatternDS.Rd +++ b/man/mdPatternDS.Rd @@ -15,6 +15,7 @@ A list containing: \item{pattern}{The missing data pattern matrix with disclosure control applied} \item{valid}{Logical indicating if all patterns meet disclosure requirements} \item{message}{A message describing the validity status} +\item{class}{The class of the input object, for client-side consistency checking} } \description{ This function is a serverside aggregate function that computes the @@ -51,4 +52,6 @@ suppressed in some studies. } \author{ Xavier Escribà montagut for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } From 5a4dcd1023bcf755723e845ece80946b947efdd0 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Tue, 22 Sep 2026 12:34:00 +0200 Subject: [PATCH 24/38] add tests for last functions --- tests/testthat/test-arg-mdPatternDS.R | 12 ++++++++++-- tests/testthat/test-disc-mdPatternDS.R | 2 +- tests/testthat/test-smk-aucDS.R | 14 +++++++++++++- tests/testthat/test-smk-bp_standardsDS.R | 12 ++++++++++-- tests/testthat/test-smk-igb_standardsDS.R | 12 ++++++++++++ tests/testthat/test-smk-mdPatternDS.R | 4 ++-- 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-arg-mdPatternDS.R b/tests/testthat/test-arg-mdPatternDS.R index 989deb76..e2ce112d 100644 --- a/tests/testthat/test-arg-mdPatternDS.R +++ b/tests/testthat/test-arg-mdPatternDS.R @@ -24,14 +24,22 @@ set.standard.disclosure.settings() test_that("mdPatternDS x NULL", { x <- NULL - expect_error(mdPatternDS(x), "The input object must be of type 'data.frame' or 'matrix'. Current type: NULL") + expect_error(mdPatternDS(x), "The input must be a single character string") }) # context("mdPatternDS::arg::x not valid variable") test_that("mdPatternDS x not variable", { x <- "not a variable" - expect_error(mdPatternDS(x), "Object 'not a variable' does not exist on the server") + expect_error(mdPatternDS(x), "does not exist") +}) + +# context("mdPatternDS::arg::x wrong type") +test_that("mdPatternDS x wrong type", { + x_val <- c(1.0, 2.0, 3.0) + x <- "x_val" + + expect_error(mdPatternDS(x), "must be of type data.frame or matrix") }) # diff --git a/tests/testthat/test-disc-mdPatternDS.R b/tests/testthat/test-disc-mdPatternDS.R index d10b004a..6f6a7c01 100644 --- a/tests/testthat/test-disc-mdPatternDS.R +++ b/tests/testthat/test-disc-mdPatternDS.R @@ -27,7 +27,7 @@ test_that("mdPatternDS: sample incomplete data.frame", { res <- mdPatternDS(x) - expect_length(res, 3) + expect_length(res, 4) expect_length(class(res), 1) expect_true(all(class(res) %in% c("list"))) expect_length(class(res$pattern), 2) diff --git a/tests/testthat/test-smk-aucDS.R b/tests/testthat/test-smk-aucDS.R index bcbbada1..c33d2eee 100644 --- a/tests/testthat/test-smk-aucDS.R +++ b/tests/testthat/test-smk-aucDS.R @@ -25,7 +25,7 @@ test_that("aucDS", { model <- glm(formula = D$DIS_DIAB~D$GENDER+D$PM_BMI_CONTINUOUS, family = 'binomial') pred <- predict(object = model, type = "link") - res <- aucDS(pred = pred, y = model$y) + res <- aucDS(pred = "pred", y = "model$y") expect_equal(class(res), "list") expect_length(res, 2) @@ -36,6 +36,18 @@ test_that("aucDS", { }) +test_that("aucDS throws error when pred does not exist", { + y <- c(0, 1, 0, 1) + + expect_error(aucDS(pred = "nonexistent_object", y = "y"), regexp = "does not exist") +}) + +test_that("aucDS throws error when y does not exist", { + pred <- c(0.1, 0.8, 0.3, 0.9) + + expect_error(aucDS(pred = "pred", y = "nonexistent_object"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-bp_standardsDS.R b/tests/testthat/test-smk-bp_standardsDS.R index fe8b9bc1..06fa5519 100644 --- a/tests/testthat/test-smk-bp_standardsDS.R +++ b/tests/testthat/test-smk-bp_standardsDS.R @@ -28,7 +28,7 @@ test_that("systolic bp_standardsDS", { bp <- c(118.54, 87.62, 72.13, 91.18, 88.47, 73.28, 100.27, 86.84, 103.51, 115.28) systolic <- TRUE - res <- bp_standardsDS(sex=sex, age=age, height=height, bp=bp, systolic=systolic) + res <- bp_standardsDS(sex="sex", age="age", height="height", bp="bp", systolic=systolic) expect_equal(class(res), "list") expect_length(res, 2) @@ -56,7 +56,7 @@ test_that("diastolic bp_standardsDS", { bp <- c(118.54, 87.62, 72.13, 91.18, 88.47, 73.28, 100.27, 86.84, 103.51, 115.28) systolic <- FALSE - res <- bp_standardsDS(sex=sex, age=age, height=height, bp=bp, systolic=systolic) + res <- bp_standardsDS(sex="sex", age="age", height="height", bp="bp", systolic=systolic) expect_equal(class(res), "list") expect_length(res, 2) @@ -76,6 +76,14 @@ test_that("diastolic bp_standardsDS", { }) +test_that("bp_standardsDS throws error when an input does not exist", { + sex <- c(2, 1) + age <- c(5.26, 7.73) + height <- c(113.57, 92.30) + + expect_error(bp_standardsDS(sex="sex", age="age", height="height", bp="nonexistent_object", systolic=TRUE), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-igb_standardsDS.R b/tests/testthat/test-smk-igb_standardsDS.R index bd3a8f79..f3f11a16 100644 --- a/tests/testthat/test-smk-igb_standardsDS.R +++ b/tests/testthat/test-smk-igb_standardsDS.R @@ -154,6 +154,18 @@ test_that("igb_standardsDS - igb_centile2value", { }) +test_that("igb_standardsDS throws error when gagebrth does not exist", { + data <- data.frame(sex = c("Male", "Female")) + + expect_error(igb_standardsDS(gagebrth="nonexistent_object", z=0, p=50, val=NULL, var="lencm", sex="data$sex", fun="igb_centile2value"), regexp = "does not exist") +}) + +test_that("igb_standardsDS throws error when val does not exist", { + data <- data.frame(gagebrth = c(250, 270), sex = c("Male", "Female")) + + expect_error(igb_standardsDS(gagebrth="data$gagebrth", z=0, p=50, val="nonexistent_object", var="lencm", sex="data$sex", fun="igb_value2zscore"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-mdPatternDS.R b/tests/testthat/test-smk-mdPatternDS.R index ba682b1e..3e11a024 100644 --- a/tests/testthat/test-smk-mdPatternDS.R +++ b/tests/testthat/test-smk-mdPatternDS.R @@ -27,7 +27,7 @@ test_that("mdPatternDS: sample 1 complete data.frame", { res <- mdPatternDS(x) - expect_length(res, 3) + expect_length(res, 4) expect_length(class(res), 1) expect_true(all(class(res) %in% c("list"))) expect_length(class(res$pattern), 2) @@ -64,7 +64,7 @@ test_that("mdPatternDS: sample 2 complete data.frame", { res <- mdPatternDS(x) - expect_length(res, 3) + expect_length(res, 4) expect_length(class(res), 1) expect_true(all(class(res) %in% c("list"))) expect_length(class(res$pattern), 2) From ad586b86d591c2b497741a86ef11a8d3f7e35ead Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Tue, 22 Sep 2026 13:31:46 +0200 Subject: [PATCH 25/38] fix issues discovered in final review --- R/BooleDS.R | 8 ++++++-- R/asListDS.R | 27 ++++++++------------------- R/corDS.R | 2 +- R/covDS.R | 2 +- R/dataFrameSortDS.R | 2 +- R/dimDS.R | 1 - R/gamlssDS.R | 5 +++-- R/glmDS1.R | 2 +- R/glmDS2.R | 2 +- R/glmSLMADS1.R | 2 +- R/glmSLMADS2.R | 2 +- R/glmerSLMADS.assign.R | 2 +- R/glmerSLMADS2.R | 2 +- R/lengthDS.R | 1 - R/levelsDS.R | 8 ++++---- R/lmerSLMADS.assign.R | 22 +++++++++------------- R/lmerSLMADS2.R | 20 ++++++++------------ R/meanDS.R | 2 +- R/meanSdGpDS.R | 2 +- R/miceDS.R | 5 +++-- R/seqDS.R | 16 ++++++++-------- R/utils.R | 7 ++++++- R/varDS.R | 2 +- man/asListDS.Rd | 23 ++++++----------------- man/dataFrameSortDS.Rd | 2 +- man/levelsDS.Rd | 2 +- 26 files changed, 75 insertions(+), 96 deletions(-) diff --git a/R/BooleDS.R b/R/BooleDS.R index 7081e32a..ee967f7f 100644 --- a/R/BooleDS.R +++ b/R/BooleDS.R @@ -53,9 +53,13 @@ thr <- dsBase::listDisclosureSettingsDS() # V1<-.loadServersideObject(V1.name) -# V2 may be either a server-side object name or a literal scalar (e.g. "3", "-1") +# V2 may be either a server-side object name or a literal scalar (e.g. "3", "-1", "TRUE", "NA") V2.numeric <- suppressWarnings(as.numeric(V2.name)) -if(!is.na(V2.numeric)){ +if(V2.name %in% c("TRUE", "FALSE")){ + V2 <- as.logical(V2.name) +}else if(V2.name == "NA"){ + V2 <- NA +}else if(!is.na(V2.numeric)){ V2 <- V2.numeric }else{ V2 <- .loadServersideObject(V2.name) diff --git a/R/asListDS.R b/R/asListDS.R index f912594e..b6ffb829 100644 --- a/R/asListDS.R +++ b/R/asListDS.R @@ -1,32 +1,21 @@ -#' @title asListDS a serverside aggregate function called by ds.asList +#' @title asListDS a serverside assign function called by ds.asList #' @description Coerces an R object into a list -#' @details Unlike most other class coercing functions this is -#' an aggregate function rather than an assign function. This -#' is because the \code{datashield.assign} function in the data repository deals specially with -#' a created object (newobj) if it is of class list. Reconfiguring the -#' function as an aggregate function works around this problem. -#' This aggregate function is based on the native R function \code{as.list} +#' @details This assign function is based on the native R function \code{as.list} #' and so additional information can be found in the help for \code{as.list} #' @param x.name the name of the input object to be coerced to class #' data.matrix. Must be specified in inverted commas. But this argument is #' usually specified directly by argument of the clientside function #' \code{ds.asList} -#' @param newobj is the object hard assigned '<<-' to be the output of the -#' function written to the serverside -#' @return the object specified by the argument (or its default name -#' .mat) which is written to the serverside. -#' In addition, two validity messages are returned. The first confirms an output -#' object has been created, the second states its class. The way that \code{as.list} -#' coerces objects to list depends on the class of the object, but in general -#' the class of the output object should usually be 'list' +#' @return the input object coerced to a list, which \code{ds.asList} writes to the +#' serverside. The way that \code{as.list} coerces objects to list depends on the class +#' of the object #' @author Amadou Gaye, Paul Burton for DataSHIELD Development Team #' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export -asListDS <- function (x.name, newobj){ +asListDS <- function (x.name){ x <- .loadServersideObject(x.name) - result <- as.list(x) - assign(newobj, result, envir = parent.frame()) + as.list(x) } -# AGGREGATE FUNCTION +# ASSIGN FUNCTION # asListDS diff --git a/R/corDS.R b/R/corDS.R index 6133b4e0..9653900a 100644 --- a/R/corDS.R +++ b/R/corDS.R @@ -32,7 +32,7 @@ corDS <- function(x=NULL, y=NULL){ x.val <- .loadServersideObject(x) .checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) - if (!is.null(y)){ + if (!is.null(y) && !any(class(x.val) %in% c("matrix", "data.frame"))){ y.val <- .loadServersideObject(y) .checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) } diff --git a/R/covDS.R b/R/covDS.R index fe25eabd..84f8f66b 100644 --- a/R/covDS.R +++ b/R/covDS.R @@ -41,7 +41,7 @@ covDS <- function(x=NULL, y=NULL, use=NULL){ x.val <- .loadServersideObject(x) .checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) - if (!is.null(y)){ + if (!is.null(y) && !any(class(x.val) %in% c("matrix", "data.frame"))){ y.val <- .loadServersideObject(y) .checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) } diff --git a/R/dataFrameSortDS.R b/R/dataFrameSortDS.R index 9801d804..c51b33e0 100644 --- a/R/dataFrameSortDS.R +++ b/R/dataFrameSortDS.R @@ -30,8 +30,8 @@ #' R environment as a data.frame named according to the argument(or with #' default name 'dataframesort.newobj') if no name is specified #' @author Paul Burton, with critical error identification by -#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' Leire Abarrategui-Martinez, for DataSHIELD Development Team, 2/4/2020 +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export #' dataFrameSortDS <- function(df.name=NULL,sort.key.name=NULL,sort.descending,sort.method){ diff --git a/R/dimDS.R b/R/dimDS.R index c27db5b5..6a1e9e1f 100644 --- a/R/dimDS.R +++ b/R/dimDS.R @@ -11,7 +11,6 @@ #' dimDS <- function(x){ x.val <- .loadServersideObject(x) - .checkClass(obj = x.val, obj_name = x, permitted_classes = c("data.frame", "matrix")) list(dim = dim(x.val), class = class(x.val)) } #AGGREGATE FUNCTION diff --git a/R/gamlssDS.R b/R/gamlssDS.R index 1789b5af..7f7ae0e0 100644 --- a/R/gamlssDS.R +++ b/R/gamlssDS.R @@ -83,8 +83,9 @@ gamlssDS <- function(formula=formula, sigma.formula=sigma.formula, nu.formula=nu thr <- dsBase::listDisclosureSettingsDS() nfilter.glm <- as.numeric(thr$nfilter.glm) - data <- .loadServersideObject(data) - .checkClass(obj = data, obj_name = "data", permitted_classes = c("data.frame", "matrix")) + data.name <- data + data <- .loadServersideObject(data.name) + .checkClass(obj = data, obj_name = data.name, permitted_classes = c("data.frame", "list")) family <- gsub("left_parenthesis", "(", family, fixed = TRUE) family <- gsub("right_parenthesis", ")", family, fixed = TRUE) diff --git a/R/glmDS1.R b/R/glmDS1.R index 568e3070..3fc2ab3c 100644 --- a/R/glmDS1.R +++ b/R/glmDS1.R @@ -43,7 +43,7 @@ nfilter.glm <- as.numeric(thr$nfilter.glm) dataTable <- NULL }else{ dataTable <- .loadServersideObject(data) - .checkClass(obj = dataTable, obj_name = data, permitted_classes = c("data.frame", "matrix")) + .checkClass(obj = dataTable, obj_name = data, permitted_classes = c("data.frame", "list")) } formulatext <- Reduce(paste, deparse(formula)) diff --git a/R/glmDS2.R b/R/glmDS2.R index 93e8edda..caff48f0 100644 --- a/R/glmDS2.R +++ b/R/glmDS2.R @@ -41,7 +41,7 @@ glmDS2 <- function (formula, family, beta.vect, offset, weights, dataName) { if(!is.null(dataName)){ dataDF <- .loadServersideObject(dataName) - .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "matrix")) + .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "list")) }else{ dataDF <- NULL } diff --git a/R/glmSLMADS1.R b/R/glmSLMADS1.R index 4cddefdb..5e594bf4 100644 --- a/R/glmSLMADS1.R +++ b/R/glmSLMADS1.R @@ -53,7 +53,7 @@ final.family.object<-eval(parse(text=family)) dataTable <- NULL }else{ dataTable <- .loadServersideObject(data) - .checkClass(obj = dataTable, obj_name = data, permitted_classes = c("data.frame", "matrix")) + .checkClass(obj = dataTable, obj_name = data, permitted_classes = c("data.frame", "list")) } diff --git a/R/glmSLMADS2.R b/R/glmSLMADS2.R index 58d1b374..20d698ae 100644 --- a/R/glmSLMADS2.R +++ b/R/glmSLMADS2.R @@ -54,7 +54,7 @@ errorMessage2<-"No errors" if(!is.null(dataName)){ dataDF <- .loadServersideObject(dataName) - .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "matrix")) + .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "list")) }else{ dataDF<-NULL } diff --git a/R/glmerSLMADS.assign.R b/R/glmerSLMADS.assign.R index 2105fea7..36c7159c 100644 --- a/R/glmerSLMADS.assign.R +++ b/R/glmerSLMADS.assign.R @@ -48,7 +48,7 @@ glmerSLMADS.assign <- function(formula, offset, weights, dataName, family, if(!is.null(dataName)){ dataDF <- .loadServersideObject(dataName) - .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "matrix")) + .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "list")) }else{ dataDF <- NULL } diff --git a/R/glmerSLMADS2.R b/R/glmerSLMADS2.R index d4b15f8c..480db660 100644 --- a/R/glmerSLMADS2.R +++ b/R/glmerSLMADS2.R @@ -55,7 +55,7 @@ glmerSLMADS2 <- function(formula, offset, weights, dataName, family, if(!is.null(dataName)){ dataDF <- .loadServersideObject(dataName) - .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "matrix")) + .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "list")) }else{ dataDF <- NULL } diff --git a/R/lengthDS.R b/R/lengthDS.R index 0441e67c..70165d99 100644 --- a/R/lengthDS.R +++ b/R/lengthDS.R @@ -12,7 +12,6 @@ #' lengthDS <- function(x){ x.val <- .loadServersideObject(x) - .checkClass(obj = x.val, obj_name = x, permitted_classes = c("character", "factor", "integer", "logical", "numeric", "list", "data.frame", "array", "matrix")) list(length = length(x.val), class = class(x.val)) } #AGGREGATE FUNCTION diff --git a/R/levelsDS.R b/R/levelsDS.R index 33c33ec6..d253bb99 100644 --- a/R/levelsDS.R +++ b/R/levelsDS.R @@ -2,7 +2,7 @@ #' @title Returns the levels of a factor vector #' @description This function is similar to R function \code{levels}. #' @details The function returns the levels of the input vector or list. -#' @param x a factor vector +#' @param x a character string, the name of a factor vector #' @return a list with one element: \code{Levels} (the factor levels present #' in the vector) #' @author Alex Westerberg, for DataSHIELD Development Team @@ -11,12 +11,12 @@ #' levelsDS <- function(x){ - x.val <- .loadServersideObject(x) - .checkClass(obj = x.val, obj_name = x, permitted_classes = "factor") - # Check Permissive Privacy Control Level. dsBase::checkPermissivePrivacyControlLevel(c('permissive', 'banana', 'carrot')) + x.val <- .loadServersideObject(x) + .checkClass(obj = x.val, obj_name = x, permitted_classes = "factor") + ################################################################## #MODULE 1: CAPTURE THE nfilter SETTINGS # thr <- dsBase::listDisclosureSettingsDS() # diff --git a/R/lmerSLMADS.assign.R b/R/lmerSLMADS.assign.R index 0aabe6b6..7731c552 100644 --- a/R/lmerSLMADS.assign.R +++ b/R/lmerSLMADS.assign.R @@ -39,7 +39,7 @@ lmerSLMADS.assign <- function(formula, offset, weights, dataName, REML = TRUE, if(!is.null(dataName)){ dataDF <- .loadServersideObject(dataName) - .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "matrix")) + .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "list")) }else{ dataDF <- NULL } @@ -126,13 +126,9 @@ lmerSLMADS.assign <- function(formula, offset, weights, dataName, REML = TRUE, ################################################################## #sort out offset and weights - # - # offset.to.use/weights.to.use are needed in two different environments: - # stats::glm() below resolves them via environment(formula2use), which is - # this function's *caller* (matching where the other formula variables are - # assigned, see the model.variables loop above); lme4::lmer() further down - # resolves them relative to its own call frame, i.e. this function's *own* - # frame. Assign to both so each modelling call finds them. + # stats::glm() finds offset.to.use/weights.to.use in the caller's frame + # (environment(formula2use)) but lme4::lmer() in this function's own frame, + # so they are assigned in both. if(is.null(offset)) { varname.offset<-NULL @@ -141,14 +137,14 @@ lmerSLMADS.assign <- function(formula, offset, weights, dataName, REML = TRUE, }else{ varname.offset <- paste0(offset) } - + if(!(is.null(offset))) { cbindtext.offset <- paste0("cbind(", offset,")") offset.to.use <- eval(parse(text=cbindtext.offset), envir = parent.frame()) assign("offset.to.use", offset.to.use, envir = parent.frame()) } - + if(is.null(weights)) { varname.weights<-NULL @@ -157,8 +153,8 @@ lmerSLMADS.assign <- function(formula, offset, weights, dataName, REML = TRUE, }else{ varname.weights <- paste0(weights) } - - + + if(!(is.null(weights))) { cbindtext.weights <- paste0("cbind(", weights,")") @@ -367,7 +363,7 @@ if(!is.null(optimizer)&&optimizer!="nloptwrap") mg <- lme4::lmer(formula2use, offset=offset.to.use, weights=weights.to.use, data=dataDF, REML = REML, verbose = verbose, control = control.obj) outlist <- mg - + } #tidy up in parent.frame() eval(quote(rm(offset.to.use)), envir = parent.frame()) diff --git a/R/lmerSLMADS2.R b/R/lmerSLMADS2.R index 68bcb465..7a1142d1 100644 --- a/R/lmerSLMADS2.R +++ b/R/lmerSLMADS2.R @@ -48,7 +48,7 @@ lmerSLMADS2 <- function(formula, offset, weights, dataName, REML = TRUE, if(!is.null(dataName)){ dataDF <- .loadServersideObject(dataName) - .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "matrix")) + .checkClass(obj = dataDF, obj_name = dataName, permitted_classes = c("data.frame", "list")) }else{ dataDF <- NULL } @@ -135,13 +135,9 @@ lmerSLMADS2 <- function(formula, offset, weights, dataName, REML = TRUE, ################################################################## #sort out offset and weights - # - # offset.to.use/weights.to.use are needed in two different environments: - # stats::glm() below resolves them via environment(formula2use), which is - # this function's *caller* (matching where the other formula variables are - # assigned, see the model.variables loop above); lme4::lmer() further down - # resolves them relative to its own call frame, i.e. this function's *own* - # frame. Assign to both so each modelling call finds them. + # stats::glm() finds offset.to.use/weights.to.use in the caller's frame + # (environment(formula2use)) but lme4::lmer() in this function's own frame, + # so they are assigned in both. if(is.null(offset)) { varname.offset<-NULL @@ -150,14 +146,14 @@ lmerSLMADS2 <- function(formula, offset, weights, dataName, REML = TRUE, }else{ varname.offset <- paste0(offset) } - + if(!(is.null(offset))) { cbindtext.offset <- paste0("cbind(", offset,")") offset.to.use <- eval(parse(text=cbindtext.offset), envir = parent.frame()) assign("offset.to.use", offset.to.use, envir = parent.frame()) } - + if(is.null(weights)) { varname.weights<-NULL @@ -166,8 +162,8 @@ lmerSLMADS2 <- function(formula, offset, weights, dataName, REML = TRUE, }else{ varname.weights <- paste0(weights) } - - + + if(!(is.null(weights))) { cbindtext.weights <- paste0("cbind(", weights,")") diff --git a/R/meanDS.R b/R/meanDS.R index 576ec1b6..49260dba 100644 --- a/R/meanDS.R +++ b/R/meanDS.R @@ -23,7 +23,7 @@ meanDS <- function(x){ ############################################################# xvect <- .loadServersideObject(x) - .checkClass(obj = xvect, obj_name = x, permitted_classes = c("numeric", "integer")) + .checkClass(obj = xvect, obj_name = x, permitted_classes = c("numeric", "integer", "logical")) out.mean <- mean(xvect, na.rm=TRUE) out.numNa <- length(which(is.na(xvect))) diff --git a/R/meanSdGpDS.R b/R/meanSdGpDS.R index eecf0dde..30b9e178 100644 --- a/R/meanSdGpDS.R +++ b/R/meanSdGpDS.R @@ -27,7 +27,7 @@ meanSdGpDS <- function (x, index){ X <- .loadServersideObject(x) .checkClass(obj = X, obj_name = x, permitted_classes = c("numeric", "integer")) INDEX <- .loadServersideObject(index) - .checkClass(obj = INDEX, obj_name = index, permitted_classes = c("factor", "character", "integer")) + .checkClass(obj = INDEX, obj_name = index, permitted_classes = c("factor", "character", "integer", "numeric")) x.class <- class(X) index.class <- class(INDEX) diff --git a/R/miceDS.R b/R/miceDS.R index 7bf0bccd..c7d68ec8 100644 --- a/R/miceDS.R +++ b/R/miceDS.R @@ -58,8 +58,9 @@ miceDS <- function(data=data, m=m, maxit=maxit, method=method, post=post, seed=s seed <- getOption("datashield.seed") } - data <- .loadServersideObject(data) - .checkClass(obj = data, obj_name = "data", permitted_classes = c("data.frame", "matrix")) + data.name <- data + data <- .loadServersideObject(data.name) + .checkClass(obj = data, obj_name = data.name, permitted_classes = c("data.frame", "matrix")) if(!is.null(method)){ method <- unlist(stringr::str_split(method, pattern=",")) diff --git a/R/seqDS.R b/R/seqDS.R index 56113e4a..d6ff81bc 100644 --- a/R/seqDS.R +++ b/R/seqDS.R @@ -66,8 +66,8 @@ nfilter.subset<-as.numeric(thr$nfilter.subset) # ######################################################################### - FROM.eval <- tryCatch(.loadServersideObject(FROM.value.char), error = function(e) as.numeric(FROM.value.char)) - if(is.character(FROM.value.char)&&is.numeric(FROM.eval)){ + FROM.eval <- suppressWarnings(as.numeric(FROM.value.char)) + if(is.character(FROM.value.char)&&!anyNA(FROM.eval)){ FROM<-FROM.eval }else{ studysideMessage<-"ERROR: FROM.value.char must be specified as a real number in inverted commas eg '-3.74' or '0'" @@ -76,8 +76,8 @@ nfilter.subset<-as.numeric(thr$nfilter.subset) # if(!is.null(TO.value.char)) { - TO.eval <- tryCatch(.loadServersideObject(TO.value.char), error = function(e) as.numeric(TO.value.char)) - if(is.character(TO.value.char)&&is.numeric(TO.eval)) + TO.eval <- suppressWarnings(as.numeric(TO.value.char)) + if(is.character(TO.value.char)&&!anyNA(TO.eval)) { TO<-TO.eval }else{ @@ -91,8 +91,8 @@ nfilter.subset<-as.numeric(thr$nfilter.subset) # TO<-NULL } - BY.eval <- tryCatch(.loadServersideObject(BY.value.char), error = function(e) as.numeric(BY.value.char)) - if(is.character(BY.value.char)&&is.numeric(BY.eval)){ + BY.eval <- suppressWarnings(as.numeric(BY.value.char)) + if(is.character(BY.value.char)&&!anyNA(BY.eval)){ BY<-BY.eval }else{ studysideMessage<-"ERROR: BY.value.char must be specified as a real number in inverted commas eg '-3.74' or '0'" @@ -100,8 +100,8 @@ nfilter.subset<-as.numeric(thr$nfilter.subset) # } if(!is.null(LENGTH.OUT.value.char)){ - LENGTH.OUT.eval <- tryCatch(.loadServersideObject(LENGTH.OUT.value.char), error = function(e) as.numeric(LENGTH.OUT.value.char)) - if(is.character(LENGTH.OUT.value.char)&&is.numeric(LENGTH.OUT.eval)){ + LENGTH.OUT.eval <- suppressWarnings(as.numeric(LENGTH.OUT.value.char)) + if(is.character(LENGTH.OUT.value.char)&&!anyNA(LENGTH.OUT.eval)){ LENGTH.OUT<-LENGTH.OUT.eval }else{ studysideMessage<-"ERROR: If LENGTH.OUT.value.char is non-NULL, it must specify a positive integer in inverted commas eg '14'" diff --git a/R/utils.R b/R/utils.R index b96d8735..30e2fa30 100644 --- a/R/utils.R +++ b/R/utils.R @@ -7,6 +7,7 @@ #' #' @param x A character string naming the object, optionally with "$column" syntax. #' @return The retrieved R object, or the specified column if `$` syntax is used. +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @noRd .loadServersideObject <- function(x) { if (!is.character(x) || length(x) != 1) { @@ -27,9 +28,13 @@ obj <- tryCatch( get(obj_name, envir = env), - error = function(e) stop("The server-side object '", x, "' does not exist") + error = function(e) stop("The server-side object '", x, "' does not exist", call. = FALSE) ) + if (is.null(obj)) { + stop("The server-side object '", x, "' is NULL", call. = FALSE) + } + if (hasColumn) { obj <- obj[[col_name]] if (is.null(obj)) { diff --git a/R/varDS.R b/R/varDS.R index eb9fcf0e..eef07147 100644 --- a/R/varDS.R +++ b/R/varDS.R @@ -24,7 +24,7 @@ varDS <- function(x){ ############################################################# xvect <- .loadServersideObject(x) - .checkClass(obj = xvect, obj_name = x, permitted_classes = c("numeric", "integer")) + .checkClass(obj = xvect, obj_name = x, permitted_classes = c("numeric", "integer", "logical")) out.sum <- sum(xvect, na.rm=TRUE) out.sumSquares <- sum(xvect^2, na.rm=TRUE) diff --git a/man/asListDS.Rd b/man/asListDS.Rd index a2fc5a1c..407c75df 100644 --- a/man/asListDS.Rd +++ b/man/asListDS.Rd @@ -2,37 +2,26 @@ % Please edit documentation in R/asListDS.R \name{asListDS} \alias{asListDS} -\title{asListDS a serverside aggregate function called by ds.asList} +\title{asListDS a serverside assign function called by ds.asList} \usage{ -asListDS(x.name, newobj) +asListDS(x.name) } \arguments{ \item{x.name}{the name of the input object to be coerced to class data.matrix. Must be specified in inverted commas. But this argument is usually specified directly by argument of the clientside function \code{ds.asList}} - -\item{newobj}{is the object hard assigned '<<-' to be the output of the -function written to the serverside} } \value{ -the object specified by the argument (or its default name -.mat) which is written to the serverside. -In addition, two validity messages are returned. The first confirms an output -object has been created, the second states its class. The way that \code{as.list} -coerces objects to list depends on the class of the object, but in general -the class of the output object should usually be 'list' +the input object coerced to a list, which \code{ds.asList} writes to the +serverside. The way that \code{as.list} coerces objects to list depends on the class +of the object } \description{ Coerces an R object into a list } \details{ -Unlike most other class coercing functions this is -an aggregate function rather than an assign function. This -is because the \code{datashield.assign} function in the data repository deals specially with -a created object (newobj) if it is of class list. Reconfiguring the -function as an aggregate function works around this problem. -This aggregate function is based on the native R function \code{as.list} +This assign function is based on the native R function \code{as.list} and so additional information can be found in the help for \code{as.list} } \author{ diff --git a/man/dataFrameSortDS.Rd b/man/dataFrameSortDS.Rd index 9aa9ea5f..a3dfd8dd 100644 --- a/man/dataFrameSortDS.Rd +++ b/man/dataFrameSortDS.Rd @@ -53,7 +53,7 @@ For more details see help for the clientside function: [ds.dataFrameShort] } \author{ Paul Burton, with critical error identification by +Leire Abarrategui-Martinez, for DataSHIELD Development Team, 2/4/2020 Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands -Leire Abarrategui-Martinez, for DataSHIELD Development Team, 2/4/2020 } diff --git a/man/levelsDS.Rd b/man/levelsDS.Rd index 4002c73c..778f8a59 100644 --- a/man/levelsDS.Rd +++ b/man/levelsDS.Rd @@ -7,7 +7,7 @@ levelsDS(x) } \arguments{ -\item{x}{a factor vector} +\item{x}{a character string, the name of a factor vector} } \value{ a list with one element: \code{Levels} (the factor levels present From be23fe74ed96aae15ce608a6d9d40dd4dd816c6b Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Tue, 22 Sep 2026 13:31:57 +0200 Subject: [PATCH 26/38] fix/add tests --- tests/testthat/test-arg-asLogicalDS.R | 2 +- tests/testthat/test-smk-BooleDS.R | 16 ++++++ tests/testthat/test-smk-asListDS.R | 58 +++++++++++++++++--- tests/testthat/test-smk-classDS.R | 6 +- tests/testthat/test-smk-corDS.R | 11 ++++ tests/testthat/test-smk-covDS.R | 11 ++++ tests/testthat/test-smk-dimDS.R | 12 ++-- tests/testthat/test-smk-glmDS1.R | 25 ++++++++- tests/testthat/test-smk-glmDS2.R | 25 ++++++++- tests/testthat/test-smk-glmSLMADS1.R | 2 +- tests/testthat/test-smk-glmSLMADS2.R | 2 +- tests/testthat/test-smk-glmerSLMADS.assign.R | 2 +- tests/testthat/test-smk-glmerSLMADS2.R | 2 +- tests/testthat/test-smk-isValidDS.R | 2 +- tests/testthat/test-smk-lengthDS.R | 9 +++ tests/testthat/test-smk-levelsDS.R | 7 +++ tests/testthat/test-smk-lmerSLMADS.assign.R | 2 +- tests/testthat/test-smk-lmerSLMADS2.R | 2 +- tests/testthat/test-smk-meanDS.R | 26 ++++++++- tests/testthat/test-smk-meanSdGpDS.R | 12 ++++ tests/testthat/test-smk-seqDS.R | 7 +++ tests/testthat/test-smk-utils.R | 8 +++ tests/testthat/test-smk-varDS.R | 17 +++++- 23 files changed, 234 insertions(+), 32 deletions(-) diff --git a/tests/testthat/test-arg-asLogicalDS.R b/tests/testthat/test-arg-asLogicalDS.R index d778e010..9d16e8a5 100644 --- a/tests/testthat/test-arg-asLogicalDS.R +++ b/tests/testthat/test-arg-asLogicalDS.R @@ -28,7 +28,7 @@ test_that("simple asLogicalDS non-input", { test_that("simple asLogicalDS NULL", { input <- NULL - expect_error(asLogicalDS("input"), "The server-side object must be of type numeric, integer, character or matrix. 'input' is type NULL.", fixed = TRUE) + expect_error(asLogicalDS("input"), "The server-side object 'input' is NULL", fixed = TRUE) }) # context("asLogicalDS::arg::input NA") diff --git a/tests/testthat/test-smk-BooleDS.R b/tests/testthat/test-smk-BooleDS.R index 685dc0fa..e517e6f1 100644 --- a/tests/testthat/test-smk-BooleDS.R +++ b/tests/testthat/test-smk-BooleDS.R @@ -299,6 +299,22 @@ test_that("BooleDS errors when V2 object does not exist", { ) }) +test_that("BooleDS accepts a literal TRUE for V2", { + input <- data.frame(flag = c(TRUE, FALSE, TRUE, FALSE)) + + res <- BooleDS("input$flag", "TRUE", 1, "NA", TRUE) + + expect_equal(res, c(1, 0, 1, 0)) +}) + +test_that("BooleDS accepts a literal FALSE for V2", { + input <- data.frame(flag = c(TRUE, FALSE, TRUE, FALSE)) + + res <- BooleDS("input$flag", "FALSE", 1, "NA", TRUE) + + expect_equal(res, c(0, 1, 0, 1)) +}) + # # Done # diff --git a/tests/testthat/test-smk-asListDS.R b/tests/testthat/test-smk-asListDS.R index 1ac8ac68..534017c6 100644 --- a/tests/testthat/test-smk-asListDS.R +++ b/tests/testthat/test-smk-asListDS.R @@ -19,19 +19,59 @@ # Tests # -# context("asListDS::smk::simple") -test_that("simple asListDS", { - input <- list(v1 = c(1, 2, 3), v2 = c(4, 5, 6)) - newobj.name <- 'newobj' +# context("asListDS::smk::list") +test_that("asListDS returns a list unchanged", { + input <- list(v1 = c(1, 2, 3), v2 = c(4, 5, 6)) - expect_false(exists("newobj")) + res <- asListDS("input") - res <- asListDS("input", newobj.name) + expect_equal(class(res), "list") + expect_identical(res, input) +}) + +# context("asListDS::smk::numeric") +test_that("asListDS converts a numeric vector to a list of its elements", { + input <- c(1.5, 2.5, 3.5) + + res <- asListDS("input") - expect_true(exists("newobj")) - expect_equal(class(newobj), "list") - expect_length(newobj, 2) + expect_equal(class(res), "list") + expect_length(res, 3) + expect_equal(unlist(res), input) }) + +# context("asListDS::smk::data.frame") +test_that("asListDS converts a data.frame to a named list of its columns", { + input <- data.frame(a = c(1, 2, 3), b = c("x", "y", "z")) + + res <- asListDS("input") + + expect_equal(class(res), "list") + expect_named(res, c("a", "b")) + expect_equal(res$a, input$a) + expect_equal(res$b, input$b) +}) + +# context("asListDS::smk::column") +test_that("asListDS converts a data.frame column given with $", { + input <- data.frame(a = c(1, 2, 3)) + + res <- asListDS("input$a") + + expect_equal(class(res), "list") + expect_equal(unlist(res), c(1, 2, 3)) +}) + +test_that("asListDS throws error when object does not exist", { + expect_error(asListDS("nonexistent_object"), regexp = "does not exist") +}) + +test_that("asListDS throws error when object is NULL", { + input <- NULL + + expect_error(asListDS("input"), "The server-side object 'input' is NULL", fixed = TRUE) +}) + # # Done # diff --git a/tests/testthat/test-smk-classDS.R b/tests/testthat/test-smk-classDS.R index a3eb79d3..9d6104d8 100644 --- a/tests/testthat/test-smk-classDS.R +++ b/tests/testthat/test-smk-classDS.R @@ -223,11 +223,7 @@ test_that("special classDS, NA", { test_that("special classDS, NULL", { input <- NULL - res <- classDS("input") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "NULL") + expect_error(classDS("input"), "The server-side object 'input' is NULL", fixed = TRUE) }) test_that("classDS throws error when object does not exist", { diff --git a/tests/testthat/test-smk-corDS.R b/tests/testthat/test-smk-corDS.R index e86b6e2c..1c4af5e5 100644 --- a/tests/testthat/test-smk-corDS.R +++ b/tests/testthat/test-smk-corDS.R @@ -728,6 +728,17 @@ test_that("corDS throws error when object is of invalid type", { expect_error(corDS("bad_input", "y"), regexp = "must be of type") }) +test_that("corDS ignores y when x is a data.frame", { + input <- data.frame(v1 = c(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0), + v2 = c(2.0, 1.0, 4.0, 3.0, 6.0, 5.0, 8.0, 7.0, 10.0, 9.0)) + other <- c(10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0) + + res.x <- corDS("input", NULL) + res.xy <- corDS("input", "other") + + expect_equal(res.xy, res.x) +}) + # # Done # diff --git a/tests/testthat/test-smk-covDS.R b/tests/testthat/test-smk-covDS.R index 24352ac7..d899c7c2 100644 --- a/tests/testthat/test-smk-covDS.R +++ b/tests/testthat/test-smk-covDS.R @@ -242,6 +242,17 @@ test_that("covDS throws error when object is of invalid type", { expect_error(covDS("bad_input", "y", "pairwise.complete"), regexp = "must be of type") }) +test_that("covDS ignores y when x is a data.frame", { + input <- data.frame(v1 = c(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0), + v2 = c(2.0, 1.0, 4.0, 3.0, 6.0, 5.0, 8.0, 7.0, 10.0, 9.0)) + other <- c(10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0) + + res.x <- covDS("input", NULL, "pairwise.complete") + res.xy <- covDS("input", "other", "pairwise.complete") + + expect_equal(res.xy, res.x) +}) + # # Done # diff --git a/tests/testthat/test-smk-dimDS.R b/tests/testthat/test-smk-dimDS.R index c45d07fb..e53908de 100644 --- a/tests/testthat/test-smk-dimDS.R +++ b/tests/testthat/test-smk-dimDS.R @@ -60,12 +60,12 @@ test_that("dimDS throws error when object does not exist", { ) }) -test_that("dimDS throws error when object is not data.frame or matrix", { - bad_input <- c(1, 2, 3) - expect_error( - dimDS("bad_input"), - regexp = "must be of type data.frame or matrix" - ) +test_that("dimDS accepts any class, e.g. a 3-D array or a table", { + arr <- array(1:24, dim = c(2, 3, 4)) + tab <- table(c("a", "b", "a")) + + expect_equal(dimDS("arr")$dim, c(2L, 3L, 4L)) + expect_equal(dimDS("tab")$dim, 2L) }) # diff --git a/tests/testthat/test-smk-glmDS1.R b/tests/testthat/test-smk-glmDS1.R index 69aa22fe..5ccb00a0 100644 --- a/tests/testthat/test-smk-glmDS1.R +++ b/tests/testthat/test-smk-glmDS1.R @@ -45,7 +45,7 @@ test_that("glmDS1 throws error when data does not exist", { ) }) -test_that("glmDS1 throws error when data is not a data.frame or matrix", { +test_that("glmDS1 throws error when data is not a data.frame or list", { bad_input <- c(1, 2, 3) expect_error( glmDS1(formula = stats::as.formula("y ~ x"), family = "gaussian", @@ -54,6 +54,29 @@ test_that("glmDS1 throws error when data is not a data.frame or matrix", { ) }) +test_that("glmDS1 gives the same result for data as a list as for a data.frame", { + D <- data.frame( + y = c(4.1, 4.2, 3.9, 2.9, 3.6, 3.8, 4.2, 4.2, 2.5, 3.5, + 2.8, 3.7, 3.3, 3.3, 2.4, 3.5, 3.0, 3.1, 3.5, 3.4), + x = c(41.0, 41.0, 39.0, 38.9, 40.6, 41.0, 40.7, 41.4, 36.0, 39.0, + 37.6, 40.0, 40.3, 40.7, 37.0, 40.0, 41.6, 36.3, 39.3, 40.0) + ) + D.list <- as.list(D) + + res.df <- suppressWarnings(glmDS1(formula = stats::as.formula("y ~ x"), family = "gaussian", weights = NULL, offset = NULL, data = "D")) + res.list <- suppressWarnings(glmDS1(formula = stats::as.formula("y ~ x"), family = "gaussian", weights = NULL, offset = NULL, data = "D.list")) + + expect_equal(res.list, res.df) +}) + +test_that("glmDS1 throws error when data is a matrix", { + D.matrix <- cbind(y = c(1, 2, 3), x = c(4, 5, 6)) + expect_error( + glmDS1(formula = stats::as.formula("y ~ x"), family = "gaussian", weights = NULL, offset = NULL, data = "D.matrix"), + regexp = "must be of type data.frame or list" + ) +}) + # # Done # diff --git a/tests/testthat/test-smk-glmDS2.R b/tests/testthat/test-smk-glmDS2.R index ddf4f284..01d52c09 100644 --- a/tests/testthat/test-smk-glmDS2.R +++ b/tests/testthat/test-smk-glmDS2.R @@ -50,7 +50,7 @@ test_that("glmDS2 throws error when dataName does not exist", { ) }) -test_that("glmDS2 throws error when dataName is not a data.frame or matrix", { +test_that("glmDS2 throws error when dataName is not a data.frame or list", { bad_input <- c(1, 2, 3) expect_error( glmDS2(formula = stats::as.formula("y ~ x"), family = "gaussian", @@ -59,6 +59,29 @@ test_that("glmDS2 throws error when dataName is not a data.frame or matrix", { ) }) +test_that("glmDS2 gives the same result for data as a list as for a data.frame", { + D <- data.frame( + y = c(4.1, 4.2, 3.9, 2.9, 3.6, 3.8, 4.2, 4.2, 2.5, 3.5, + 2.8, 3.7, 3.3, 3.3, 2.4, 3.5, 3.0, 3.1, 3.5, 3.4), + x = c(41.0, 41.0, 39.0, 38.9, 40.6, 41.0, 40.7, 41.4, 36.0, 39.0, + 37.6, 40.0, 40.3, 40.7, 37.0, 40.0, 41.6, 36.3, 39.3, 40.0) + ) + D.list <- as.list(D) + + res.df <- suppressWarnings(glmDS2(formula = stats::as.formula("y ~ x"), family = "gaussian", beta.vect = "0,0", offset = NULL, weights = NULL, dataName = "D")) + res.list <- suppressWarnings(glmDS2(formula = stats::as.formula("y ~ x"), family = "gaussian", beta.vect = "0,0", offset = NULL, weights = NULL, dataName = "D.list")) + + expect_equal(res.list, res.df) +}) + +test_that("glmDS2 throws error when data is a matrix", { + D.matrix <- cbind(y = c(1, 2, 3), x = c(4, 5, 6)) + expect_error( + glmDS2(formula = stats::as.formula("y ~ x"), family = "gaussian", beta.vect = "0,0", offset = NULL, weights = NULL, dataName = "D.matrix"), + regexp = "must be of type data.frame or list" + ) +}) + # # Done # diff --git a/tests/testthat/test-smk-glmSLMADS1.R b/tests/testthat/test-smk-glmSLMADS1.R index 7496a5f8..e5f941e0 100644 --- a/tests/testthat/test-smk-glmSLMADS1.R +++ b/tests/testthat/test-smk-glmSLMADS1.R @@ -45,7 +45,7 @@ test_that("glmSLMADS1 throws error when data does not exist", { ) }) -test_that("glmSLMADS1 throws error when data is not a data.frame or matrix", { +test_that("glmSLMADS1 throws error when data is not a data.frame or list", { bad_input <- c(1, 2, 3) expect_error( glmSLMADS1(formula = stats::as.formula("y ~ x"), family = "gaussian", diff --git a/tests/testthat/test-smk-glmSLMADS2.R b/tests/testthat/test-smk-glmSLMADS2.R index 74c26fea..15b2a144 100644 --- a/tests/testthat/test-smk-glmSLMADS2.R +++ b/tests/testthat/test-smk-glmSLMADS2.R @@ -49,7 +49,7 @@ test_that("glmSLMADS2 throws error when dataName does not exist", { ) }) -test_that("glmSLMADS2 throws error when dataName is not a data.frame or matrix", { +test_that("glmSLMADS2 throws error when dataName is not a data.frame or list", { bad_input <- c(1, 2, 3) expect_error( diff --git a/tests/testthat/test-smk-glmerSLMADS.assign.R b/tests/testthat/test-smk-glmerSLMADS.assign.R index abe56803..3c7ce4e4 100644 --- a/tests/testthat/test-smk-glmerSLMADS.assign.R +++ b/tests/testthat/test-smk-glmerSLMADS.assign.R @@ -45,7 +45,7 @@ test_that("glmerSLMADS.assign throws error when dataName does not exist", { ) }) -test_that("glmerSLMADS.assign throws error when dataName is not a data.frame or matrix", { +test_that("glmerSLMADS.assign throws error when dataName is not a data.frame or list", { bad_input <- c(1, 2, 3) expect_error( glmerSLMADS.assign(formula = stats::as.formula("y ~ x + (1|group)"), diff --git a/tests/testthat/test-smk-glmerSLMADS2.R b/tests/testthat/test-smk-glmerSLMADS2.R index 81b26fcb..a40dd97a 100644 --- a/tests/testthat/test-smk-glmerSLMADS2.R +++ b/tests/testthat/test-smk-glmerSLMADS2.R @@ -49,7 +49,7 @@ test_that("glmerSLMADS2 throws error when dataName does not exist", { ) }) -test_that("glmerSLMADS2 throws error when dataName is not a data.frame or matrix", { +test_that("glmerSLMADS2 throws error when dataName is not a data.frame or list", { bad_input <- c(1, 2, 3) expect_error( glmerSLMADS2(formula = stats::as.formula("y ~ x + (1|group)"), diff --git a/tests/testthat/test-smk-isValidDS.R b/tests/testthat/test-smk-isValidDS.R index 83937374..bedab4c7 100644 --- a/tests/testthat/test-smk-isValidDS.R +++ b/tests/testthat/test-smk-isValidDS.R @@ -215,5 +215,5 @@ test_that("special isValidDS, NA", { test_that("special isValidDS, NULL", { input <- NULL - expect_error(isValidDS("input"), regexp = "must be of type") + expect_error(isValidDS("input"), "The server-side object 'input' is NULL", fixed = TRUE) }) diff --git a/tests/testthat/test-smk-lengthDS.R b/tests/testthat/test-smk-lengthDS.R index d91fafd9..f3216719 100644 --- a/tests/testthat/test-smk-lengthDS.R +++ b/tests/testthat/test-smk-lengthDS.R @@ -96,6 +96,15 @@ test_that("simple lengthDS, array", { expect_equal(res$class, "array") }) +test_that("lengthDS accepts any class, e.g. a Date vector", { + input <- as.Date(c("2020-01-01", "2020-06-01")) + + res <- lengthDS("input") + + expect_equal(res$length, 2) + expect_equal(res$class, "Date") +}) + # # Done # diff --git a/tests/testthat/test-smk-levelsDS.R b/tests/testthat/test-smk-levelsDS.R index 43fd7658..0a498229 100644 --- a/tests/testthat/test-smk-levelsDS.R +++ b/tests/testthat/test-smk-levelsDS.R @@ -61,6 +61,13 @@ test_that("levelsDS blocks when levels density exceeds threshold", { ) }) +test_that("levelsDS is blocked in non-permissive mode before any object lookup", { + options(datashield.privacyControlLevel = "non-permissive") + on.exit(options(datashield.privacyControlLevel = NULL), add = TRUE) + + expect_error(levelsDS("nonexistent_object"), regexp = "non-permissive") +}) + # # Done # diff --git a/tests/testthat/test-smk-lmerSLMADS.assign.R b/tests/testthat/test-smk-lmerSLMADS.assign.R index 6ef1a9c1..a5f8237a 100644 --- a/tests/testthat/test-smk-lmerSLMADS.assign.R +++ b/tests/testthat/test-smk-lmerSLMADS.assign.R @@ -71,7 +71,7 @@ test_that("lmerSLMADS.assign throws error when dataName does not exist", { ) }) -test_that("lmerSLMADS.assign throws error when dataName is not a data.frame or matrix", { +test_that("lmerSLMADS.assign throws error when dataName is not a data.frame or list", { bad_input <- c(1, 2, 3) expect_error( lmerSLMADS.assign(formula = stats::as.formula("y ~ x + (1|group)"), diff --git a/tests/testthat/test-smk-lmerSLMADS2.R b/tests/testthat/test-smk-lmerSLMADS2.R index 4e09bbe3..93d93000 100644 --- a/tests/testthat/test-smk-lmerSLMADS2.R +++ b/tests/testthat/test-smk-lmerSLMADS2.R @@ -48,7 +48,7 @@ test_that("lmerSLMADS2 throws error when dataName does not exist", { ) }) -test_that("lmerSLMADS2 throws error when dataName is not a data.frame or matrix", { +test_that("lmerSLMADS2 throws error when dataName is not a data.frame or list", { bad_input <- c(1, 2, 3) expect_error( lmerSLMADS2(formula = stats::as.formula("y ~ x + (1|group)"), diff --git a/tests/testthat/test-smk-meanDS.R b/tests/testthat/test-smk-meanDS.R index 8bb47c69..d15aa516 100644 --- a/tests/testthat/test-smk-meanDS.R +++ b/tests/testthat/test-smk-meanDS.R @@ -78,13 +78,37 @@ test_that("numeric meanDS, with all NA", { expect_equal(res$class, "numeric") }) +# context("meanDS::smk::logical with all NA") +test_that("logical meanDS, with all NA", { + input <- c(NA, NA, NA, NA, NA) + + res <- meanDS("input") + + expect_equal(res$EstimatedMean, NaN) + expect_equal(res$Nmissing, 5) + expect_equal(res$Nvalid, 0) + expect_equal(res$Ntotal, 5) + expect_equal(res$class, "logical") +}) + +# context("meanDS::smk::logical") +test_that("logical meanDS is the proportion TRUE", { + input <- c(TRUE, FALSE, TRUE, TRUE, NA) + + res <- meanDS("input") + + expect_equal(res$EstimatedMean, 0.75) + expect_equal(res$Nvalid, 4) + expect_equal(res$class, "logical") +}) + test_that("meanDS throws error when object does not exist", { expect_error(meanDS("nonexistent_object"), regexp = "does not exist") }) test_that("meanDS throws error when object is not numeric or integer", { bad_input <- c("a", "b", "c") - expect_error(meanDS("bad_input"), regexp = "must be of type numeric or integer") + expect_error(meanDS("bad_input"), regexp = "must be of type numeric, integer or logical") }) # diff --git a/tests/testthat/test-smk-meanSdGpDS.R b/tests/testthat/test-smk-meanSdGpDS.R index de3d4ecb..ed8ef814 100644 --- a/tests/testthat/test-smk-meanSdGpDS.R +++ b/tests/testthat/test-smk-meanSdGpDS.R @@ -37,6 +37,18 @@ test_that("simple meanSdGpDS, numeric by factor", { expect_equal(as.numeric(res$Mean_gp)[2], 8.0) }) +# context("meanSdGpDS::smk::numeric by double 0/1") +test_that("simple meanSdGpDS, numeric by a double 0/1 grouping variable", { + x_var <- c(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0) + index_var <- c(0, 0, 0, 0, 0, 1, 1, 1, 1, 1) + + res <- meanSdGpDS("x_var", "index_var") + + expect_equal(res$class.index, "numeric") + expect_equal(as.numeric(res$Mean_gp)[1], 3.0) + expect_equal(as.numeric(res$Mean_gp)[2], 8.0) +}) + test_that("meanSdGpDS throws error when X does not exist", { index_var <- as.factor(c("A", "A", "B", "B")) expect_error(meanSdGpDS("nonexistent_x", "index_var"), regexp = "does not exist") diff --git a/tests/testthat/test-smk-seqDS.R b/tests/testthat/test-smk-seqDS.R index 3a9edfb6..c5ed9370 100644 --- a/tests/testthat/test-smk-seqDS.R +++ b/tests/testthat/test-smk-seqDS.R @@ -135,6 +135,13 @@ test_that("seqDS errors when ALONG.WITH object does not exist", { ) }) +test_that("seqDS rejects a FROM value that is not a number", { + expect_error( + seqDS("not_a_number", "12", "2", NULL, NULL), + regexp = "FROM.value.char must be specified as a real number" + ) +}) + # # Done # diff --git a/tests/testthat/test-smk-utils.R b/tests/testthat/test-smk-utils.R index 131454e1..e3b3452d 100644 --- a/tests/testthat/test-smk-utils.R +++ b/tests/testthat/test-smk-utils.R @@ -48,6 +48,14 @@ test_that(".loadServersideObject() throws error for missing object", { ) }) +test_that(".loadServersideObject() throws error for a NULL object", { + null_obj <- NULL + expect_error( + .dsFunctionWrapper("null_obj"), + regexp = "The server-side object 'null_obj' is NULL" + ) +}) + test_that(".checkClass() passes for correct class", { df <- data.frame(a = 1) expect_invisible( diff --git a/tests/testthat/test-smk-varDS.R b/tests/testthat/test-smk-varDS.R index 51eac8e2..f3da7671 100644 --- a/tests/testthat/test-smk-varDS.R +++ b/tests/testthat/test-smk-varDS.R @@ -84,13 +84,28 @@ test_that("numeric varDS, with all NA", { expect_equal(res$class, "numeric") }) +# context("varDS::smk::logical with all NA") +test_that("logical varDS, with all NA", { + input <- c(NA, NA, NA, NA, NA) + + res <- varDS("input") + + expect_equal(class(res$Sum), "integer") + expect_equal(res$Sum, 0) + expect_equal(res$SumOfSquares, 0) + expect_equal(res$Nmissing, 5) + expect_equal(res$Nvalid, 0) + expect_equal(res$Ntotal, 5) + expect_equal(res$class, "logical") +}) + test_that("varDS throws error when object does not exist", { expect_error(varDS("nonexistent_object"), regexp = "does not exist") }) test_that("varDS throws error when object is not numeric or integer", { bad_input <- c("a", "b", "c") - expect_error(varDS("bad_input"), regexp = "must be of type numeric or integer") + expect_error(varDS("bad_input"), regexp = "must be of type numeric, integer or logical") }) # From 886f6b7b078bde2ed7fda3ec72e03c859e06e736 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Tue, 22 Sep 2026 12:33:51 +0200 Subject: [PATCH 27/38] refactor last functions --- R/aucDS.R | 9 +++------ R/bp_standardsDS.R | 17 +++++------------ R/igb_standardsDS.R | 13 +++++-------- R/mdPatternDS.R | 25 ++++++------------------- man/aucDS.Rd | 2 ++ man/bp_standardsDS.Rd | 2 ++ man/igb_standardsDS.Rd | 2 ++ man/mdPatternDS.Rd | 3 +++ 8 files changed, 28 insertions(+), 45 deletions(-) diff --git a/R/aucDS.R b/R/aucDS.R index 6afda830..7229212c 100644 --- a/R/aucDS.R +++ b/R/aucDS.R @@ -8,16 +8,13 @@ #' the complete cases that are used in the regression model. #' @return returns the AUC and its standard error #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @export #' aucDS <- function(pred=pred, y=y){ - if(is.character(pred)){ - pred <- eval(parse(text = pred), envir = parent.frame()) - } - if(is.character(y)){ - y <- eval(parse(text = y), envir = parent.frame()) - } + pred <- .loadServersideObject(pred) + y <- .loadServersideObject(y) y <- as.numeric(as.character(y)) diff --git a/R/bp_standardsDS.R b/R/bp_standardsDS.R index f90e683e..8d6baec7 100644 --- a/R/bp_standardsDS.R +++ b/R/bp_standardsDS.R @@ -20,23 +20,16 @@ #' @note The z-scores of height based on CDC growth charts are calculated #' by the sds function from the childsds R package. #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @import childsds #' @export #' bp_standardsDS <- function(sex=sex, age=age, height=height, bp=bp, systolic=systolic){ - if(is.character(sex)){ - sex <- eval(parse(text = sex), envir = parent.frame()) - } - if(is.character(age)){ - age <- eval(parse(text = age), envir = parent.frame()) - } - if(is.character(height)){ - height <- eval(parse(text = height), envir = parent.frame()) - } - if(is.character(bp)){ - bp <- eval(parse(text = bp), envir = parent.frame()) - } + sex <- .loadServersideObject(sex) + age <- .loadServersideObject(age) + height <- .loadServersideObject(height) + bp <- .loadServersideObject(bp) # convert height to a Z-score relative to age and sex based on CDC growth charts Zht <- sds(value=height, age=age, sex=sex, male="1", female="2", diff --git a/R/igb_standardsDS.R b/R/igb_standardsDS.R index e30247cb..13a19afc 100644 --- a/R/igb_standardsDS.R +++ b/R/igb_standardsDS.R @@ -17,6 +17,7 @@ #' standard is used. #' @return assigns the converted measurement as a new object on the server-side #' @author Demetris Avraam for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @import dplyr #' @importFrom gamlss.dist qST3 pST3 #' @export @@ -228,15 +229,11 @@ igb_standardsDS <- function(gagebrth=gagebrth, z=z, p=p, val=val, var=var, sex=s # Start the analysis - if(is.character(gagebrth)){ - gagebrth <- eval(parse(text = gagebrth), envir = parent.frame()) - } - if(is.character(val)){ - val <- eval(parse(text = val), envir = parent.frame()) - } - if(is.character(sex)){ - sex <- eval(parse(text = sex), envir = parent.frame()) + gagebrth <- .loadServersideObject(gagebrth) + if(!is.null(val)){ + val <- .loadServersideObject(val) } + sex <- .loadServersideObject(sex) x.out <- rep(NA, t=length(sex)) idx.males <- which(sex=="Male") diff --git a/R/mdPatternDS.R b/R/mdPatternDS.R index 0f817034..66dbaaba 100644 --- a/R/mdPatternDS.R +++ b/R/mdPatternDS.R @@ -36,7 +36,9 @@ #' \item{pattern}{The missing data pattern matrix with disclosure control applied} #' \item{valid}{Logical indicating if all patterns meet disclosure requirements} #' \item{message}{A message describing the validity status} +#' \item{class}{The class of the input object, for client-side consistency checking} #' @author Xavier Escribà montagut for DataSHIELD Development Team +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands #' @import mice #' @export #' @@ -48,24 +50,8 @@ mdPatternDS <- function(x){ nfilter.tab <- as.numeric(thr$nfilter.tab) ############################################################# - # Parse the input data name with error handling - x.val <- tryCatch( - { - eval(parse(text=x), envir = parent.frame()) - }, - error = function(e) { - stop(paste0("Object '", x, "' does not exist on the server"), call. = FALSE) - } - ) - - # Check object class - typ <- class(x.val) - - # Check that input is a data frame or matrix - if(!("data.frame" %in% typ || "matrix" %in% typ)){ - stop(paste0("The input object must be of type 'data.frame' or 'matrix'. Current type: ", - paste(typ, collapse = ", ")), call. = FALSE) - } + x.val <- .loadServersideObject(x) + .checkClass(obj = x.val, obj_name = x, permitted_classes = c("data.frame", "matrix")) # Use x.val for further processing x <- x.val @@ -113,7 +99,8 @@ mdPatternDS <- function(x){ message = ifelse(validity == "valid", "Valid: all pattern counts meet disclosure requirements", paste0("Invalid: some pattern counts below threshold (", - nfilter.tab, ") have been suppressed")) + nfilter.tab, ") have been suppressed")), + class = class(x.val) )) } diff --git a/man/aucDS.Rd b/man/aucDS.Rd index 567f2e38..b1d4cb30 100644 --- a/man/aucDS.Rd +++ b/man/aucDS.Rd @@ -24,4 +24,6 @@ The AUC determines the discriminative ability of a model. } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/bp_standardsDS.Rd b/man/bp_standardsDS.Rd index 1b26b9f5..cfafb344 100644 --- a/man/bp_standardsDS.Rd +++ b/man/bp_standardsDS.Rd @@ -45,4 +45,6 @@ by the sds function from the childsds R package. } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/igb_standardsDS.Rd b/man/igb_standardsDS.Rd index 99fd30e0..4eed445d 100644 --- a/man/igb_standardsDS.Rd +++ b/man/igb_standardsDS.Rd @@ -46,4 +46,6 @@ standard is used. } \author{ Demetris Avraam for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } diff --git a/man/mdPatternDS.Rd b/man/mdPatternDS.Rd index 1084565e..6295c024 100644 --- a/man/mdPatternDS.Rd +++ b/man/mdPatternDS.Rd @@ -15,6 +15,7 @@ A list containing: \item{pattern}{The missing data pattern matrix with disclosure control applied} \item{valid}{Logical indicating if all patterns meet disclosure requirements} \item{message}{A message describing the validity status} +\item{class}{The class of the input object, for client-side consistency checking} } \description{ This function is a serverside aggregate function that computes the @@ -51,4 +52,6 @@ suppressed in some studies. } \author{ Xavier Escribà montagut for DataSHIELD Development Team + +Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands } From e1ffe2849abe4452705f7f2b522f0f56f4f4e22c Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Tue, 22 Sep 2026 12:34:00 +0200 Subject: [PATCH 28/38] add tests for last functions --- tests/testthat/test-arg-mdPatternDS.R | 12 ++++++++++-- tests/testthat/test-disc-mdPatternDS.R | 2 +- tests/testthat/test-smk-aucDS.R | 14 +++++++++++++- tests/testthat/test-smk-bp_standardsDS.R | 12 ++++++++++-- tests/testthat/test-smk-igb_standardsDS.R | 12 ++++++++++++ tests/testthat/test-smk-mdPatternDS.R | 4 ++-- 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-arg-mdPatternDS.R b/tests/testthat/test-arg-mdPatternDS.R index 989deb76..e2ce112d 100644 --- a/tests/testthat/test-arg-mdPatternDS.R +++ b/tests/testthat/test-arg-mdPatternDS.R @@ -24,14 +24,22 @@ set.standard.disclosure.settings() test_that("mdPatternDS x NULL", { x <- NULL - expect_error(mdPatternDS(x), "The input object must be of type 'data.frame' or 'matrix'. Current type: NULL") + expect_error(mdPatternDS(x), "The input must be a single character string") }) # context("mdPatternDS::arg::x not valid variable") test_that("mdPatternDS x not variable", { x <- "not a variable" - expect_error(mdPatternDS(x), "Object 'not a variable' does not exist on the server") + expect_error(mdPatternDS(x), "does not exist") +}) + +# context("mdPatternDS::arg::x wrong type") +test_that("mdPatternDS x wrong type", { + x_val <- c(1.0, 2.0, 3.0) + x <- "x_val" + + expect_error(mdPatternDS(x), "must be of type data.frame or matrix") }) # diff --git a/tests/testthat/test-disc-mdPatternDS.R b/tests/testthat/test-disc-mdPatternDS.R index d10b004a..6f6a7c01 100644 --- a/tests/testthat/test-disc-mdPatternDS.R +++ b/tests/testthat/test-disc-mdPatternDS.R @@ -27,7 +27,7 @@ test_that("mdPatternDS: sample incomplete data.frame", { res <- mdPatternDS(x) - expect_length(res, 3) + expect_length(res, 4) expect_length(class(res), 1) expect_true(all(class(res) %in% c("list"))) expect_length(class(res$pattern), 2) diff --git a/tests/testthat/test-smk-aucDS.R b/tests/testthat/test-smk-aucDS.R index bcbbada1..c33d2eee 100644 --- a/tests/testthat/test-smk-aucDS.R +++ b/tests/testthat/test-smk-aucDS.R @@ -25,7 +25,7 @@ test_that("aucDS", { model <- glm(formula = D$DIS_DIAB~D$GENDER+D$PM_BMI_CONTINUOUS, family = 'binomial') pred <- predict(object = model, type = "link") - res <- aucDS(pred = pred, y = model$y) + res <- aucDS(pred = "pred", y = "model$y") expect_equal(class(res), "list") expect_length(res, 2) @@ -36,6 +36,18 @@ test_that("aucDS", { }) +test_that("aucDS throws error when pred does not exist", { + y <- c(0, 1, 0, 1) + + expect_error(aucDS(pred = "nonexistent_object", y = "y"), regexp = "does not exist") +}) + +test_that("aucDS throws error when y does not exist", { + pred <- c(0.1, 0.8, 0.3, 0.9) + + expect_error(aucDS(pred = "pred", y = "nonexistent_object"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-bp_standardsDS.R b/tests/testthat/test-smk-bp_standardsDS.R index fe8b9bc1..06fa5519 100644 --- a/tests/testthat/test-smk-bp_standardsDS.R +++ b/tests/testthat/test-smk-bp_standardsDS.R @@ -28,7 +28,7 @@ test_that("systolic bp_standardsDS", { bp <- c(118.54, 87.62, 72.13, 91.18, 88.47, 73.28, 100.27, 86.84, 103.51, 115.28) systolic <- TRUE - res <- bp_standardsDS(sex=sex, age=age, height=height, bp=bp, systolic=systolic) + res <- bp_standardsDS(sex="sex", age="age", height="height", bp="bp", systolic=systolic) expect_equal(class(res), "list") expect_length(res, 2) @@ -56,7 +56,7 @@ test_that("diastolic bp_standardsDS", { bp <- c(118.54, 87.62, 72.13, 91.18, 88.47, 73.28, 100.27, 86.84, 103.51, 115.28) systolic <- FALSE - res <- bp_standardsDS(sex=sex, age=age, height=height, bp=bp, systolic=systolic) + res <- bp_standardsDS(sex="sex", age="age", height="height", bp="bp", systolic=systolic) expect_equal(class(res), "list") expect_length(res, 2) @@ -76,6 +76,14 @@ test_that("diastolic bp_standardsDS", { }) +test_that("bp_standardsDS throws error when an input does not exist", { + sex <- c(2, 1) + age <- c(5.26, 7.73) + height <- c(113.57, 92.30) + + expect_error(bp_standardsDS(sex="sex", age="age", height="height", bp="nonexistent_object", systolic=TRUE), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-igb_standardsDS.R b/tests/testthat/test-smk-igb_standardsDS.R index bd3a8f79..f3f11a16 100644 --- a/tests/testthat/test-smk-igb_standardsDS.R +++ b/tests/testthat/test-smk-igb_standardsDS.R @@ -154,6 +154,18 @@ test_that("igb_standardsDS - igb_centile2value", { }) +test_that("igb_standardsDS throws error when gagebrth does not exist", { + data <- data.frame(sex = c("Male", "Female")) + + expect_error(igb_standardsDS(gagebrth="nonexistent_object", z=0, p=50, val=NULL, var="lencm", sex="data$sex", fun="igb_centile2value"), regexp = "does not exist") +}) + +test_that("igb_standardsDS throws error when val does not exist", { + data <- data.frame(gagebrth = c(250, 270), sex = c("Male", "Female")) + + expect_error(igb_standardsDS(gagebrth="data$gagebrth", z=0, p=50, val="nonexistent_object", var="lencm", sex="data$sex", fun="igb_value2zscore"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-mdPatternDS.R b/tests/testthat/test-smk-mdPatternDS.R index ba682b1e..3e11a024 100644 --- a/tests/testthat/test-smk-mdPatternDS.R +++ b/tests/testthat/test-smk-mdPatternDS.R @@ -27,7 +27,7 @@ test_that("mdPatternDS: sample 1 complete data.frame", { res <- mdPatternDS(x) - expect_length(res, 3) + expect_length(res, 4) expect_length(class(res), 1) expect_true(all(class(res) %in% c("list"))) expect_length(class(res$pattern), 2) @@ -64,7 +64,7 @@ test_that("mdPatternDS: sample 2 complete data.frame", { res <- mdPatternDS(x) - expect_length(res, 3) + expect_length(res, 4) expect_length(class(res), 1) expect_true(all(class(res) %in% c("list"))) expect_length(class(res$pattern), 2) From 4e98e2eb2d5178fc63fe4950196d01d2dc141704 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Fri, 25 Sep 2026 17:53:41 +0200 Subject: [PATCH 29/38] docs: updated server references to include Armadillo --- R/blackBoxDS.R | 2 +- R/blackBoxRanksDS.R | 2 +- R/meanSdGpDS.R | 2 +- R/ranksSecureDS4.R | 4 ++-- R/table1DDS.R | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/blackBoxDS.R b/R/blackBoxDS.R index 63cf0160..40c882a0 100644 --- a/R/blackBoxDS.R +++ b/R/blackBoxDS.R @@ -367,7 +367,7 @@ if(sum(round(rank(blackbox.output.df[,3])-rank(blackbox.output.df[,4]),2)==0)!=n paste0("FAILED: inconsistent values across different transformations in black box, try a different seed. Altenatively this could reflect modification of the clientside code which is not recommended. Finally, it can also occur - if the R session on one or more of the opal data servers runs out + if the R session on one or more of the Armadillo/Opal data servers runs out of memory") stop(error.message, call. = FALSE) }else{ diff --git a/R/blackBoxRanksDS.R b/R/blackBoxRanksDS.R index 522307a8..c2380242 100644 --- a/R/blackBoxRanksDS.R +++ b/R/blackBoxRanksDS.R @@ -257,7 +257,7 @@ if(sum(round(rank(blackbox.ranks.df[,5])-rank(blackbox.ranks.df[,8]),2)==0)!=num paste0("FAILED: inconsistent ranking across different transformations in black box, try a different seed. Altenatively this could reflect modification of the clientside code which is not recommended. Finally, it can also occur - if the R session on one or more of the opal data servers runs out + if the R session on one or more of the Armadillo/Opal data servers runs out of memory") stop(error.message, call. = FALSE) }else{ diff --git a/R/meanSdGpDS.R b/R/meanSdGpDS.R index eecf0dde..d84eca03 100644 --- a/R/meanSdGpDS.R +++ b/R/meanSdGpDS.R @@ -116,7 +116,7 @@ meanSdGpDS <- function (x, index){ ansmat.count<-table(group) # Set filter for cell sizes that are too small - # the minimum number of observations that are allowed (the below function gets the value from opal) + # the minimum number of observations that are allowed (the below function gets the value from the server) any.invalid.cell<-(sum(ansmat.count0)>=1) if(!any.invalid.cell) { diff --git a/R/ranksSecureDS4.R b/R/ranksSecureDS4.R index 97cd47ce..1bf3159d 100644 --- a/R/ranksSecureDS4.R +++ b/R/ranksSecureDS4.R @@ -71,7 +71,7 @@ if((length(sR8.df$global.ranks.input.from.sR5)!=lenx)|| error.message<- paste0("FAILED: ranking components of different lengths. This could reflect modification of the clientside code which is not recommended. It can - also occur if the R session on one or more of the opal data servers + also occur if the R session on one or more of the Armadillo/Opal data servers runs out of memory") stop(error.message, call. = FALSE) } @@ -96,7 +96,7 @@ if(ranks.consistent==0) paste0("FAILED: inconsistent ranking across different components of ranking matrix, try a different seed. Altenatively this could reflect modification of the clientside code which is not recommended. Finally, it can also occur - if the R session on one or more of the opal data servers runs out + if the R session on one or more of the Armadillo/Opal data servers runs out of memory") stop(error.message, call. = FALSE) } diff --git a/R/table1DDS.R b/R/table1DDS.R index 94bff957..de23a79c 100644 --- a/R/table1DDS.R +++ b/R/table1DDS.R @@ -15,7 +15,7 @@ #' table1DDS <- function(xvect){ - # the minimum number of observations that are allowed (the below function gets the value from opal) + # the minimum number of observations that are allowed (the below function gets the value from the server) ############################################################# # MODULE 1: CAPTURE THE nfilter SETTINGS From b253c54b070d699d044e2f90b8dd5659228ec3f9 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Tue, 13 Oct 2026 19:21:33 +0200 Subject: [PATCH 30/38] added tests coverage --- tests/testthat/test-smk-absDS.R | 10 +++++ tests/testthat/test-smk-asCharacterDS.R | 4 ++ tests/testthat/test-smk-asDataMatrixDS.R | 5 +++ tests/testthat/test-smk-asIntegerDS.R | 5 +++ tests/testthat/test-smk-asLogicalDS.R | 19 ++++++++ tests/testthat/test-smk-asMatrixDS.R | 5 +++ tests/testthat/test-smk-asNumericDS.R | 5 +++ .../test-smk-boxPlotGG_data_TreatmentDS.R | 8 ++++ ...t-smk-boxPlotGG_data_Treatment_numericDS.R | 9 ++++ tests/testthat/test-smk-cDS.R | 4 ++ tests/testthat/test-smk-corDS.R | 25 +++++++++++ tests/testthat/test-smk-corTestDS.R | 13 ++++++ tests/testthat/test-smk-covDS.R | 25 +++++++++++ tests/testthat/test-smk-densityGridDS.R | 17 +++++++ tests/testthat/test-smk-expDS.R | 10 +++++ tests/testthat/test-smk-gamlssDS.R | 45 +++++++++++++++++++ tests/testthat/test-smk-glmSLMADS1.R | 15 +++++++ tests/testthat/test-smk-glmSLMADS2.R | 19 ++++++++ tests/testthat/test-smk-glmerSLMADS.assign.R | 22 +++++++++ tests/testthat/test-smk-glmerSLMADS2.R | 22 +++++++++ tests/testthat/test-smk-histogramDS1.R | 11 +++++ tests/testthat/test-smk-histogramDS2.R | 8 ++++ tests/testthat/test-smk-isNaDS.R | 41 +++++++++++++++++ tests/testthat/test-smk-kurtosisDS1.R | 11 +++++ tests/testthat/test-smk-kurtosisDS2.R | 11 +++++ tests/testthat/test-smk-listDS.R | 4 ++ tests/testthat/test-smk-lmerSLMADS.assign.R | 19 ++++++++ tests/testthat/test-smk-lmerSLMADS2.R | 19 ++++++++ tests/testthat/test-smk-logDS.R | 10 +++++ tests/testthat/test-smk-matrixDetDS1.R | 10 +++++ tests/testthat/test-smk-matrixDetDS2.R | 10 +++++ tests/testthat/test-smk-matrixDimnamesDS.R | 10 +++++ tests/testthat/test-smk-matrixInvertDS.R | 10 +++++ tests/testthat/test-smk-matrixMultDS.R | 12 +++++ tests/testthat/test-smk-matrixTransposeDS.R | 10 +++++ tests/testthat/test-smk-mdPatternDS.R | 20 +++++++++ tests/testthat/test-smk-meanDS.R | 11 +++++ tests/testthat/test-smk-meanSdGpDS.R | 31 +++++++++++++ tests/testthat/test-smk-miceDS.R | 24 ++++++++++ tests/testthat/test-smk-quantileMeanDS.R | 11 +++++ tests/testthat/test-smk-rangeDS.R | 7 +++ tests/testthat/test-smk-recodeValuesDS.R | 7 +++ tests/testthat/test-smk-replaceNaDS.R | 4 ++ tests/testthat/test-smk-skewnessDS1.R | 11 +++++ tests/testthat/test-smk-skewnessDS2.R | 11 +++++ tests/testthat/test-smk-sqrtDS.R | 10 +++++ tests/testthat/test-smk-unListDS.R | 4 ++ tests/testthat/test-smk-uniqueDS.R | 4 ++ tests/testthat/test-smk-varDS.R | 11 +++++ 49 files changed, 649 insertions(+) diff --git a/tests/testthat/test-smk-absDS.R b/tests/testthat/test-smk-absDS.R index 6b2f9a76..361ae4be 100644 --- a/tests/testthat/test-smk-absDS.R +++ b/tests/testthat/test-smk-absDS.R @@ -157,6 +157,16 @@ test_that("simple absDS", { expect_equal(res[5], 50L) expect_equal(res[6], 20L) }) + +test_that("absDS throws error when object does not exist", { + expect_error(absDS("nonexistent_object"), regexp = "does not exist") +}) + +test_that("absDS throws error when object is the wrong type", { + bad_input <- c("a", "b", "c") + expect_error(absDS("bad_input"), regexp = "must be of type numeric or integer") +}) + # # Done # diff --git a/tests/testthat/test-smk-asCharacterDS.R b/tests/testthat/test-smk-asCharacterDS.R index 40cdaf73..e9541ee5 100644 --- a/tests/testthat/test-smk-asCharacterDS.R +++ b/tests/testthat/test-smk-asCharacterDS.R @@ -81,6 +81,10 @@ test_that("logical vector asCharacterDS", { expect_equal(res[5], "TRUE") }) +test_that("asCharacterDS throws error when object does not exist", { + expect_error(asCharacterDS("nonexistent_object"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-asDataMatrixDS.R b/tests/testthat/test-smk-asDataMatrixDS.R index 6529b1ab..fa279944 100644 --- a/tests/testthat/test-smk-asDataMatrixDS.R +++ b/tests/testthat/test-smk-asDataMatrixDS.R @@ -55,6 +55,11 @@ test_that("simple asDataMatrixDS", { expect_equal(res.colnames[1], "v1") expect_equal(res.colnames[2], "v2") }) + +test_that("asDataMatrixDS throws error when object does not exist", { + expect_error(asDataMatrixDS("nonexistent_object"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-asIntegerDS.R b/tests/testthat/test-smk-asIntegerDS.R index 1fc8445b..f23669fc 100644 --- a/tests/testthat/test-smk-asIntegerDS.R +++ b/tests/testthat/test-smk-asIntegerDS.R @@ -70,6 +70,11 @@ test_that("character vector asIntegerDS", { expect_equal(res[4], 404) expect_equal(res[5], 505) }) + +test_that("asIntegerDS throws error when object does not exist", { + expect_error(asIntegerDS("nonexistent_object"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-asLogicalDS.R b/tests/testthat/test-smk-asLogicalDS.R index 41ef866e..d4b4d222 100644 --- a/tests/testthat/test-smk-asLogicalDS.R +++ b/tests/testthat/test-smk-asLogicalDS.R @@ -166,6 +166,25 @@ test_that("simple asLogicalDS, character vector", { expect_equal(res[5], FALSE) expect_equal(res[6], FALSE) }) + +test_that("asLogicalDS throws error when object does not exist", { + expect_error(asLogicalDS("nonexistent_object"), regexp = "does not exist") +}) + +test_that("asLogicalDS throws error when object is the wrong type", { + bad_input <- list(1, 2, 3) + expect_error(asLogicalDS("bad_input"), regexp = "must be of type numeric, integer, character or matrix") +}) + +test_that("simple asLogicalDS matrix", { + input <- matrix(c(0, 1, 2, 0), nrow = 2) + + res <- asLogicalDS("input") + + expect_equal(class(res), "logical") + expect_equal(res, c(FALSE, TRUE, TRUE, FALSE)) +}) + # # Done # diff --git a/tests/testthat/test-smk-asMatrixDS.R b/tests/testthat/test-smk-asMatrixDS.R index ba759e27..28b5d77f 100644 --- a/tests/testthat/test-smk-asMatrixDS.R +++ b/tests/testthat/test-smk-asMatrixDS.R @@ -55,6 +55,11 @@ test_that("simple asMatrixDS", { expect_equal(res.colnames[1], "v1") expect_equal(res.colnames[2], "v2") }) + +test_that("asMatrixDS throws error when object does not exist", { + expect_error(asMatrixDS("nonexistent_object"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-asNumericDS.R b/tests/testthat/test-smk-asNumericDS.R index 4ace90f5..ad8632b2 100644 --- a/tests/testthat/test-smk-asNumericDS.R +++ b/tests/testthat/test-smk-asNumericDS.R @@ -226,6 +226,11 @@ test_that("integer vector asNumericDS", { expect_equal(res[4], 2) expect_equal(res[5], 1) }) + +test_that("asNumericDS throws error when object does not exist", { + expect_error(asNumericDS("nonexistent_object"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-boxPlotGG_data_TreatmentDS.R b/tests/testthat/test-smk-boxPlotGG_data_TreatmentDS.R index 0deb5ff5..2161294f 100644 --- a/tests/testthat/test-smk-boxPlotGG_data_TreatmentDS.R +++ b/tests/testthat/test-smk-boxPlotGG_data_TreatmentDS.R @@ -41,6 +41,14 @@ test_that("boxPlotGG_data_TreatmentDS fails when group is not a factor", { expect_error(boxPlotGG_data_TreatmentDS("D", variables = c("v1"), group = "group"), "must be of type factor") }) +test_that("boxPlotGG_data_TreatmentDS gives the same result for numeric columns as for integer", { + D.integer <- data.frame(v1 = c(1:20), v2 = c(20:1)) + D.numeric <- data.frame(v1 = as.numeric(1:20), v2 = as.numeric(20:1)) + + expect_equal(boxPlotGG_data_TreatmentDS("D.numeric", variables = c("v1", "v2")), + boxPlotGG_data_TreatmentDS("D.integer", variables = c("v1", "v2"))) +}) + # # Done # diff --git a/tests/testthat/test-smk-boxPlotGG_data_Treatment_numericDS.R b/tests/testthat/test-smk-boxPlotGG_data_Treatment_numericDS.R index 354de5cd..106821d0 100644 --- a/tests/testthat/test-smk-boxPlotGG_data_Treatment_numericDS.R +++ b/tests/testthat/test-smk-boxPlotGG_data_Treatment_numericDS.R @@ -29,6 +29,15 @@ test_that("boxPlotGG_data_Treatment_numericDS fails when vector is not numeric o expect_error(boxPlotGG_data_Treatment_numericDS("v1"), "must be of type numeric or integer") }) +test_that("boxPlotGG_data_Treatment_numericDS gives the same result for numeric input as for integer", { + v1 <- c(1:20) + res.integer <- boxPlotGG_data_Treatment_numericDS("v1") + v1 <- as.numeric(v1) + res.numeric <- boxPlotGG_data_Treatment_numericDS("v1") + + expect_equal(res.numeric, res.integer) +}) + # # Done # diff --git a/tests/testthat/test-smk-cDS.R b/tests/testthat/test-smk-cDS.R index 518d9ac5..017b5481 100644 --- a/tests/testthat/test-smk-cDS.R +++ b/tests/testthat/test-smk-cDS.R @@ -69,6 +69,10 @@ test_that("empty list cDS", { expect_equal(class(res), "NULL") }) +test_that("cDS throws error when object does not exist", { + expect_error(cDS("nonexistent_object"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-corDS.R b/tests/testthat/test-smk-corDS.R index 1c4af5e5..ba51e096 100644 --- a/tests/testthat/test-smk-corDS.R +++ b/tests/testthat/test-smk-corDS.R @@ -739,6 +739,31 @@ test_that("corDS ignores y when x is a data.frame", { expect_equal(res.xy, res.x) }) +test_that("corDS gives the same result for integer input as for numeric", { + x.numeric <- c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0) + y.numeric <- c(4.0, 3.0, 3.0, 1.0, 2.0, 0.0, 2.0, 1.0, 1.0) + x.integer <- as.integer(x.numeric) + y.integer <- as.integer(y.numeric) + + res.numeric <- corDS("x.numeric", "y.numeric") + res.integer <- corDS("x.integer", "y.integer") + + expect_equal(res.integer$class, "integer") + expect_equal(res.integer[names(res.integer) != "class"], res.numeric[names(res.numeric) != "class"]) +}) + +test_that("corDS gives the same result for a matrix as for a data.frame", { + input.df <- data.frame(v1 = c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0), + v2 = c(4.0, 3.0, 3.0, 1.0, 2.0, 0.0, 2.0, 1.0, 1.0)) + input.matrix <- as.matrix(input.df) + + res.df <- corDS("input.df") + res.matrix <- corDS("input.matrix") + + expect_true("matrix" %in% res.matrix$class) + expect_equal(res.matrix[names(res.matrix) != "class"], res.df[names(res.df) != "class"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-corTestDS.R b/tests/testthat/test-smk-corTestDS.R index cb54b62f..a007eee7 100644 --- a/tests/testthat/test-smk-corTestDS.R +++ b/tests/testthat/test-smk-corTestDS.R @@ -612,6 +612,19 @@ test_that("corTestDS throws error when object is not numeric or integer", { expect_error(corTestDS("bad_input", "y", "pearson", NULL, 0.95), regexp = "must be of type numeric or integer") }) +test_that("corTestDS gives the same result for integer input as for numeric", { + x.numeric <- c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0) + y.numeric <- c(4.0, 3.0, 3.0, 1.0, 2.0, 0.0, 2.0, 1.0, 1.0) + x.integer <- as.integer(x.numeric) + y.integer <- as.integer(y.numeric) + + res.numeric <- corTestDS("x.numeric", "y.numeric", "pearson", NULL, 0.95) + res.integer <- corTestDS("x.integer", "y.integer", "pearson", NULL, 0.95) + + expect_equal(res.integer$class, "integer") + expect_equal(res.integer[names(res.integer) != "class"], res.numeric[names(res.numeric) != "class"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-covDS.R b/tests/testthat/test-smk-covDS.R index d899c7c2..d44f98bb 100644 --- a/tests/testthat/test-smk-covDS.R +++ b/tests/testthat/test-smk-covDS.R @@ -253,6 +253,31 @@ test_that("covDS ignores y when x is a data.frame", { expect_equal(res.xy, res.x) }) +test_that("covDS gives the same result for integer input as for numeric", { + x.numeric <- c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0) + y.numeric <- c(4.0, 3.0, 3.0, 1.0, 2.0, 0.0, 2.0, 1.0, 1.0) + x.integer <- as.integer(x.numeric) + y.integer <- as.integer(y.numeric) + + res.numeric <- covDS("x.numeric", "y.numeric", "casewise.complete") + res.integer <- covDS("x.integer", "y.integer", "casewise.complete") + + expect_equal(res.integer$class, "integer") + expect_equal(res.integer[names(res.integer) != "class"], res.numeric[names(res.numeric) != "class"]) +}) + +test_that("covDS gives the same result for a matrix as for a data.frame", { + input.df <- data.frame(v1 = c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0), + v2 = c(4.0, 3.0, 3.0, 1.0, 2.0, 0.0, 2.0, 1.0, 1.0)) + input.matrix <- as.matrix(input.df) + + res.df <- covDS("input.df", NULL, "casewise.complete") + res.matrix <- covDS("input.matrix", NULL, "casewise.complete") + + expect_true("matrix" %in% res.matrix$class) + expect_equal(res.matrix[names(res.matrix) != "class"], res.df[names(res.df) != "class"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-densityGridDS.R b/tests/testthat/test-smk-densityGridDS.R index 05efb14f..1554b832 100644 --- a/tests/testthat/test-smk-densityGridDS.R +++ b/tests/testthat/test-smk-densityGridDS.R @@ -73,6 +73,23 @@ test_that("densityGridDS fails when y is not numeric or integer", { expect_error(densityGridDS(x="xvect", y="yvect", numints=3), "must be of type numeric or integer") }) +test_that("densityGridDS gives the same result for integer input as for numeric", { + x.numeric <- c(119, 101, 100, 95, 123, 97, 111, 123, 110, 99, + 100, 118, 93, 98, 103, 102, 81, 97, 91, 94) + y.numeric <- rev(x.numeric) + c(1:20) + x.integer <- as.integer(x.numeric) + y.integer <- as.integer(y.numeric) + + res.numeric <- densityGridDS(x="x.numeric", y="y.numeric", limits=FALSE, x.min=NULL, + x.max=NULL, y.min=NULL, y.max=NULL, numints=3) + res.integer <- densityGridDS(x="x.integer", y="y.integer", limits=FALSE, x.min=NULL, + x.max=NULL, y.min=NULL, y.max=NULL, numints=3) + + expect_equal(res.integer$class.x, "integer") + expect_equal(res.integer$class.y, "integer") + expect_equal(res.integer$grid, res.numeric$grid) +}) + # # Done # diff --git a/tests/testthat/test-smk-expDS.R b/tests/testthat/test-smk-expDS.R index 4c359470..a5bda785 100644 --- a/tests/testthat/test-smk-expDS.R +++ b/tests/testthat/test-smk-expDS.R @@ -37,6 +37,16 @@ test_that("expDS computes exponential for integer vector", { expect_equal(res, exp(input)) }) + +test_that("expDS throws error when object does not exist", { + expect_error(expDS("nonexistent_object"), regexp = "does not exist") +}) + +test_that("expDS throws error when object is the wrong type", { + bad_input <- c("a", "b", "c") + expect_error(expDS("bad_input"), regexp = "must be of type numeric or integer") +}) + # # Done # diff --git a/tests/testthat/test-smk-gamlssDS.R b/tests/testthat/test-smk-gamlssDS.R index de284148..ddb71fec 100644 --- a/tests/testthat/test-smk-gamlssDS.R +++ b/tests/testthat/test-smk-gamlssDS.R @@ -85,6 +85,51 @@ test_that("birthweight gamlssDS", { }) +test_that("gamlssDS throws error when object does not exist", { + expect_error(gamlssDS(formula="e3_bwtilde_symbole3_gac_None", sigma.formula="e3_bwtilde_symbole3_gac_None", + nu.formula="tilde_symbol1", tau.formula="tilde_symbol1", + family="NOleft_parenthesisright_parenthesis", data="nonexistent_object", method="RS", mu.fix=FALSE, + sigma.fix=FALSE, nu.fix=FALSE, tau.fix=FALSE, + control="0.001,20,1,1,1,1,Inf", i.control="0.001,50,30,0.001", centiles=TRUE, + xvar="D$e3_gac_None", newobj="z_scores_e3_bw"), regexp = "does not exist") +}) + +test_that("gamlssDS throws error when object is the wrong type", { + bad_input <- c("a", "b", "c") + expect_error(gamlssDS(formula="e3_bwtilde_symbole3_gac_None", sigma.formula="e3_bwtilde_symbole3_gac_None", + nu.formula="tilde_symbol1", tau.formula="tilde_symbol1", + family="NOleft_parenthesisright_parenthesis", data="bad_input", method="RS", mu.fix=FALSE, + sigma.fix=FALSE, nu.fix=FALSE, tau.fix=FALSE, + control="0.001,20,1,1,1,1,Inf", i.control="0.001,50,30,0.001", centiles=TRUE, + xvar="D$e3_gac_None", newobj="z_scores_e3_bw"), regexp = "must be of type data.frame or list") +}) + +test_that("gamlssDS gives the same result for data as a list as for a data.frame", { + D <- data.frame( + e3_bw = c(4100, 4158, 4110, 2900, 3580, 3780, 4220, 4210, 2460, 3510, + 2800, 3730, 3300, 3310, 2390, 3480, 3040, 3050, 3500, 3420), + e3_gac_None = c(41.00, 41.00, 39.00, 38.86, 40.57, 41.00, 40.71, 41.43, 36.00, 39.00, + 37.57, 40.00, 40.29, 40.71, 37.00, 40.00, 41.57, 36.29, 39.29, 40.00) + ) + D.list <- as.list(D) + + res.df <- gamlssDS(formula="e3_bwtilde_symbole3_gac_None", sigma.formula="e3_bwtilde_symbole3_gac_None", + nu.formula="tilde_symbol1", tau.formula="tilde_symbol1", + family="NOleft_parenthesisright_parenthesis", data="D", method="RS", mu.fix=FALSE, + sigma.fix=FALSE, nu.fix=FALSE, tau.fix=FALSE, + control="0.001,20,1,1,1,1,Inf", i.control="0.001,50,30,0.001", centiles=TRUE, + xvar="D$e3_gac_None", newobj="z_scores_e3_bw") + res.list <- gamlssDS(formula="e3_bwtilde_symbole3_gac_None", sigma.formula="e3_bwtilde_symbole3_gac_None", + nu.formula="tilde_symbol1", tau.formula="tilde_symbol1", + family="NOleft_parenthesisright_parenthesis", data="D.list", method="RS", mu.fix=FALSE, + sigma.fix=FALSE, nu.fix=FALSE, tau.fix=FALSE, + control="0.001,20,1,1,1,1,Inf", i.control="0.001,50,30,0.001", centiles=TRUE, + xvar="D.list$e3_gac_None", newobj="z_scores_e3_bw") + + expect_equal(stats::coef(res.list$results), stats::coef(res.df$results)) + expect_equal(res.list$centiles, res.df$centiles) +}) + # # Done # diff --git a/tests/testthat/test-smk-glmSLMADS1.R b/tests/testthat/test-smk-glmSLMADS1.R index e5f941e0..18641903 100644 --- a/tests/testthat/test-smk-glmSLMADS1.R +++ b/tests/testthat/test-smk-glmSLMADS1.R @@ -54,6 +54,21 @@ test_that("glmSLMADS1 throws error when data is not a data.frame or list", { ) }) +test_that("glmSLMADS1 gives the same result for data as a list as for a data.frame", { + D <- data.frame( + y = c(4.1, 4.2, 3.9, 2.9, 3.6, 3.8, 4.2, 4.2, 2.5, 3.5, + 2.8, 3.7, 3.3, 3.3, 2.4, 3.5, 3.0, 3.1, 3.5, 3.4), + x = c(41.0, 41.0, 39.0, 38.9, 40.6, 41.0, 40.7, 41.4, 36.0, 39.0, + 37.6, 40.0, 40.3, 40.7, 37.0, 40.0, 41.6, 36.3, 39.3, 40.0) + ) + D.list <- as.list(D) + + res.df <- suppressWarnings(glmSLMADS1(formula = stats::as.formula("y ~ x"), family = "gaussian", weights = NULL, offset = NULL, data = "D")) + res.list <- suppressWarnings(glmSLMADS1(formula = stats::as.formula("y ~ x"), family = "gaussian", weights = NULL, offset = NULL, data = "D.list")) + + expect_equal(res.list, res.df) +}) + # # Done # diff --git a/tests/testthat/test-smk-glmSLMADS2.R b/tests/testthat/test-smk-glmSLMADS2.R index 15b2a144..02965fdf 100644 --- a/tests/testthat/test-smk-glmSLMADS2.R +++ b/tests/testthat/test-smk-glmSLMADS2.R @@ -59,6 +59,25 @@ test_that("glmSLMADS2 throws error when dataName is not a data.frame or list", { ) }) +test_that("glmSLMADS2 gives the same result for data as a list as for a data.frame", { + D <- data.frame( + y = c(4.1, 4.2, 3.9, 2.9, 3.6, 3.8, 4.2, 4.2, 2.5, 3.5, + 2.8, 3.7, 3.3, 3.3, 2.4, 3.5, 3.0, 3.1, 3.5, 3.4), + x = c(41.0, 41.0, 39.0, 38.9, 40.6, 41.0, 40.7, 41.4, 36.0, 39.0, + 37.6, 40.0, 40.3, 40.7, 37.0, 40.0, 41.6, 36.3, 39.3, 40.0) + ) + D.list <- as.list(D) + my.glm.obj <- glm(y ~ x, family = gaussian(), data = D, x = TRUE) + + res.df <- glmSLMADS2(formula = stats::as.formula("y ~ x"), family = "gaussian", + offset = NULL, weights = NULL, newobj = "my.glm.obj", dataName = "D") + res.list <- glmSLMADS2(formula = stats::as.formula("y ~ x"), family = "gaussian", + offset = NULL, weights = NULL, newobj = "my.glm.obj", dataName = "D.list") + + expect_equal(res.list$data, "D.list") + expect_equal(res.list[names(res.list) != "data"], res.df[names(res.df) != "data"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-glmerSLMADS.assign.R b/tests/testthat/test-smk-glmerSLMADS.assign.R index 3c7ce4e4..9277ffad 100644 --- a/tests/testthat/test-smk-glmerSLMADS.assign.R +++ b/tests/testthat/test-smk-glmerSLMADS.assign.R @@ -56,6 +56,28 @@ test_that("glmerSLMADS.assign throws error when dataName is not a data.frame or ) }) +test_that("glmerSLMADS.assign gives the same result for data as a list as for a data.frame", { + set.seed(7) + D <- data.frame( + group = factor(rep(1:5, each = 10)), + x = rep(1:10, times = 5) + ) + lp <- -1.5 + 0.35 * D$x + rep(rnorm(5, sd = 1.5), each = 10) + D$y <- rbinom(50, 1, plogis(lp)) + D.list <- as.list(D) + + res.df <- suppressWarnings(glmerSLMADS.assign(formula = stats::as.formula("y ~ x + (1|group)"), + offset = NULL, weights = NULL, dataName = "D", family = "binomial", + control_type = NULL, control_value.transmit = NULL, + nAGQ = 1L, verbose = 0, theta = NULL, fixef = NULL)) + res.list <- suppressWarnings(glmerSLMADS.assign(formula = stats::as.formula("y ~ x + (1|group)"), + offset = NULL, weights = NULL, dataName = "D.list", family = "binomial", + control_type = NULL, control_value.transmit = NULL, + nAGQ = 1L, verbose = 0, theta = NULL, fixef = NULL)) + + expect_equal(lme4::fixef(res.list), lme4::fixef(res.df)) +}) + # # Done # diff --git a/tests/testthat/test-smk-glmerSLMADS2.R b/tests/testthat/test-smk-glmerSLMADS2.R index a40dd97a..94821cea 100644 --- a/tests/testthat/test-smk-glmerSLMADS2.R +++ b/tests/testthat/test-smk-glmerSLMADS2.R @@ -60,6 +60,28 @@ test_that("glmerSLMADS2 throws error when dataName is not a data.frame or list", ) }) +test_that("glmerSLMADS2 gives the same result for data as a list as for a data.frame", { + set.seed(7) + D <- data.frame( + group = factor(rep(1:5, each = 10)), + x = rep(1:10, times = 5) + ) + lp <- -1.5 + 0.35 * D$x + rep(rnorm(5, sd = 1.5), each = 10) + D$y <- rbinom(50, 1, plogis(lp)) + D.list <- as.list(D) + + res.df <- suppressWarnings(glmerSLMADS2(formula = stats::as.formula("y ~ x + (1|group)"), + offset = NULL, weights = NULL, dataName = "D", family = "binomial", + control_type = NULL, control_value.transmit = NULL, + nAGQ = 1L, verbose = 0, theta = NULL, fixef = NULL)) + res.list <- suppressWarnings(glmerSLMADS2(formula = stats::as.formula("y ~ x + (1|group)"), + offset = NULL, weights = NULL, dataName = "D.list", family = "binomial", + control_type = NULL, control_value.transmit = NULL, + nAGQ = 1L, verbose = 0, theta = NULL, fixef = NULL)) + + expect_equal(res.list, res.df) +}) + # # Done # diff --git a/tests/testthat/test-smk-histogramDS1.R b/tests/testthat/test-smk-histogramDS1.R index 10559b97..905c5841 100644 --- a/tests/testthat/test-smk-histogramDS1.R +++ b/tests/testthat/test-smk-histogramDS1.R @@ -31,6 +31,17 @@ test_that("histogramDS1 fails when x is not numeric or integer", { expect_error(histogramDS1("xvect", method.indicator=1, k=3, noise=0.25), "must be of type numeric or integer") }) +test_that("histogramDS1 gives the same result for numeric input as for integer", { + x.integer <- c(1:100) + x.numeric <- as.numeric(x.integer) + + res.integer <- histogramDS1("x.integer", method.indicator=1, k=3, noise=0.25) + res.numeric <- histogramDS1("x.numeric", method.indicator=1, k=3, noise=0.25) + + expect_equal(res.numeric$class, "numeric") + expect_equal(res.numeric[names(res.numeric) != "class"], res.integer[names(res.integer) != "class"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-histogramDS2.R b/tests/testthat/test-smk-histogramDS2.R index da26d99a..1176ddf7 100644 --- a/tests/testthat/test-smk-histogramDS2.R +++ b/tests/testthat/test-smk-histogramDS2.R @@ -30,6 +30,14 @@ test_that("histogramDS2 fails when x is not numeric or integer", { expect_error(histogramDS2("xvect", num.breaks=10, min=1, max=100, method.indicator=1, k=3, noise=0.25), "must be of type numeric or integer") }) +test_that("histogramDS2 gives the same result for numeric input as for integer", { + x.integer <- c(1:100) + x.numeric <- as.numeric(x.integer) + + expect_equal(histogramDS2("x.numeric", num.breaks=10, min=1, max=100, method.indicator=1, k=3, noise=0.25), + histogramDS2("x.integer", num.breaks=10, min=1, max=100, method.indicator=1, k=3, noise=0.25)) +}) + # # Done # diff --git a/tests/testthat/test-smk-isNaDS.R b/tests/testthat/test-smk-isNaDS.R index 33012766..f52057e2 100644 --- a/tests/testthat/test-smk-isNaDS.R +++ b/tests/testthat/test-smk-isNaDS.R @@ -88,6 +88,47 @@ test_that("isNaDS throws error when object does not exist", { ) }) +test_that("isNaDS throws error when object is the wrong type", { + bad_input <- list(1, 2, 3) + expect_error(isNaDS("bad_input"), regexp = "must be of type character, factor, integer, logical, numeric, data.frame or matrix") +}) + +test_that("isNaDS accepts a factor", { + input <- as.factor(c("a", "b", NA)) + + res <- isNaDS("input") + + expect_equal(res$class, "factor") + expect_false(res$is.na) +}) + +test_that("isNaDS accepts an integer vector", { + input <- c(1L, NA, 3L) + + res <- isNaDS("input") + + expect_equal(res$class, "integer") + expect_false(res$is.na) +}) + +test_that("isNaDS accepts a data.frame", { + input <- data.frame(v1 = c(1, NA), v2 = c("x", "y")) + + res <- isNaDS("input") + + expect_equal(res$class, "data.frame") + expect_false(res$is.na) +}) + +test_that("isNaDS accepts a matrix", { + input <- matrix(c(1, NA, 3, 4), nrow = 2) + + res <- isNaDS("input") + + expect_true("matrix" %in% res$class) + expect_false(res$is.na) +}) + # # Done # diff --git a/tests/testthat/test-smk-kurtosisDS1.R b/tests/testthat/test-smk-kurtosisDS1.R index 3a13786d..41a84c11 100644 --- a/tests/testthat/test-smk-kurtosisDS1.R +++ b/tests/testthat/test-smk-kurtosisDS1.R @@ -75,6 +75,17 @@ test_that("kurtosisDS1 throws error when object is not numeric or integer", { expect_error(kurtosisDS1("bad_input", 1), regexp = "must be of type numeric or integer") }) +test_that("kurtosisDS1 gives the same result for integer input as for numeric", { + input.numeric <- c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0) + input.integer <- as.integer(input.numeric) + + res.numeric <- kurtosisDS1("input.numeric", 1) + res.integer <- kurtosisDS1("input.integer", 1) + + expect_equal(res.integer$class, "integer") + expect_equal(res.integer[names(res.integer) != "class"], res.numeric[names(res.numeric) != "class"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-kurtosisDS2.R b/tests/testthat/test-smk-kurtosisDS2.R index 69a735a6..f0b880f0 100644 --- a/tests/testthat/test-smk-kurtosisDS2.R +++ b/tests/testthat/test-smk-kurtosisDS2.R @@ -48,6 +48,17 @@ test_that("kurtosisDS2 throws error when object is not numeric or integer", { expect_error(kurtosisDS2("bad_input", 2.5), regexp = "must be of type numeric or integer") }) +test_that("kurtosisDS2 gives the same result for integer input as for numeric", { + input.numeric <- c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0) + input.integer <- as.integer(input.numeric) + + res.numeric <- kurtosisDS2("input.numeric", 1.8) + res.integer <- kurtosisDS2("input.integer", 1.8) + + expect_equal(res.integer$class, "integer") + expect_equal(res.integer[names(res.integer) != "class"], res.numeric[names(res.numeric) != "class"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-listDS.R b/tests/testthat/test-smk-listDS.R index 51e75550..e6399dfd 100644 --- a/tests/testthat/test-smk-listDS.R +++ b/tests/testthat/test-smk-listDS.R @@ -40,6 +40,10 @@ test_that("simple listDS", { expect_equal(res.names[2], 'n2') }) +test_that("listDS throws error when object does not exist", { + expect_error(listDS(x.names = "nonexistent_object", eltnames = "a"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-lmerSLMADS.assign.R b/tests/testthat/test-smk-lmerSLMADS.assign.R index a5f8237a..a86df352 100644 --- a/tests/testthat/test-smk-lmerSLMADS.assign.R +++ b/tests/testthat/test-smk-lmerSLMADS.assign.R @@ -82,6 +82,25 @@ test_that("lmerSLMADS.assign throws error when dataName is not a data.frame or l ) }) +test_that("lmerSLMADS.assign gives the same result for data as a list as for a data.frame", { + set.seed(42) + D <- data.frame( + group = factor(rep(1:4, each = 6)), + x = rep(1:6, times = 4) + ) + D$y <- 2 + 0.5 * D$x + rep(rnorm(4, sd = 1), each = 6) + rnorm(24, sd = 0.3) + D.list <- as.list(D) + + res.df <- suppressWarnings(lmerSLMADS.assign(formula = stats::as.formula("y ~ x + (1|group)"), + offset = NULL, weights = NULL, dataName = "D", REML = TRUE, + control_type = NULL, control_value.transmit = NULL, optimizer = NULL, verbose = 0)) + res.list <- suppressWarnings(lmerSLMADS.assign(formula = stats::as.formula("y ~ x + (1|group)"), + offset = NULL, weights = NULL, dataName = "D.list", REML = TRUE, + control_type = NULL, control_value.transmit = NULL, optimizer = NULL, verbose = 0)) + + expect_equal(lme4::fixef(res.list), lme4::fixef(res.df)) +}) + # # Done # diff --git a/tests/testthat/test-smk-lmerSLMADS2.R b/tests/testthat/test-smk-lmerSLMADS2.R index 93d93000..e4d84aad 100644 --- a/tests/testthat/test-smk-lmerSLMADS2.R +++ b/tests/testthat/test-smk-lmerSLMADS2.R @@ -59,6 +59,25 @@ test_that("lmerSLMADS2 throws error when dataName is not a data.frame or list", ) }) +test_that("lmerSLMADS2 gives the same result for data as a list as for a data.frame", { + set.seed(42) + D <- data.frame( + group = factor(rep(1:4, each = 6)), + x = rep(1:6, times = 4) + ) + D$y <- 2 + 0.5 * D$x + rep(rnorm(4, sd = 1), each = 6) + rnorm(24, sd = 0.3) + D.list <- as.list(D) + + res.df <- suppressWarnings(lmerSLMADS2(formula = stats::as.formula("y ~ x + (1|group)"), + offset = NULL, weights = NULL, dataName = "D", REML = TRUE, + control_type = NULL, control_value.transmit = NULL, optimizer = NULL, verbose = 0)) + res.list <- suppressWarnings(lmerSLMADS2(formula = stats::as.formula("y ~ x + (1|group)"), + offset = NULL, weights = NULL, dataName = "D.list", REML = TRUE, + control_type = NULL, control_value.transmit = NULL, optimizer = NULL, verbose = 0)) + + expect_equal(res.list, res.df) +}) + # # Done # diff --git a/tests/testthat/test-smk-logDS.R b/tests/testthat/test-smk-logDS.R index d56ea1c9..d4347c15 100644 --- a/tests/testthat/test-smk-logDS.R +++ b/tests/testthat/test-smk-logDS.R @@ -45,6 +45,16 @@ test_that("logDS computes log for integer vector", { expect_equal(res, log(input)) }) + +test_that("logDS throws error when object does not exist", { + expect_error(logDS("nonexistent_object"), regexp = "does not exist") +}) + +test_that("logDS throws error when object is the wrong type", { + bad_input <- c("a", "b", "c") + expect_error(logDS("bad_input"), regexp = "must be of type numeric or integer") +}) + # # Done # diff --git a/tests/testthat/test-smk-matrixDetDS1.R b/tests/testthat/test-smk-matrixDetDS1.R index 37d39ac2..7b5be4a1 100644 --- a/tests/testthat/test-smk-matrixDetDS1.R +++ b/tests/testthat/test-smk-matrixDetDS1.R @@ -42,3 +42,13 @@ test_that("matrixDetDS1 is blocked in non-permissive mode", { M1 <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 10), 3, 3) expect_error(matrixDetDS1("M1", logarithm=FALSE), regexp = "non-permissive") }) + +test_that("matrixDetDS1 gives the same result for a data.frame as for a matrix", { + M1 <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 10), 3, 3) + M1.df <- as.data.frame(M1) + + res.matrix <- matrixDetDS1("M1", logarithm=FALSE) + res.df <- matrixDetDS1("M1.df", logarithm=FALSE) + + expect_equal(res.df, res.matrix) +}) diff --git a/tests/testthat/test-smk-matrixDetDS2.R b/tests/testthat/test-smk-matrixDetDS2.R index bf20a3a9..da9395ba 100644 --- a/tests/testthat/test-smk-matrixDetDS2.R +++ b/tests/testthat/test-smk-matrixDetDS2.R @@ -27,3 +27,13 @@ test_that("matrixDetDS2 errors when input is wrong type", { bad_input <- c("a", "b", "c") expect_error(matrixDetDS2("bad_input", logarithm=FALSE), regexp = "must be of type") }) + +test_that("matrixDetDS2 gives the same result for a data.frame as for a matrix", { + M1 <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 10), 3, 3) + M1.df <- as.data.frame(M1) + + res.matrix <- matrixDetDS2("M1", logarithm=FALSE) + res.df <- matrixDetDS2("M1.df", logarithm=FALSE) + + expect_equal(res.df, res.matrix) +}) diff --git a/tests/testthat/test-smk-matrixDimnamesDS.R b/tests/testthat/test-smk-matrixDimnamesDS.R index c82427ac..c8ac4b88 100644 --- a/tests/testthat/test-smk-matrixDimnamesDS.R +++ b/tests/testthat/test-smk-matrixDimnamesDS.R @@ -32,3 +32,13 @@ test_that("matrixDimnamesDS errors when input is wrong type", { bad_input <- c("a", "b", "c") expect_error(matrixDimnamesDS("bad_input", dimnames = list(c("r1"), c("c1"))), regexp = "must be of type") }) + +test_that("matrixDimnamesDS gives the same result for a data.frame as for a matrix", { + M1 <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 10), 3, 3) + M1.df <- as.data.frame(M1) + + res.matrix <- matrixDimnamesDS("M1", dimnames = list(c("r1", "r2", "r3"), c("c1", "c2", "c3"))) + res.df <- matrixDimnamesDS("M1.df", dimnames = list(c("r1", "r2", "r3"), c("c1", "c2", "c3"))) + + expect_equal(res.df, res.matrix) +}) diff --git a/tests/testthat/test-smk-matrixInvertDS.R b/tests/testthat/test-smk-matrixInvertDS.R index 4d9f5ec8..84d71137 100644 --- a/tests/testthat/test-smk-matrixInvertDS.R +++ b/tests/testthat/test-smk-matrixInvertDS.R @@ -30,3 +30,13 @@ test_that("matrixInvertDS errors when input is wrong type", { bad_input <- c("a", "b", "c") expect_error(matrixInvertDS("bad_input"), regexp = "must be of type") }) + +test_that("matrixInvertDS gives the same result for a data.frame as for a matrix", { + M1 <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 10), 3, 3) + M1.df <- as.data.frame(M1) + + res.matrix <- matrixInvertDS("M1") + res.df <- matrixInvertDS("M1.df") + + expect_equal(unname(res.df), unname(res.matrix)) +}) diff --git a/tests/testthat/test-smk-matrixMultDS.R b/tests/testthat/test-smk-matrixMultDS.R index 19eb58a1..2de6cb6b 100644 --- a/tests/testthat/test-smk-matrixMultDS.R +++ b/tests/testthat/test-smk-matrixMultDS.R @@ -32,3 +32,15 @@ test_that("matrixMultDS errors when input is wrong type", { M2 <- matrix(c(1, 2, 3, 4), 2, 2) expect_error(matrixMultDS("bad_input", "M2"), regexp = "must be of type") }) + +test_that("matrixMultDS gives the same result for a data.frame as for a matrix", { + M1 <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 10), 3, 3) + M2 <- matrix(c(5, 6, 7, 8, 9, 1, 2, 3, 4), 3, 3) + M1.df <- as.data.frame(M1) + M2.df <- as.data.frame(M2) + + res.matrix <- matrixMultDS("M1", "M2") + res.df <- matrixMultDS("M1.df", "M2.df") + + expect_equal(unname(res.df), unname(res.matrix)) +}) diff --git a/tests/testthat/test-smk-matrixTransposeDS.R b/tests/testthat/test-smk-matrixTransposeDS.R index c66d1366..69a79a1b 100644 --- a/tests/testthat/test-smk-matrixTransposeDS.R +++ b/tests/testthat/test-smk-matrixTransposeDS.R @@ -30,3 +30,13 @@ test_that("matrixTransposeDS errors when input is wrong type", { bad_input <- c("a", "b", "c") expect_error(matrixTransposeDS("bad_input"), regexp = "must be of type") }) + +test_that("matrixTransposeDS gives the same result for a data.frame as for a matrix", { + M1 <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 10), 3, 3) + M1.df <- as.data.frame(M1) + + res.matrix <- matrixTransposeDS("M1") + res.df <- matrixTransposeDS("M1.df") + + expect_equal(unname(res.df), unname(res.matrix)) +}) diff --git a/tests/testthat/test-smk-mdPatternDS.R b/tests/testthat/test-smk-mdPatternDS.R index 3e11a024..a641c769 100644 --- a/tests/testthat/test-smk-mdPatternDS.R +++ b/tests/testthat/test-smk-mdPatternDS.R @@ -94,6 +94,26 @@ test_that("mdPatternDS: sample 2 complete data.frame", { expect_equal(res$message, "Valid: all pattern counts meet disclosure requirements") }) +test_that("mdPatternDS throws error when object does not exist", { + expect_error(mdPatternDS("nonexistent_object"), regexp = "does not exist") +}) + +test_that("mdPatternDS throws error when object is the wrong type", { + bad_input <- c("a", "b", "c") + expect_error(mdPatternDS("bad_input"), regexp = "must be of type data.frame or matrix") +}) + +test_that("mdPatternDS gives the same result for a matrix as for a data.frame", { + x.df <- data.frame(v1 = c(0.0, 1.0, 2.0, 3.0, 4.0), v2 = c(4.0, 3.0, 2.0, 1.0, 0.0)) + x.matrix <- as.matrix(x.df) + + res.df <- mdPatternDS("x.df") + res.matrix <- mdPatternDS("x.matrix") + + expect_true("matrix" %in% res.matrix$class) + expect_equal(res.matrix[names(res.matrix) != "class"], res.df[names(res.df) != "class"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-meanDS.R b/tests/testthat/test-smk-meanDS.R index d15aa516..fda93cde 100644 --- a/tests/testthat/test-smk-meanDS.R +++ b/tests/testthat/test-smk-meanDS.R @@ -111,6 +111,17 @@ test_that("meanDS throws error when object is not numeric or integer", { expect_error(meanDS("bad_input"), regexp = "must be of type numeric, integer or logical") }) +test_that("meanDS gives the same result for integer input as for numeric", { + input.numeric <- c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0) + input.integer <- as.integer(input.numeric) + + res.numeric <- meanDS("input.numeric") + res.integer <- meanDS("input.integer") + + expect_equal(res.integer$class, "integer") + expect_equal(res.integer[names(res.integer) != "class"], res.numeric[names(res.numeric) != "class"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-meanSdGpDS.R b/tests/testthat/test-smk-meanSdGpDS.R index ed8ef814..4852b8b6 100644 --- a/tests/testthat/test-smk-meanSdGpDS.R +++ b/tests/testthat/test-smk-meanSdGpDS.R @@ -65,6 +65,37 @@ test_that("meanSdGpDS throws error when X is not numeric or integer", { expect_error(meanSdGpDS("bad_x", "index_var"), regexp = "must be of type numeric or integer") }) +test_that("meanSdGpDS gives the same result for an integer X as for numeric", { + x.numeric <- c(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0) + x.integer <- as.integer(x.numeric) + index_var <- as.factor(c("A", "A", "A", "A", "A", "B", "B", "B", "B", "B")) + + res.numeric <- meanSdGpDS("x.numeric", "index_var") + res.integer <- meanSdGpDS("x.integer", "index_var") + + expect_equal(res.integer$class.x, "integer") + expect_equal(res.integer[names(res.integer) != "class.x"], res.numeric[names(res.numeric) != "class.x"]) +}) + +test_that("meanSdGpDS gives the same result for an integer grouping variable as for a factor", { + x_var <- c(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0) + index.integer <- c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L) + index.factor <- as.factor(index.integer) + + res.factor <- meanSdGpDS("x_var", "index.factor") + res.integer <- meanSdGpDS("x_var", "index.integer") + + expect_equal(res.integer$class.index, "integer") + expect_equal(res.integer[names(res.integer) != "class.index"], res.factor[names(res.factor) != "class.index"]) +}) + +test_that("meanSdGpDS throws error when INDEX is the wrong type", { + x_var <- c(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0) + index_var <- c(TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) + + expect_error(meanSdGpDS("x_var", "index_var"), regexp = "must be of type factor, character, integer or numeric") +}) + # # Done # diff --git a/tests/testthat/test-smk-miceDS.R b/tests/testthat/test-smk-miceDS.R index 3b584da5..19eb98dd 100644 --- a/tests/testthat/test-smk-miceDS.R +++ b/tests/testthat/test-smk-miceDS.R @@ -50,6 +50,30 @@ test_that("miceDS", { }) +test_that("miceDS throws error when object does not exist", { + expect_error(miceDS(data='nonexistent_object', m=1, maxit=5, method=NULL, post=NULL, predictorMatrix=NULL, seed=NA, + ncol.pred.mat=NULL, newobj_mids='mids_object', newobj_df='impSet'), regexp = "does not exist") +}) + +test_that("miceDS throws error when object is the wrong type", { + bad_input <- c("a", "b", "c") + expect_error(miceDS(data='bad_input', m=1, maxit=5, method=NULL, post=NULL, predictorMatrix=NULL, seed=NA, + ncol.pred.mat=NULL, newobj_mids='mids_object', newobj_df='impSet'), regexp = "must be of type data.frame or matrix") +}) + +test_that("miceDS gives the same result for a matrix as for a data.frame", { + load(file = 'data_files/CNSIM/CNSIM1.rda') + D <- study1[, c("LAB_TSC", "LAB_TRIG", "LAB_HDL")] + D.matrix <- as.matrix(D) + + res.df <- miceDS(data='D', m=1, maxit=2, method=NULL, post=NULL, predictorMatrix=NULL, seed=123, + ncol.pred.mat=NULL, newobj_mids='mids_object', newobj_df='impSet') + res.matrix <- miceDS(data='D.matrix', m=1, maxit=2, method=NULL, post=NULL, predictorMatrix=NULL, seed=123, + ncol.pred.mat=NULL, newobj_mids='mids_object', newobj_df='impSet') + + expect_equal(res.matrix, res.df) +}) + # # Done # diff --git a/tests/testthat/test-smk-quantileMeanDS.R b/tests/testthat/test-smk-quantileMeanDS.R index d305c8de..30666f95 100644 --- a/tests/testthat/test-smk-quantileMeanDS.R +++ b/tests/testthat/test-smk-quantileMeanDS.R @@ -100,6 +100,17 @@ test_that("quantileMeanDS throws error when object is not numeric or integer", { expect_error(quantileMeanDS("bad_input"), regexp = "must be of type numeric or integer") }) +test_that("quantileMeanDS gives the same result for integer input as for numeric", { + input.numeric <- c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0) + input.integer <- as.integer(input.numeric) + + res.numeric <- quantileMeanDS("input.numeric") + res.integer <- quantileMeanDS("input.integer") + + expect_equal(res.integer$class, "integer") + expect_equal(res.integer[names(res.integer) != "class"], res.numeric[names(res.numeric) != "class"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-rangeDS.R b/tests/testthat/test-smk-rangeDS.R index 31f58566..3a1d67d1 100644 --- a/tests/testthat/test-smk-rangeDS.R +++ b/tests/testthat/test-smk-rangeDS.R @@ -55,6 +55,13 @@ test_that("rangeDS throws error when object is not numeric", { expect_error(rangeDS("input"), regexp = "must be of type numeric or integer") }) +test_that("rangeDS gives the same result for integer input as for numeric", { + input.numeric <- c(0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 3.0, 2.0, 1.0, 0.0) + input.integer <- as.integer(input.numeric) + + expect_equal(rangeDS("input.integer"), rangeDS("input.numeric")) +}) + # # Done # diff --git a/tests/testthat/test-smk-recodeValuesDS.R b/tests/testthat/test-smk-recodeValuesDS.R index dcbe39b5..ebdef2d5 100644 --- a/tests/testthat/test-smk-recodeValuesDS.R +++ b/tests/testthat/test-smk-recodeValuesDS.R @@ -139,6 +139,13 @@ test_that("recodeValuesDS errors when object has wrong type", { ) }) +test_that("recodeValuesDS gives the same result for integer input as for numeric", { + input.numeric <- c(1, 2, 3, 4, 1, 3) + input.integer <- as.integer(input.numeric) + + expect_equal(recodeValuesDS("input.integer", "1,3", "10,30"), recodeValuesDS("input.numeric", "1,3", "10,30")) +}) + # # Done # diff --git a/tests/testthat/test-smk-replaceNaDS.R b/tests/testthat/test-smk-replaceNaDS.R index 8d9c49d7..96fbe13c 100644 --- a/tests/testthat/test-smk-replaceNaDS.R +++ b/tests/testthat/test-smk-replaceNaDS.R @@ -40,6 +40,10 @@ test_that("simple replaceNaDS", { expect_equal(res[8], 7.7) }) +test_that("replaceNaDS throws error when object does not exist", { + expect_error(replaceNaDS("nonexistent_object", replacements = 0), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-skewnessDS1.R b/tests/testthat/test-smk-skewnessDS1.R index f5d3357b..7f272db8 100644 --- a/tests/testthat/test-smk-skewnessDS1.R +++ b/tests/testthat/test-smk-skewnessDS1.R @@ -75,6 +75,17 @@ test_that("skewnessDS1 throws error when object is not numeric or integer", { expect_error(skewnessDS1("bad_input", 1), regexp = "must be of type numeric or integer") }) +test_that("skewnessDS1 gives the same result for integer input as for numeric", { + input.numeric <- c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0) + input.integer <- as.integer(input.numeric) + + res.numeric <- skewnessDS1("input.numeric", 1) + res.integer <- skewnessDS1("input.integer", 1) + + expect_equal(res.integer$class, "integer") + expect_equal(res.integer[names(res.integer) != "class"], res.numeric[names(res.numeric) != "class"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-skewnessDS2.R b/tests/testthat/test-smk-skewnessDS2.R index 9e2ccea4..6e36b51e 100644 --- a/tests/testthat/test-smk-skewnessDS2.R +++ b/tests/testthat/test-smk-skewnessDS2.R @@ -48,6 +48,17 @@ test_that("skewnessDS2 throws error when object is not numeric or integer", { expect_error(skewnessDS2("bad_input", 2.5), regexp = "must be of type numeric or integer") }) +test_that("skewnessDS2 gives the same result for integer input as for numeric", { + input.numeric <- c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0) + input.integer <- as.integer(input.numeric) + + res.numeric <- skewnessDS2("input.numeric", 1.8) + res.integer <- skewnessDS2("input.integer", 1.8) + + expect_equal(res.integer$class, "integer") + expect_equal(res.integer[names(res.integer) != "class"], res.numeric[names(res.numeric) != "class"]) +}) + # # Done # diff --git a/tests/testthat/test-smk-sqrtDS.R b/tests/testthat/test-smk-sqrtDS.R index 273baec1..d06b4f38 100644 --- a/tests/testthat/test-smk-sqrtDS.R +++ b/tests/testthat/test-smk-sqrtDS.R @@ -156,6 +156,16 @@ test_that("simple sqrtDS", { expect_true(is.nan(res[5])) expect_true(is.nan(res[6])) }) + +test_that("sqrtDS throws error when object does not exist", { + expect_error(sqrtDS("nonexistent_object"), regexp = "does not exist") +}) + +test_that("sqrtDS throws error when object is the wrong type", { + bad_input <- c("a", "b", "c") + expect_error(sqrtDS("bad_input"), regexp = "must be of type numeric or integer") +}) + # # Done # diff --git a/tests/testthat/test-smk-unListDS.R b/tests/testthat/test-smk-unListDS.R index b8f814fe..806bf552 100644 --- a/tests/testthat/test-smk-unListDS.R +++ b/tests/testthat/test-smk-unListDS.R @@ -46,6 +46,10 @@ test_that("simple unListDS", { expect_equal(res.names[6], 'v23') }) +test_that("unListDS throws error when object does not exist", { + expect_error(unListDS("nonexistent_object"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-uniqueDS.R b/tests/testthat/test-smk-uniqueDS.R index 3f4b908c..52064f89 100644 --- a/tests/testthat/test-smk-uniqueDS.R +++ b/tests/testthat/test-smk-uniqueDS.R @@ -49,6 +49,10 @@ test_that("simple uniqueDS for list", { expect_length(names(res), 0) }) +test_that("uniqueDS throws error when object does not exist", { + expect_error(uniqueDS("nonexistent_object"), regexp = "does not exist") +}) + # # Done # diff --git a/tests/testthat/test-smk-varDS.R b/tests/testthat/test-smk-varDS.R index f3da7671..82b41363 100644 --- a/tests/testthat/test-smk-varDS.R +++ b/tests/testthat/test-smk-varDS.R @@ -108,6 +108,17 @@ test_that("varDS throws error when object is not numeric or integer", { expect_error(varDS("bad_input"), regexp = "must be of type numeric, integer or logical") }) +test_that("varDS gives the same result for integer input as for numeric", { + input.numeric <- c(0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0) + input.integer <- as.integer(input.numeric) + + res.numeric <- varDS("input.numeric") + res.integer <- varDS("input.integer") + + expect_equal(res.integer$class, "integer") + expect_equal(res.integer[names(res.integer) != "class"], res.numeric[names(res.numeric) != "class"]) +}) + # # Done # From 81a9893ccaa1d9d2d7f0a8d4e32b2bf16b13c9b9 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Thu, 15 Oct 2026 16:51:07 +0200 Subject: [PATCH 31/38] Remove server functions of defunct client functions --- NAMESPACE | 17 - R/blackBoxDS.R | 385 ---------------------- R/blackBoxRanksDS.R | 275 ---------------- R/dataFrameFillDS.R | 105 ------ R/extractQuantilesDS1.R | 134 -------- R/extractQuantilesDS2.R | 95 ------ R/messageDS.R | 99 ------ R/minMaxRandDS.R | 76 ----- R/ranksSecureDS1.R | 34 -- R/ranksSecureDS2.R | 111 ------- R/ranksSecureDS3.R | 46 --- R/ranksSecureDS4.R | 108 ------ R/ranksSecureDS5.R | 53 --- R/recodeLevelsDS.R | 29 -- R/subsetByClassDS.R | 79 ----- R/subsetByClassHelper1.R | 41 --- R/subsetByClassHelper2.R | 64 ---- R/subsetByClassHelper3.R | 59 ---- R/subsetDS.R | 134 -------- R/table2DDS.R | 61 ---- R/testObjExistsDS.R | 33 -- inst/DATASHIELD | 17 - inst/WORDLIST | 5 - man/blackBoxDS.Rd | 70 ---- man/blackBoxRanksDS.Rd | 64 ---- man/dataFrameFillDS.Rd | 45 --- man/extractQuantilesDS1.Rd | 60 ---- man/extractQuantilesDS2.Rd | 60 ---- man/messageDS.Rd | 40 --- man/minMaxRandDS.Rd | 35 -- man/ranksSecureDS1.Rd | 35 -- man/ranksSecureDS2.Rd | 44 --- man/ranksSecureDS3.Rd | 46 --- man/ranksSecureDS4.Rd | 55 ---- man/ranksSecureDS5.Rd | 55 ---- man/recodeLevelsDS.Rd | 23 -- man/subsetByClassDS.Rd | 32 -- man/subsetDS.Rd | 57 ---- man/table2DDS.Rd | 31 -- man/testObjExistsDS.Rd | 27 -- tests/testthat/test-arg-dataFrameFillDS.R | 55 ---- tests/testthat/test-smk-dataFrameFillDS.R | 110 ------- tests/testthat/test-smk-messageDS.R | 92 ------ tests/testthat/test-smk-minMaxRandDS.R | 38 --- tests/testthat/test-smk-recodeLevelsDS.R | 47 --- tests/testthat/test-smk-subsetByClassDS.R | 88 ----- tests/testthat/test-smk-subsetDS.R | 126 ------- tests/testthat/test-smk-testObjExistsDS.R | 270 --------------- 48 files changed, 3665 deletions(-) delete mode 100644 R/blackBoxDS.R delete mode 100644 R/blackBoxRanksDS.R delete mode 100644 R/dataFrameFillDS.R delete mode 100644 R/extractQuantilesDS1.R delete mode 100644 R/extractQuantilesDS2.R delete mode 100644 R/messageDS.R delete mode 100644 R/minMaxRandDS.R delete mode 100644 R/ranksSecureDS1.R delete mode 100644 R/ranksSecureDS2.R delete mode 100644 R/ranksSecureDS3.R delete mode 100644 R/ranksSecureDS4.R delete mode 100644 R/ranksSecureDS5.R delete mode 100644 R/recodeLevelsDS.R delete mode 100644 R/subsetByClassDS.R delete mode 100644 R/subsetByClassHelper1.R delete mode 100644 R/subsetByClassHelper2.R delete mode 100644 R/subsetByClassHelper3.R delete mode 100644 R/subsetDS.R delete mode 100644 R/table2DDS.R delete mode 100644 R/testObjExistsDS.R delete mode 100644 man/blackBoxDS.Rd delete mode 100644 man/blackBoxRanksDS.Rd delete mode 100644 man/dataFrameFillDS.Rd delete mode 100644 man/extractQuantilesDS1.Rd delete mode 100644 man/extractQuantilesDS2.Rd delete mode 100644 man/messageDS.Rd delete mode 100644 man/minMaxRandDS.Rd delete mode 100644 man/ranksSecureDS1.Rd delete mode 100644 man/ranksSecureDS2.Rd delete mode 100644 man/ranksSecureDS3.Rd delete mode 100644 man/ranksSecureDS4.Rd delete mode 100644 man/ranksSecureDS5.Rd delete mode 100644 man/recodeLevelsDS.Rd delete mode 100644 man/subsetByClassDS.Rd delete mode 100644 man/subsetDS.Rd delete mode 100644 man/table2DDS.Rd delete mode 100644 man/testObjExistsDS.Rd delete mode 100644 tests/testthat/test-arg-dataFrameFillDS.R delete mode 100644 tests/testthat/test-smk-dataFrameFillDS.R delete mode 100644 tests/testthat/test-smk-messageDS.R delete mode 100644 tests/testthat/test-smk-minMaxRandDS.R delete mode 100644 tests/testthat/test-smk-recodeLevelsDS.R delete mode 100644 tests/testthat/test-smk-subsetByClassDS.R delete mode 100644 tests/testthat/test-smk-subsetDS.R delete mode 100644 tests/testthat/test-smk-testObjExistsDS.R diff --git a/NAMESPACE b/NAMESPACE index 4bf3dc67..4efc223c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,8 +13,6 @@ export(asLogicalDS) export(asMatrixDS) export(asNumericDS) export(aucDS) -export(blackBoxDS) -export(blackBoxRanksDS) export(boxPlotGGDS) export(boxPlotGG_data_TreatmentDS) export(boxPlotGG_data_Treatment_numericDS) @@ -31,7 +29,6 @@ export(corDS) export(corTestDS) export(covDS) export(dataFrameDS) -export(dataFrameFillDS) export(dataFrameSortDS) export(dataFrameSubsetDS1) export(dataFrameSubsetDS2) @@ -40,8 +37,6 @@ export(dimDS) export(dmtC2SDS) export(elsplineDS) export(expDS) -export(extractQuantilesDS1) -export(extractQuantilesDS2) export(fixClassDS) export(fixColsDS) export(fixLevelsDS) @@ -93,10 +88,8 @@ export(mdPatternDS) export(meanDS) export(meanSdGpDS) export(mergeDS) -export(messageDS) export(metadataDS) export(miceDS) -export(minMaxRandDS) export(namesDS) export(nsDS) export(numNaDS) @@ -107,14 +100,8 @@ export(rNormDS) export(rPoisDS) export(rUnifDS) export(rangeDS) -export(ranksSecureDS1) -export(ranksSecureDS2) -export(ranksSecureDS3) -export(ranksSecureDS4) -export(ranksSecureDS5) export(rbindDS) export(reShapeDS) -export(recodeLevelsDS) export(recodeValuesDS) export(repDS) export(replaceNaDS) @@ -127,16 +114,12 @@ export(setSeedDS) export(skewnessDS1) export(skewnessDS2) export(sqrtDS) -export(subsetByClassDS) -export(subsetDS) export(table1DDS) -export(table2DDS) export(tableDS) export(tableDS.assign) export(tableDS2) export(tapplyDS) export(tapplyDS.assign) -export(testObjExistsDS) export(unListDS) export(uniqueDS) export(varDS) diff --git a/R/blackBoxDS.R b/R/blackBoxDS.R deleted file mode 100644 index 40c882a0..00000000 --- a/R/blackBoxDS.R +++ /dev/null @@ -1,385 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description The first key serverside function that sets up the V2BR for -#' ranking in the client. -#' @details Severside assign function called by ds.ranksSecure. -#' Creates pseudo-data by using the real distribution of values in V2BR -#' to create a large number of synthetic data with a similar distribution to -#' the values in V2BR but with a slightly broader distribution at both ends -#' to ensure that any extreme values in the "combined real+pseudo data vector" -#' are all pseudo-data. Also ensures that the number of decimal places of -#' the values in the V2BR is reflected by the number of decimal places in -#' the pseudodata. Finally, takes the "combined real+pseudo data vector" through -#' seven rounds of rank consistent encryption that involves algorithms -#' themselves generated by a pseudorandom process that selects which -#' transformation to apply and with what parameters. The encryption algorithms -#' are the same in each study ensuring that ranks also remain consistent between -#' studies. After encryption the encrypted "combined real+pseudo data vector" is -#' written to the serverside as a dataframe also including other key component -#' vectors from the first stage of the ranking procedure. -#' For more details about the cluster of functions that -#' collectively enable secure global ranking and estimation of global quantiles -#' see the associated document entitled "secure.global.ranking.docx". Also -#' see the header file for ds.ranksSecure -#' @param input.var.name a character string specifying the name of V2BR. This -#' argument is set by the argument with the same name in the clientside function -#' ds.ranksSecure -#' @param shared.seedval a pseudorandom number seed that ensures that the -#' processes generating the order and parameterisation of the encryption -#' algorithms are the same in each study. This argument is set by the argument -#' in the clientside function ds.ranksSecure. For more -#' details, including future plans to share this starting seed in a more secure -#' way, please see the associated document entitled "secure.global.ranking.docx" -#' and the header file for ds.ranksSecure. -#' @param synth.real.ratio an integer value representing -#' the ratio of synthetic (pseudo-data) values to the real number of -#' values in V2BR. This argument is set by the argument with the same name -#' in the clientside function ds.ranksSecure. For more details, please see the -#' associated document entitled "secure.global.ranking.docx" and the header file -#' for ds.ranksSecure. -#' @param NA.manage character string indicating how missing values (NAs) in -#' V2BR should be managed. It takes three possible values: "NA.delete", -#' "NA.low","NA.hi". This argument is set by the argument with the same name -#' in the clientside function ds.ranksSecure. For more details, please see the -#' associated document entitled "secure.global.ranking.docx" and the header file -#' for ds.ranksSecure. -#' @return writes a data frame object entitled blackbox.output.df to the -#' serverside. In each study this contains the encrypted -#' "combined real+pseudo data vector" and a range of other key components -#' from the first stage of the ranking procedure. For more details see the -#' associated document entitled "secure.global.ranking.docx" -#' @author Paul Burton 9th November, 2021 -#' @export -#' -blackBoxDS <- function(input.var.name=NULL, - shared.seedval, synth.real.ratio, NA.manage){ #START FUNC - - ####################################################### - #MODULE 1: CAPTURE THE nfilter SETTINGS - #thr<-dsBase::listDisclosureSettingsDS() - #nfilter.tab <- as.numeric(thr$nfilter.tab) - #nfilter.glm <- as.numeric(thr$nfilter.glm) - #nfilter.subset <- as.numeric(thr$nfilter.subset) - #nfilter.string <- as.numeric(thr$nfilter.string) - #nfilter.stringShort <- as.numeric(thr$nfilter.stringShort) - #nfilter.kNN <- as.numeric(thr$nfilter.kNN) - #nfilter.noise <- as.numeric(thr$nfilter.noise) - #nfilter.levels <- as.numeric(thr$nfilter.levels) - ######################################################## - - # back-up current .Random.seed and revert on.exit - if (exists(x = ".Random.seed", envir = globalenv())) { - assign(x = ".old_seed", value = .Random.seed, envir = parent.frame()); - on.exit({ assign(x = ".Random.seed", value = parent.frame()$.old_seed, envir = globalenv()); remove(".old_seed", envir = parent.frame()) }, add = TRUE) - } else - on.exit(if (exists(x = ".Random.seed", envir = globalenv())) remove(".Random.seed", envir = globalenv()), add = TRUE) - - input.var <- eval(parse(text=input.var.name), envir = parent.frame()) - - input.var.orig<-input.var - -#manage NAs - -if(NA.manage=="NA.delete"){ - input.var <- input.var[stats::complete.cases(input.var)] - input.var.orig<-input.var - } - - if(NA.manage=="NA.low"){ - input.var[is.na(input.var)]<-min.max.df[,1] - input.var.orig<-input.var - } - - if(NA.manage=="NA.hi"){ - input.var[is.na(input.var)]<-min.max.df[,2] - input.var.orig<-input.var - } - -#ESTIMATED OVERALL MEAN AND SD FROM meanQuantileDS -#SAVED IN input.mean.sd.df BY ds.dmtC2S -max.sd.input.var<-input.mean.sd.df$max.sd.input.var -mean.input.var<-input.mean.sd.df$mean.input.var - -numsubs.real<-length(input.var.orig) -numsubs.synth<-length(input.var.orig)*synth.real.ratio -numsubs<-numsubs.real+numsubs.synth - -#Create indicators for original original sequence order and real/synthetic -ID.seq.real.synth.orig<-1:numsubs -is.real.synth.orig<-c(rep(1,numsubs.real),rep(0,numsubs.synth)) - -#Allow individual implementations of blackBoxDS for groups of projects to have a -#unique but shared starting seed (given specified starting seed) but only -#the person setting up the function can know how that seed is perturbed relative -#to the specified seed - -restart.seed.transformation.control.n<-37169 -restart.seed.other.seed.actions<-67881 - -#Now set up for repeated transformations -set.seed(shared.seedval) - -#Create long fixed sequence of calls to seed to keep resetting seed at start -null.vector<-stats::runif(restart.seed.transformation.control.n,0,1) - -#Create transformation control vectors/values first so all studies -#have the same transformation controls given input random seed -#even if the lengths of later vectors (eg synthetic concealing data) are -#different between studies so would lead to inconsistent control -#vectors/values - - -control.vector<-sample(c(1,1,2,2,3,3),replace=FALSE) -#control.vector<-c(1,control.vector) -control.vector - - -control.value<-stats::runif(6,0.0001,1) -control.value - -#Reset seed for other purposes -#Include study-specific component so seeds different in each study - -#This code ensures you end up with a valid seed - -study.specific.seed<-tryCatch(sum(abs(input.var.orig),na.rm=TRUE)/abs(stats::quantile(input.var.orig,0.25,na.rm=TRUE))+abs(stats::median(input.var.orig,na.rm=TRUE))+abs(stats::quantile(input.var.orig,0.75,na.rm=TRUE))) - -if(is.na(study.specific.seed)||is.infinite(study.specific.seed)) -{ - #specific seed to ensure reproducibility if tryCatch fails - set.seed(671628) - study.specific.seed<-stats::runif(1,1000,1000000) -} - -if(study.specific.seed<1000){ - study.specific.seed<-study.specific.seed*1234 - if(study.specific.seed<1||study.specific.seed>5.0E08){ - study.specific.seed<-shared.seedval - } -} - -study.specific.seed<-round(study.specific.seed,0) - - -set.seed(shared.seedval+restart.seed.other.seed.actions+study.specific.seed) - - -#Check that no attempt has been made to enter a fake value for max.sd.input.var -#via the clientside that is close to zero so that the random component of the -#sythetic data is always effectively zero - -if(max.sd.input.var<(sqrt(stats::var(input.var, na.rm=TRUE)))/2){ - error.message<- - paste0("FAILED: the estimated standard deviation being used to generate part of the random component of the synthetic pseudodata is considerably smaller than the actual standard deviation of the input variable (V2BR) suggesting that information may have been fed in from the clientside to create a modified value that is too small. As this increases disclosure risk the whole ranking analysis has been halted") - stop(error.message, call. = FALSE) -} - -#create synthetic data vector -input.var.synth.fixed<-sample(input.var.orig,numsubs.synth,replace=TRUE) -input.var.synth.random<-stats::rnorm(numsubs.synth,0,max.sd.input.var) -input.var.synth.random.rounded<-input.var.synth.random - -input.var.synth<-input.var.synth.fixed+input.var.synth.random - -#ARE THERE MULTIPLE TIES SUGGESTING LIMITED DECIMAL PLACES OR POWERS OF 10 -#IF SO MODIFY input.var.synth ACCORDINGLY - - - num.3dp<-sum(round(input.var.orig%%0.001,2)==0) - prop.3dp<-num.3dp/length(input.var.orig) - if(prop.3dp>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,3) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - num.2dp<-sum(round(input.var.orig%%0.01,2)==0) - prop.2dp<-num.2dp/length(input.var.orig) - if(prop.2dp>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,2) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - - num.1dp<-sum(round(input.var.orig%%0.1,2)==0) - prop.1dp<-num.1dp/length(input.var.orig) - if(prop.1dp>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,1) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - num.integers<-sum(round(input.var.orig%%1,2)==0) - prop.integers<-num.integers/length(input.var.orig) - if(prop.integers>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,0) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - num.tens<-sum(round(input.var.orig%%10,2)==0) - prop.tens<-num.tens/length(input.var.orig) - if(prop.tens>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,-1) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - num.hundreds<-sum(round(input.var.orig%%100,2)==0) - prop.hundreds<-num.hundreds/length(input.var.orig) - if(prop.hundreds>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,-2) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - num.thousands<-sum(round(input.var.orig%%1000,2)==0) - prop.thousands<-num.thousands/length(input.var.orig) - if(prop.thousands>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,-3) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - -#Initialise input.var for analysis. Start by converting to values 0 to 1 -#in same order as original input.var. Going to use probit function (pnorm) for this. -#This can take any values -inf to +inf but to avoid extreme value rounding errors -#scale input.var to normal 0 1 - -input.var.real.orig<-input.var.orig - -#have to round this because otherwise eg 0.3 -> 0.2999999999999999999 -input.var.real.synth.orig<-round(c(input.var.real.orig,input.var.synth),5) - - -#input.var.probit.temp<-((input.var.real.synth.orig-mean.input.var)/max.sd.input.var) -input.var.probit.temp<-(input.var.real.synth.orig-mean.input.var)/(max.sd.input.var) -input.var.probit<-stats::pnorm(input.var.probit.temp) - - - -if(min(input.var.probit)<=0 | max(input.var.probit)>=1){ - error.message<- - paste0("FAILED: initialised values should strictly be >0 and <1 this rule has been violated - there is possiblyly an NA, inf or other error in the input.var.orig") - stop(error.message, call. = FALSE) -} - - -if(min(rank(input.var.real.synth.orig)-rank(input.var.probit))<0 | max(rank(input.var.real.synth.orig)-rank(input.var.probit))>0) { - error.message<- - paste0("FAILED: probit initialised values are not in an identical order to the original input variable please check") - stop(error.message, call. = FALSE) -} - - - -intermediate.value.matrix<-matrix(NA,ncol=8,nrow=numsubs) - -intermediate.value.matrix[,1]<-input.var.real.synth.orig -intermediate.value.matrix[,2]<-input.var.probit - -utils::head(intermediate.value.matrix) - -for(cv in 3:(length(control.vector)+2)){ - - if(control.vector[cv-2]==1){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]^(control.value[cv-2]) - } - if(control.vector[cv-2]==2){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]+(control.value[cv-2]) - } - if(control.vector[cv-2]==3){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]*(control.value[cv-2]) - } -} - -intermediate.value.matrix<-cbind(intermediate.value.matrix,ID.seq.real.synth.orig,is.real.synth.orig) -colnames(intermediate.value.matrix)<-c("input.var.real.synth.orig","input.var.probit", - 1:6,"ID.seq.real.synth.orig","is.real.synth.orig") - - - -dim(intermediate.value.matrix) -utils::head(intermediate.value.matrix) -utils::tail(intermediate.value.matrix) - - -rank.intermediate.value.matrix<-matrix(NA,ncol=8,nrow=numsubs) - - - -for(k in 1:8) -{ - rank.intermediate.value.matrix[,k]<-rank(intermediate.value.matrix[,k]) -} - -rank.intermediate.value.matrix<-cbind(rank.intermediate.value.matrix,ID.seq.real.synth.orig,is.real.synth.orig) - -colnames(rank.intermediate.value.matrix)<-c("input.var.real.synth.orig","input.var.probit", - 1:6,"ID.seq.real.synth.orig","is.real.synth.orig") - -utils::head(rank.intermediate.value.matrix) -utils::tail(rank.intermediate.value.matrix) - - -message("\nRANKS IN ALL COLUMNS ABOVE SHOULD BE THE SAME\n") - -control.vector -control.value - - -#CREATE blackBox OUTPUT DF - -intermediate.value.df<-data.frame(intermediate.value.matrix) - - -encrypted.var<-intermediate.value.df$"X6" - -ranks.input.var.real.synth.orig<-rank(intermediate.value.df$input.var.real.synth.orig) -ranks.encrypted.var<-rank(intermediate.value.df$"X6") - - -output.df<-data.frame(cbind(input.var.real.synth.orig,encrypted.var,ranks.input.var.real.synth.orig,ranks.encrypted.var,ID.seq.real.synth.orig,is.real.synth.orig)) - -utils::head(output.df) -utils::tail(output.df) - - - -#Sort df by magnitude of key variable -ord.by.val<-order(input.var.real.synth.orig) - -output.temp.sort.by.val<-output.df[ord.by.val,] - - -ID.by.val<-1:nrow(output.temp.sort.by.val) - -output.df.sort.by.val<-data.frame(cbind(output.temp.sort.by.val,ID.by.val)) - - -utils::head(output.df.sort.by.val) -utils::tail(output.df.sort.by.val) -dim(output.df.sort.by.val) - - - -blackbox.output.df <- output.df.sort.by.val - - -if(sum(round(rank(blackbox.output.df[,3])-rank(blackbox.output.df[,4]),2)==0)!=numsubs) -{ - error.message<- - paste0("FAILED: inconsistent values across different transformations in black box, - try a different seed. Altenatively this could reflect modification of the - clientside code which is not recommended. Finally, it can also occur - if the R session on one or more of the Armadillo/Opal data servers runs out - of memory") - stop(error.message, call. = FALSE) -}else{ - message("\nPROCESSING SUCCESSFUL, ALL RANKS AGREE FOR ALL TRANSFORMATIONS\n\n") -} - - -return(blackbox.output.df) - -} #END FUNCTION - -#ASSIGN -# blackBoxDS - - diff --git a/R/blackBoxRanksDS.R b/R/blackBoxRanksDS.R deleted file mode 100644 index c2380242..00000000 --- a/R/blackBoxRanksDS.R +++ /dev/null @@ -1,275 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description The second key serverside function that prepares the global -#' ranks of the the real data only generated in the first stage of the -#' ranking procedure and encrypts them in preparation for generating global -#' ranks that correspond 1 to 1 with only the real data in V2BR. -#' @details Severside assign function called by ds.ranksSecure. It takes the -#' global ranks currently held in sR5.df which reflect the global ranks based on -#' the "combined real+pseudo data vector" as encrypted by blackBoxDS -#' but with all pseudo-data stripped out. It then uses these global ranks (of -#' the real data) as if they were a new variable to be ranked. This is then -#' equivalent to blackBoxDS with the primary difference that no -#' pseudo-data are needed. This is because the global ranks are fundamentally -#' non-disclosive and so can be transferred to the clientside with no risk of -#' disclosure. However, in order to ensure that the client cannot compare -#' the list of global.ranks in sR4.df (after initial global ranking based on -#' ranking of real and pseudo-data combined) with the global.ranks to be -#' generated by blackBoxRanksDS (based solely on the real data they are -#' processed through seven more rounds of encryption as before in blackBoxDS. -#' In consequence the client remains unable to determine which of the original -#' global ranks corresponded to real data and which to pseudo-data. In -#' addition, blackBoxRanksDS does not need to determine the number of decimal -#' places in the data because it is only applied to ranks which are assumed to -#' be integers. For more details about the cluster of functions that -#' collectively enable secure global ranking and estimation of global quantiles -#' see the associated document entitled "secure.global.ranking.docx". Also -#' see the header file for ds.ranksSecure and the header file for blackBoxDS -#' @param input.var.name a character string specifying the name of the -#' vector holding the global ranks. This argument is set automatically by -#' the clientside function ds.ranksSecure -#' @param shared.seedval a pseudorandom number seed that ensures that the -#' processes generating the order and parameterisation of the encryption -#' algorithms are the same in each study. This argument is set by the argument -#' in the clientside function ds.ranksSecure. The -#' seed value shared by all studies in setting up the encryption procedures -#' in blackBoxRanksDS is arbitrarily changed from that used to set up the -#' encryption procedures in blackBoxDS, so the the set of 7 encryption -#' algorithms is deliberately different. For more -#' details, including future plans to share this starting seed in a more secure -#' way, please see the associated document entitled "secure.global.ranking.docx" -#' and the header file for ds.ranksSecure. -#' @return writes a data frame object entitled blackbox.ranks.df to the -#' serverside. In each study this contains the encrypted global ranks -#' and a range of other key components from the second stage (ranking of global -#' ranks for real observations only) of the ranking procedure. For more details -#' see the associated document entitled "secure.global.ranking.docx" -#' @author Paul Burton 9th November, 2021 -#' @export -#' -blackBoxRanksDS <- function(input.var.name=NULL, shared.seedval){ #START FUNC - - ####################################################### - #MODULE 1: CAPTURE THE nfilter SETTINGS - #thr<-dsBase::listDisclosureSettingsDS() - #nfilter.tab <- as.numeric(thr$nfilter.tab) - #nfilter.glm <- as.numeric(thr$nfilter.glm) - #nfilter.subset <- as.numeric(thr$nfilter.subset) - #nfilter.string <- as.numeric(thr$nfilter.string) - #nfilter.stringShort <- as.numeric(thr$nfilter.stringShort) - #nfilter.kNN <- as.numeric(thr$nfilter.kNN) - #nfilter.noise <- as.numeric(thr$nfilter.noise) - #nfilter.levels <- as.numeric(thr$nfilter.levels) - ######################################################## - - # back-up current .Random.seed and revert on.exit - if (exists(x = ".Random.seed", envir = globalenv())) { - assign(x = ".old_seed", value = .Random.seed, envir = parent.frame()); - on.exit({ assign(x = ".Random.seed", value = parent.frame()$.old_seed, envir = globalenv()); remove(".old_seed", envir = parent.frame()) }, add = TRUE) - } else - on.exit(if (exists(x = ".Random.seed", envir = globalenv())) remove(".Random.seed", envir = globalenv()), add = TRUE) - -input.var <- eval(parse(text=input.var.name), envir = parent.frame()) -input.global.ranks<-input.var - -#ESTIMATED OVERALL MEAN AND SD FROM meanQuantileDS -#SAVED IN input.mean.sd.df BY ds.dmtC2S -max.sd.input.ranks<-input.ranks.sd.df$max.sd.input.ranks -mean.input.ranks<-input.ranks.sd.df$mean.input.ranks - -numsubs.real<-length(input.global.ranks) - -numsubs<-numsubs.real - -#Create indicators for original original sequence order and real/synthetic -ID.seq.real.orig<-1:numsubs - -#Allow individual implementations of blackBoxDS for groups of projects to have a -#unique but shared starting seed (given specified starting seed) but only -#the person setting up the function can know how that seed is perturbed relative -#to the specified seed - -restart.seed.transformation.control.n<-78615 -restart.seed.other.seed.actions<-43 - -#Now set up for repeated transformations -shared.seedval<-(shared.seedval+19)*7 -set.seed(shared.seedval) - -#Create long fixed sequence of calls to seed to keep resetting seed at start -null.vector<-stats::runif(restart.seed.transformation.control.n,0,1) - -#Create transformation control vectors/values first so all studies -#have the same transformation controls given input random seed -#even if the lengths of later vectors (eg synthetic concealing data) are -#different between studies so would lead to inconsistent control -#vectors/values - - -control.vector<-sample(c(1,1,2,2,3,3),replace=FALSE) -#control.vector<-c(1,control.vector) -control.vector - - -control.value<-stats::runif(6,0.0001,1) -control.value - -#Reset seed for other purposes -set.seed(shared.seedval+restart.seed.other.seed.actions) - - -#Initialise input.var for analysis. Start by converting to values 0 to 1 -#in same order as original input.var. Going to use probit function (stats::pnorm) for this. -#This can take any values -inf to +inf but to avoid extreme value rounding errors -#scale input.var to normal 0 1 - -#Unlike blackBoxDS no need to check that no attempt has been made to enter a -#fake value for max.sd.input.var. That is because in blackBoxRanksDS no -#synthetic data are generated so the only impact of changing the value of -#max.sd.input.var is to change the first probit transformation. This will either -#cause the whole analysis to fail if the value of max.sd.input.var is too small -#or large or will have no effect at all. So there is no enhanced disclosure risk -#and no need for the equivalent disclosure trap. - -input.var.probit.temp<-((input.global.ranks-mean.input.ranks)/max.sd.input.ranks) -input.var.probit<-stats::pnorm(input.var.probit.temp) - - -if(min(input.var.probit)<=0 | max(input.var.probit)>=1){ - error.message<- - paste0("FAILED: initialised values should strictly be >0 and <1 this rule has been violated - there is possiblyly an NA, inf or other error in the input.global.ranks") - stop(error.message, call. = FALSE) -} - - -if(min(rank(input.global.ranks)-rank(input.var.probit))<0 | max(rank(input.global.ranks)-rank(input.var.probit))>0) { - error.message<- - paste0("FAILED: probit initialised values are not in an identical order to the original input variable please check") - stop(error.message, call. = FALSE) -} - - - -intermediate.value.matrix<-matrix(NA,ncol=8,nrow=numsubs) - -intermediate.value.matrix[,1]<-input.global.ranks -intermediate.value.matrix[,2]<-input.var.probit - - -for(cv in 3:(length(control.vector)+2)){ - - if(control.vector[cv-2]==1){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]^(control.value[cv-2]) - } - if(control.vector[cv-2]==2){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]+(control.value[cv-2]) - } - if(control.vector[cv-2]==3){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]*(control.value[cv-2]) - } -} - -intermediate.value.matrix<-cbind(intermediate.value.matrix,ID.seq.real.orig) -colnames(intermediate.value.matrix)<-c("input.global.ranks.orig","input.var.probit", - 1:6,"ID.seq.real.orig") - - - -dim(intermediate.value.matrix) -utils::head(intermediate.value.matrix) -utils::tail(intermediate.value.matrix) - - -rank.intermediate.value.matrix<-matrix(NA,ncol=8,nrow=numsubs) - - - -for(k in 1:8) -{ - rank.intermediate.value.matrix[,k]<-rank(intermediate.value.matrix[,k]) -} - -rank.intermediate.value.matrix<-cbind(rank.intermediate.value.matrix,ID.seq.real.orig) - -colnames(rank.intermediate.value.matrix)<-c("input.global.ranks.orig","input.var.probit", - 1:6,"ID.seq.real.orig") - - -message("\nRANKS IN ALL COLUMNS ABOVE SHOULD BE THE SAME\n") - -control.vector -control.value - - -#CREATE blackBox OUTPUT DF - -intermediate.value.df<-data.frame(intermediate.value.matrix) - -names(intermediate.value.df) -encrypted.global.ranks<-intermediate.value.df$"X6" - -ranks.input.global.ranks.orig<-rank(intermediate.value.df$input.global.ranks.orig) -ranks.encrypted.global.ranks<-rank(intermediate.value.df$"X6") - - -output.df<-data.frame(cbind(input.global.ranks,encrypted.global.ranks,ranks.input.global.ranks.orig,ranks.encrypted.global.ranks,ID.seq.real.orig)) - -utils::head(output.df) -utils::tail(output.df) - - - -#Sort df by magnitude of key variable -ord.by.val<-order(input.global.ranks) - -output.temp.sort.by.val<-output.df[ord.by.val,] - -utils::head(output.temp.sort.by.val) - - -ID.by.val<-1:nrow(output.temp.sort.by.val) - -output.df.sort.by.val<-data.frame(cbind(output.temp.sort.by.val,ID.by.val)) - - -utils::head(output.df.sort.by.val) -utils::tail(output.df.sort.by.val) -dim(output.df.sort.by.val) - - - -blackbox.ranks.df <- cbind(sR5.df[,c(5,1,2,3,9,6,10)],output.df.sort.by.val[,1:2]) - -colnames(blackbox.ranks.df)[3]<-"encrypted.input.var" -colnames(blackbox.ranks.df)[5]<-"global.ranks.input.from.sR5" -colnames(blackbox.ranks.df)[6]<-"is.real" -colnames(blackbox.ranks.df)[8]<-"global.ranks.after.blackbox" -colnames(blackbox.ranks.df)[9]<-"encrypted.global.ranks" - - - -utils::head(blackbox.ranks.df) - - -if(sum(round(rank(blackbox.ranks.df[,5])-rank(blackbox.ranks.df[,8]),2)==0)!=numsubs) -{ - error.message<- - paste0("FAILED: inconsistent ranking across different transformations in black box, - try a different seed. Altenatively this could reflect modification of the - clientside code which is not recommended. Finally, it can also occur - if the R session on one or more of the Armadillo/Opal data servers runs out - of memory") - stop(error.message, call. = FALSE) -}else{ - message("\nPROCESSING SUCCESSFUL, ALL RANKS AGREE FOR ALL TRANSFORMATIONS\n\n") -} - - -return(blackbox.ranks.df) - -} #END FUNCTION - -#ASSIGN -# blackBoxRanksDS - - diff --git a/R/dataFrameFillDS.R b/R/dataFrameFillDS.R deleted file mode 100644 index 7de8d805..00000000 --- a/R/dataFrameFillDS.R +++ /dev/null @@ -1,105 +0,0 @@ -#' -#' @title dataFrameFillDS -#' @description An assign function called by the clientside ds.dataFrameFill function. -#' @details This function checks if each study has all the variables compared to the other studies -#' in the analysis. If a study does not have some of the variables, the function generates those -#' variables as vectors of missing values and combines them as columns to the input data frame. -#' Then, the "complete" in terms of the columns dataframe is saved in each server with a name -#' specified by the argument \code{newobj} on the clientside. -#' @param df.name a character string representing the name of the input data frame that will be -#' filled with extra columns with missing values if a number of variables is missing from it -#' compared to the data frames of the other studies used in the analysis. -#' @param allNames.transmit unique names of all the variables that are included in the input -#' data frames from all the used datasources. -#' @param class.vect.transmit the classes of all the variables that are included in the vector -#' \code{allNames.transmit}. -#' @param levels.vec.transmit the levels of all factor variables. -#' The classes supported are 'numeric', 'integer', 'character', 'factor' and 'logical'. -#' @return Nothing is returned to the client. The generated object is written to the serverside. -#' @author Demetris Avraam for DataSHIELD Development Team -#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands -#' @export -#' -dataFrameFillDS <- function(df.name, allNames.transmit, class.vect.transmit, levels.vec.transmit){ - - data <- .loadServersideObject(df.name) - - if(!is.null(allNames.transmit)){ - allNames <- unlist(strsplit(allNames.transmit, split=",")) - }else{ - allNames <- NULL - } - - if(!is.null(class.vect.transmit)){ - class.vect <- unlist(strsplit(class.vect.transmit, split=",")) - }else{ - class.vect <- NULL - } - - if(!is.null(levels.vec.transmit)){ - levels.vec <- strsplit(levels.vec.transmit, split=" ") - levels.vec <- lapply(levels.vec, function(x){as.numeric(unlist(strsplit(x, split=",")))}) - }else{ - levels.vec <- NULL - } - - for (class.vect.index in 1:length(class.vect)){ - if (! class.vect[class.vect.index] %in% c('numeric', 'integer', 'character', 'factor' , 'logical')){ - stop(paste0("Unexpected missing class specified: '", class.vect[class.vect.index], "'"), call.=FALSE) - } - } - - study.colnames <- colnames(data) - missingIndex <- which(!(allNames %in% study.colnames)) - - missingFactorsIndex <- which(class.vect=='factor') - if(!is.null(levels.vec)){ - missingFactorsIndex.vec <- rep(NA,length(allNames)) - for (i in 1:length(missingFactorsIndex.vec)){ - if(class.vect[[i]]=='factor'){ - missingFactorsIndex.vec[i] <- i - }else{ - missingFactorsIndex.vec[i] <- NA - } - } - nonNA.missingFactorsIndex <- length(missingFactorsIndex) - - Factorslevels <- as.list(rep(NA, length(allNames))) - for (i in 1:nonNA.missingFactorsIndex){ - Factorslevels[[missingFactorsIndex[i]]] <- levels.vec[[i]] - } - } - - if (length(missingIndex) > 0){ - missingVars <- allNames[missingIndex] - missingClass <- class.vect[missingIndex] - numRows <- nrow(data) - numCols <- length(missingVars) - - mat.new <- matrix(NA, ncol=numCols, nrow=numRows) - - df.new <- data.frame(x=mat.new, row.names=NULL) - colnames(df.new) <- missingVars - - funs <- sapply(paste0("as.", missingClass), match.fun) - df.new[] <- Map(function(dd, f) f(as.character(dd)), df.new, funs) - - if(length(which(missingClass=='factor')) > 0){ - missingLevels <- Factorslevels[missingIndex] - factor.index <- which(missingClass=='factor') - for(i in 1:length(factor.index)){ - levels(df.new[,factor.index[i]]) <- missingLevels[[factor.index[i]]] - } - } - - df.out <- cbind(data, df.new) - }else{ - df.out <- data - } - - return(df.out) - -} -# ASSIGN FUNCTION -# dataFrameFillDS - diff --git a/R/extractQuantilesDS1.R b/R/extractQuantilesDS1.R deleted file mode 100644 index d7aeef49..00000000 --- a/R/extractQuantilesDS1.R +++ /dev/null @@ -1,134 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' and use of these ranks to estimate global quantiles across all studies -#' @description identify the global values of V2BR (i.e. the values across all -#' studies) that relate to a set of quantiles to be evaluated. -#' @details Severside aggregate function called by ds.extractQuantiles via -#' ds.ranksSecure. As well as estimating the key values of V2BR that correspond -#' to the selected quantiles, this function also implements a disclosure control -#' trap. If the ratio of the total number of all observations across all studies -#' divided by the number of quantile values to be estimated is less than or -#' equal to nfilter.subset (which specifies the minimum size of a subset) the -#' process stops and an error message is returned suggesting that you might -#' try selecting a narrower range of quantiles with less quantile values to be -#' estimated as specified by the argument of the -#' function ds.ranksSecure. For more details about the cluster of functions that -#' collectively enable secure global ranking and estimation of global quantiles -#' see the associated document entitled "secure.global.ranking.docx" -#' @param extract.quantiles one of a restricted set of character strings that -#' fix the set of quantile values for which the corresponding values across -#' all studies are to be estimated. For more details -#' see the associated document entitled "secure.global.ranking.docx", the -#' header for ds.ranksSecure and ds.extractQuantiles functions. -#' The value of this argument is set in choosing the value of the argument -#' in ds.ranksSecure. -#' @param extract.summary.output.ranks.df character string specifying optional -#' name for the data.frame written to the serverside on each data source that -#' contains 5 of the key output variables from the ranking procedure pertaining -#' to that particular data source. This data frame represents the key source of -#' information - including global ranks - that determines the values of V2BR -#' that are identified as corresponding to the particular set of quantiles to -#' be estimated as specified by the argument of -#' function ds.ranksSecure (and the argument of -#' ds.extractQuantiles). -#' @return as a first step in creating the vector of values of values of V2BR -#' that correspond to each quantile value, extractQuantilesDS1 identifies the -#' two closest quantile values across all studies that span each key quantile -#' value. These are saved as the data frame "closest.bounds.df" on the -#' clientside and then saved on the serverside by ds.dmtC2S into the data frame -#' "global.bounds.df". Also if the number of observations across all studies is -#' too small, and a disclosure risk exists if the final.quantile.vector is made -#' available via the client, this function stops the processing and returns a -#' warning/error message. -#' @author Paul Burton 11th November, 2021 -#' @export -extractQuantilesDS1 <- function(extract.quantiles,extract.summary.output.ranks.df){ #START FUNC - - - ############################################################# - #MODULE 1: CAPTURE THE nfilter SETTINGS # - thr<-dsBase::listDisclosureSettingsDS() # - nfilter.tab <- as.numeric(thr$nfilter.tab) # - #nfilter.glm <- as.numeric(thr$nfilter.glm) # - nfilter.subset <- as.numeric(thr$nfilter.subset) # - #nfilter.string <- as.numeric(thr$nfilter.string) # - #nfilter.stringShort <- as.numeric(thr$nfilter.stringShort) # - #nfilter.kNN <- as.numeric(thr$nfilter.kNN) # - #nfilter.noise <- as.numeric(thr$nfilter.noise) # - #nfilter.levels <- as.numeric(thr$nfilter.levels) # - ############################################################# - - ############################################# - - extract.summary.ranks.df <- eval(parse(text=extract.summary.output.ranks.df), envir = parent.frame()) - - #Specify quantiles to evaluate - if(extract.quantiles=="0.025-0.975"){ - evaluation.quantiles<-c(0.025,0.05,0.10,0.20,0.25,0.30,0.3333,0.40,0.50,0.60,0.6667,0.70,0.75,0.80,0.90,0.95,0.975) - } - if(extract.quantiles=="0.05-0.95"){ - evaluation.quantiles<-c(0.05,0.10,0.20,0.25,0.30,0.3333,0.40,0.50,0.60,0.6667,0.70,0.75,0.80,0.90,0.95) - } - if(extract.quantiles=="0.10-0.90"){ - evaluation.quantiles<-c(0.10,0.20,0.25,0.30,0.3333,0.40,0.50,0.60,0.6667,0.70,0.75,0.80,0.90) - } - if(extract.quantiles=="0.20-0.80"){ - evaluation.quantiles<-c(0.20,0.25,0.30,0.3333,0.40,0.50,0.60,0.6667,0.70,0.75,0.80) - } - if(extract.quantiles=="quartiles"){ - evaluation.quantiles<-c(0.25,0.50,0.75) - } - if(extract.quantiles=="median"){ - evaluation.quantiles<-c(0.50) - } - - - numvals<-length(evaluation.quantiles) - numsubs.in.study<-nrow(extract.summary.ranks.df) - - #calculate total number of real data observations in variable to be ranked - #across all studies to prime disclosure control - - #Identify specific observations defining chosen evaluation quantiles - quants<-extract.summary.ranks.df$final.quantiles.global - ranks<-extract.summary.ranks.df$final.ranks.global - numsubs.real<-max(ranks/quants) - - if((numsubs.real/numvals)<=nfilter.tab){ - error.message<- - paste0("FAILED: the total number of observations across all studies is so small that there is a disclosure risk in releasing the list of quantiles requested. You could change the quantiles.for.estimation argument to request a narrower range of quantiles to be be estimated.") - stop(error.message, call. = FALSE) - } - - - lower.bound<-rep(NA,numvals) - upper.bound<-rep(NA,numvals) - - num.real.all.studies<-max() - for(qq in 1:numvals){ - disclosure.risk<-FALSE - if(length(quants<=evaluation.quantiles[qq])=evaluation.quantiles[qq])=evaluation.quantiles[qq]]) - - } - -bounds.df<-data.frame(evaluation.quantiles,lower.bound,upper.bound) - -colnames(bounds.df)<-c("evaluation.quantiles","lower.bound","upper.bound") - -return(bounds.df) -} - -#AGGREGATE -# extractQuantilesDS1 - - - - diff --git a/R/extractQuantilesDS2.R b/R/extractQuantilesDS2.R deleted file mode 100644 index 7b8ee593..00000000 --- a/R/extractQuantilesDS2.R +++ /dev/null @@ -1,95 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' and use of these ranks to estimate global quantiles across all studies -#' @description identify the global values of V2BR (i.e. the values across all -#' studies) that relate to a set of quantiles to be evaluated. -#' @details Severside aggregate function called by ds.extractQuantiles via -#' ds.ranksSecure. This takes the "global.bounds.df" data frame saved on the -#' serverside following construction by extractQuantilesDS1. This -#' data frame includes the two quantile values that most closely span each -#' quartile value to be estimated. If either of the values had been the correct -#' value for a given quantile, both the bounding values would have taken that -#' value in global.bounds.df. This is because the upper bound was defined as -#' the lowest value that was equal to or greater than the true value for that -#' quantile while the lower bound was defined as the highest value that was -#' equal to or lower than the true value. Next, the function extractQuantileDS2 -#' goes round study by study to identify the values of V2BR that actually -#' correspond to each of the spanning values around each quantile. Then the -#' function goes quantile by quantile and estimates the mean of the -#' two values of V2BR that correspond to the the spanning quantiles. If these -#' two values are the same it means that that value of V2BR is the -#' "true" value and the mean of two (or potentially several) instances of that -#' value is inevitably also equal to that true value. If the upper and lower -#' bounding values of V2BR differ, neither can be the precisely correct single -#' value of V2BR for that quantile (see above for explanation) and so the mean -#' of the two is a reasonable interpolated summary. -#' @param extract.summary.output.ranks.df character string specifies an optional -#' name for the data.frame written to the serverside on each data source that -#' contains 5 of the key output variables from the ranking procedure pertaining -#' to that particular data source. This data frame represents the key source of -#' information - including global ranks - that determines the values of V2BR -#' that are identified as corresponding to the particular set of quantiles to -#' be estimated as specified by the argument of -#' function ds.ranksSecure (and the argument of -#' ds.extractQuantiles). -#' @return the single value of V2BR which best corresponds to each key quantile -#' value to be estimated as specified by the argument -#' A data frame (final.quantile.df)summarising the results of this analysis -#' is written to the clientside. This data frame consists of two vectors. The -#' first is named "evaluation.quantiles". It lists the full set of quantiles -#' you have requested for evaluation as specified by the argument -#' "quantiles.for.estimation" The second vector which is called -#' "final.quantile.vector" details the values of V2BR that correspond to the -#' the key quantiles listed in vector 1. -#' @author Paul Burton 11th November, 2021 -#' @export -extractQuantilesDS2 <- function(extract.summary.output.ranks.df){ #START FUNC - - - ############################################################# - #MODULE 1: CAPTURE THE nfilter SETTINGS # - thr<-dsBase::listDisclosureSettingsDS() # - #nfilter.tab <- as.numeric(thr$nfilter.tab) # - #nfilter.glm <- as.numeric(thr$nfilter.glm) # - nfilter.subset <- as.numeric(thr$nfilter.subset) # - #nfilter.string <- as.numeric(thr$nfilter.string) # - #nfilter.stringShort <- as.numeric(thr$nfilter.stringShort) # - #nfilter.kNN <- as.numeric(thr$nfilter.kNN) # - #nfilter.noise <- as.numeric(thr$nfilter.noise) # - #nfilter.levels <- as.numeric(thr$nfilter.levels) # - ############################################################# - -extract.summary.ranks.df2 <- eval(parse(text=extract.summary.output.ranks.df), envir = parent.frame()) -numsubs<-nrow(extract.summary.ranks.df2) -numvals<-length(global.bounds.df$evaluation.quantiles) - - -relevant.study.specific.input.values.lower<-rep(NA,numvals) -relevant.study.specific.input.values.upper<-rep(NA,numvals) - -for(ww in 1:numvals){ - if(sum(extract.summary.ranks.df2$final.quantiles.global==global.bounds.df$lower.bound.vector[ww])>0) - { - relevant.study.specific.input.values.lower[ww]<- - mean(extract.summary.ranks.df2$input.var.real.orig[extract.summary.ranks.df2$final.quantiles.global - ==global.bounds.df$lower.bound.vector[ww]]) - } - - if(sum(extract.summary.ranks.df2$final.quantiles.global==global.bounds.df$upper.bound.vector[ww])>0) - { - relevant.study.specific.input.values.upper[ww]<- - mean(extract.summary.ranks.df2$input.var.real.orig[extract.summary.ranks.df2$final.quantiles.global - ==global.bounds.df$upper.bound.vector[ww]]) - } -} - - - return(list(relevant.study.specific.input.values.lower=relevant.study.specific.input.values.lower, - relevant.study.specific.input.values.upper=relevant.study.specific.input.values.upper)) -} - -#AGGREGATE -# extractQuantilesDS2 - - - - diff --git a/R/messageDS.R b/R/messageDS.R deleted file mode 100644 index a148ea10..00000000 --- a/R/messageDS.R +++ /dev/null @@ -1,99 +0,0 @@ -#' -#' @title messageDS -#' @description This function allows for error messages arising from the -#' running of a server-side assign function to be returned to the client-side -#' @details Errors arising from aggregate server-side functions can be returned -#' directly to the client-side. But this is not possible for server-side assign -#' functions because they are designed specifically to write objects to the -#' server-side and to return no meaningful information to the client-side. -#' Otherwise, users may be able to use assign functions to return disclosive -#' output to the client-side. ds.message calls messageDS which looks -#' specifically for an object called $serversideMessage in a designated list on -#' the server-side. Server-side functions from which error messages are to be made -#' available, are designed to be able to write the designated error message to -#' the $serversideMessage object into the list that is saved on the server-side -#' as the primary output of that function. So only valid server-side functions of -#' DataSHIELD can write a $studysideMessage, and as additional protection against -#' unexpected ways that someone may try to get round this limitation, a -#' $studysideMessage is a string that cannot exceed a length of nfilter.string -#' a default of 80 characters. -#' @param message.object.name is a character string, containing the name of the list containing the -#' message. See the header of the client-side function ds.message for more details. -#' @return a list object from each study, containing whatever message has been written by -#' DataSHIELD into $studysideMessage. -#' @author Burton PR -#' @export -#' -messageDS <- function(message.object.name){ - -############################################################# -#MODULE 1: CAPTURE THE nfilter SETTINGS # -thr<-dsBase::listDisclosureSettingsDS() # -#nfilter.tab<-as.numeric(thr$nfilter.tab) # -#nfilter.glm<-as.numeric(thr$nfilter.glm) # -nfilter.subset<-as.numeric(thr$nfilter.subset) # -nfilter.string<-as.numeric(thr$nfilter.string) # -nfilter.stringShort<-as.numeric(thr$nfilter.stringShort) # -nfilter.kNN<-as.numeric(thr$nfilter.kNN) # -############################################################# - -#TEST IF message.object.name EXISTS AS AN OBJECT ON SERVERSIDE -#exists() must have message.object.name explicitly specified in inverted commas. -#NOT just the name of a character class object representing the name without -#inverted comma - -A1.exists.text<-paste0("exists('",message.object.name,"')") - -boole.A1.exists<-eval(parse(text=A1.exists.text), envir = parent.frame()) - - - - -if(!boole.A1.exists) { -out.obj<-"Error: the object does not exist in this datasource" -return(out.obj) -} - - - -#IF message.object.name EXISTS, CHECK WHETHER IT CURRENTLY CONTAINS A studysideMessage - -if(boole.A1.exists){ -message.object.name.active<-eval(parse(text=message.object.name), envir = parent.frame()) - - - -#CASE WHERE PRIMARY OUTPUT OBJECT IS A LIST -if("list" %in% class(message.object.name.active)){ - -#A LIST WITH NAMES - could be a studysideMessage - if(!is.null(names(message.object.name.active))) { - s.message.available<-FALSE - for(j in 1:length(names(message.object.name.active))){ - if(names(message.object.name.active)[j]=="studysideMessage"){ - s.message.available<-TRUE - out.obj<-"NOT ALL OK: there are studysideMessage(s) on this datasource" - } - } - if(!s.message.available){ - out.obj<-"ALL OK: there are no studysideMessage(s) on this datasource" - } - } - -#A LIST WITHOUT NAMES - if(is.null(names(message.object.name.active))) { - out.obj<-"Outcome object is a list without names. So a studysideMessage may be hidden. Please check output is OK" - } - -}else{ -#CASE WHERE PRIMARY OUTPUT IS AN OBJECT OF A CLASS OTHER THAN LIST - output object created OK and so no studysideMessage - out.obj<-"ALL OK: there are no studysideMessage(s) on this datasource" - } - - } - - return(MESSAGE=out.obj) - -} -#AGGREGATE FUNCTION -# messageDS diff --git a/R/minMaxRandDS.R b/R/minMaxRandDS.R deleted file mode 100644 index 64caf7ae..00000000 --- a/R/minMaxRandDS.R +++ /dev/null @@ -1,76 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description Creates a minimum value that is more negative, and less positive -#' than any real value in V2BR and a maximum value that is more positive and -#' less negative than any value of V2BR. -#' @details Severside aggregate function called by ds.ranksSecure. The minimum -#' and maximum values it creates are used to replace missing values -#' (NAs) in V2BR if the argument e is set to "NA.low" or "NA.hi" -#' respectively. For more details about the cluster of functions that -#' collectively enable secure global ranking and estimation of global quantiles -#' see the associated document entitled "secure.global.ranking.docx". Also -#' see the header file for ds.ranksSecure -#' @param input.var.name a character string specifying the name of V2BR. This -#' argument is set by the argument with the same name in the clientside function -#' ds.ranksSecure -#' @return the data frame objects containing the global ranks and quantiles. -#' For more details see the associated document entitled -#' "secure.global.ranking.docx" -#' @author Paul Burton 9th November, 2021 -#' @export -#' -minMaxRandDS <- function(input.var.name){ #START FUNC - - # back-up current .Random.seed and revert on.exit - if (exists(x = ".Random.seed", envir = globalenv())) { - assign(x = ".old_seed", value = .Random.seed, envir = parent.frame()); - on.exit({ assign(x = ".Random.seed", value = parent.frame()$.old_seed, envir = globalenv()); remove(".old_seed", envir = parent.frame()) }, add = TRUE) - } else - on.exit(if (exists(x = ".Random.seed", envir = globalenv())) remove(".Random.seed", envir = globalenv()), add = TRUE) - - input.var <- eval(parse(text=input.var.name), envir = parent.frame()) - - #create seed that is unknown and cannot be repeated - set.seed(NULL) - - mult.created<-0 - while(mult.created==0){ - rand.mult.temp<-stats::rnorm(1,1.5,0.5) - if(rand.mult.temp>1.2){ - rand.mult<-rand.mult.temp - mult.created<-1 - } - } - rand.max<-max(input.var,na.rm=TRUE) - rand.min<-min(input.var,na.rm=TRUE) - - if(rand.max<0){ - rand.max<-(-rand.max)+1 - } - - if(rand.max==0){ - rand.max<-1 - } - - rand.max<-rand.max*rand.mult - - if(rand.min>0){ - rand.min<-(-rand.min)-1 - } - - if(rand.min==0){ - rand.min<-(-1) - } - - rand.min<-rand.min*rand.mult - -rand.min.max<-c(rand.min,rand.max) - -return(rand.min.max) - -} -#AGGREGATE -# minMaxRandDS - - - - diff --git a/R/ranksSecureDS1.R b/R/ranksSecureDS1.R deleted file mode 100644 index f24a4318..00000000 --- a/R/ranksSecureDS1.R +++ /dev/null @@ -1,34 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description takes key non-disclosive components of the serverside data frame -#' blackbox.output.df over to the clientside to enable global ranking. -#' @details Severside aggregate function called by ds.ranksSecure. The -#' non-disclosive components of blackbox.output.df that are transmitted to the -#' clientside are: (1) final values of the "combined real+pseudo data vector" -#' after all seven rounds of encryption have been completed; (2) a set of -#' sequential IDs allocated after sorting the "combined real+pseudo data vector" -#' by value (in ascending order). This allows later re-linkage of values back on -#' the serverside and confirmation that that linkage is correct. For more -#' details about the cluster of functions that collectively enable secure global -#' ranking and estimation of global quantiles see the associated document -#' entitled "secure.global.ranking.docx". Also see the header file -#' for ds.ranksSecure -#' @return the non-disclosive elements of blackbox.output.df (see details) -#' on the serverside as a data frame object (called blackbox.output) -#' on the clientside. After processing to create the global ranks across all -#' studies, this is returned to the serverside as the data frame sR4.df using -#' the clientside function ds.dmtC2S -#' @author Paul Burton 9th November, 2021 -#' @export -ranksSecureDS1 <- function(){ #START FUNC - -sR2.df<-blackbox.output.df[,c(2,7)] - -return(sR2.df) -} - -#AGGREGATE -# ranksSecureDS1 - - - - diff --git a/R/ranksSecureDS2.R b/R/ranksSecureDS2.R deleted file mode 100644 index 5a4acc5e..00000000 --- a/R/ranksSecureDS2.R +++ /dev/null @@ -1,111 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description Checks that the data frame produced in creating the initial -#' global ranks (ranks based on real and pseudo-data after the running of -#' blackBoxDS)has the correct dimensions and order as the serverside data frames -#' to which it will now be appended. If either the number of rows or the order -#' of the rows are inconsistent with the pre-existing data frames on the -#' serverside an error message is returned and the processing stops. Then -#' strips out the pseudo-data leaving solely the global ranks based just on -#' the real data -#' @details Severside assign function called by ds.ranksSecure. -#' It works on the on the output created by serverside function ranksSecureDS1 -#' and saved on the serverside in data frame sR4.df by ds.dmtC2S. Having -#' checked QA it strips out all rows corresponding to pseudo-data. The resultant -#' data frame contains the following vectors: (1) the fully encrypted V2BR -#' (after application of blackBoxDS);(2) "ID.by.val" the sequential -#' ID associated with the "combined real+pseudo data vector" sorted by -#' value (ascending); (3) "studyid", a vector consisting solely of value n in -#' the nth study; (4) "global.rank" the vector containing global ranks created by -#' the clientside code in ds.ranksSecure after ranksSecureDS1 is called and up -#' to the point where ds.dmtC2S sends sR4.df to the serverside. For more -#' details about the cluster of functions that collectively enable secure global -#' ranking and estimation of global quantiles see the associated document -#' entitled "secure.global.ranking.docx". Also see the header file -#' for ds.ranksSecure -#' @return creates a new data frame sR5.df on the serverside containing -#' solely the real data and including key elements needed for next stage of the -#' ranking process. Most crucially these include "global.rank" and "ID.by.val" -#' sorted in ascending order of the magnitude of V2BR -#' @author Paul Burton 9th November, 2021 -#' @export -ranksSecureDS2 <- function(){ #START FUNC - -########################################################################## -########################################################################## -##LOCAL CODE SET UP TO CHECK ERROR TRAPS DURING DEVELOPMENT -##THIS CODE TESTED AND PASSED 11/10/21 -# -##FIRST RUN QA.ranksSecure -# -##THEN RUN THIS FUNCTION WITH NEITHER TRAP TRIGGERED (ie FROM #generic ..) -##SHOULD BE NO ERROR MESSAGES -# -##THEN RUN WITH JUST TRAP 2 TRIGGERED (i.e. FROM #trap 2) -##SHOULD JUST BE TRAP 2 ERROR MESSAGE -# -##THEN RUN QA.ranksSecure AGAIN -# -##THEN RUN WITH JUST TRAP 1 TRIGGERED (i.e. FROM #trap 1 BUT NOT #trap 2) -##SHOULD JUST BE TRAP 2 ERROR MESSAGE -# -##trap 1 -## bodf.1<-bodf.1[2:nrow(bodf.1),] -# -##trap 2 -## ord10<-order(bodf.1[,5]) -## bodf.1<-bodf.1[ord10,] -# -##generic set up no traps triggered -# -#sR4.df<-R.sR4.df.2 -#blackbox.output.df<-bodf.2 -########################################################################## -########################################################################## - -#check key data frames have the same number of rows and are in the same order -df.equivalent<-1 - -if(nrow(blackbox.output.df)!=nrow(sR4.df)){ - df.equivalent<-0 - } -if(df.equivalent==0){ -error.message<- - paste0("FAILED: in at least one study, data frame before global ranking has - a different number of rows to data.frame after global ranking. Please explore - and correct whatever may have caused this") -stop(error.message, call. = FALSE) -} - -if(sum(round(abs(blackbox.output.df$encrypted.var-sR4.df$encrypted.var),2))>0){ - df.equivalent<-0 -} - -if(df.equivalent==0){ - error.message<- - paste0("FAILED: in at least one study, data frame before global ranking is - in a different order to the data.frame after global ranking. Please explore - and correct whatever may have caused this") - stop(error.message, call. = FALSE) -} - - -sR5.df.temp<-data.frame(cbind(blackbox.output.df,sR4.df[,c(1,4,3)])) - -sR5.df.real<-sR5.df.temp[blackbox.output.df$is.real==1,] - -colnames(sR5.df.real)<-colnames(sR5.df.temp) - -colnames(sR5.df.real)[1]<-"input.var.real.orig" -colnames(sR5.df.real)[3]<-"ranks.input.var.real.orig" -colnames(sR5.df.real)[5]<-"ID.seq.real.orig" - - -return(sR5.df.real) -} - -#ASSIGN -# ranksSecureDS2 - - - - diff --git a/R/ranksSecureDS3.R b/R/ranksSecureDS3.R deleted file mode 100644 index 2d20d7fe..00000000 --- a/R/ranksSecureDS3.R +++ /dev/null @@ -1,46 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description takes key non-disclosive components of the serverside data frame -#' blackbox.ranks.df over to the clientside to enable global re-ranking of the -#' global ranks just applying to the real data (not the pseudo-data). -#' @details Severside aggregate function called by ds.ranksSecure. The -#' non-disclosive components of blackbox.ranks.df that are transmitted to the -#' clientside are: (1) final values of the encrypted global ranks vector -#' after all seven rounds of encryption have been completed; (2) a set of -#' sequential IDs allocated to the global ranks vector in each study in their -#' current order based on increasing value of V2BR. This allows later re-linkage -#' of values back on the serverside and confirmation that that linkage is -#' correct. (3) a studyid vector with all values n in the nth study. This -#' facilitates data management on the serverside during the global ranking -#' of global ranks. For more details about the cluster of functions that -#' collectively enable secure global ranking and estimation of global quantiles -#' see the associated document entitled "secure.global.ranking.docx". Also see -#' the header file for ds.ranksSecure -#' @return the non-disclosive elements of blackbox.output.df (see details) -#' on the serverside as a data frame object (called sR6.df) -#' on the clientside. After processing within ds.ranksSecure to create the -#' global ranks and global quantiles (of real data only) across all studies, -#' this is returned to the serverside as data frame "global.ranks.quantiles.df" -#' using the clientside function ds.dmtC2S. To illustrate the difference between -#' ranks and quantiles, if there are a total of 1000 original real observations -#' across all studies and one particular observation has the rank 250, it will -#' have quantile value 0.25 (i.e. 25%th value in the overall data ordered by -#' increasing value). Both ranks and quantiles can have ties. For more details -#' about the cluster of functions that collectively enable secure global ranking -#' and estimation of global quantiles see the associated document entitled -#' "secure.global.ranking.docx". Also see the header file for ds.ranksSecure -#' @author Paul Burton 9th November, 2021 -#' @export -ranksSecureDS3 <- function(){ #START FUNC - -sR6.df<-data.frame(cbind(blackbox.ranks.df[,9],1:nrow(blackbox.ranks.df),blackbox.ranks.df[,7])) -colnames(sR6.df)<-c("encrypted.ranks","ID.real.by.val","studyid") - -return(sR6.df) -} - -#AGGREGATE -# ranksSecureDS3 - - - - diff --git a/R/ranksSecureDS4.R b/R/ranksSecureDS4.R deleted file mode 100644 index 1bf3159d..00000000 --- a/R/ranksSecureDS4.R +++ /dev/null @@ -1,108 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description Creates a data frame "sR8.df" by cbinding the data frame -#' "blackBox.ranks.df" with the global ranks and global quantiles vectors in -#' "global.ranks.quantiles.df". Performs QA on this matrix and orders the -#' sR8.df data frame according to the argument in ds.ranksSecure -#' @details Severside assign function called by ds.ranksSecure. -#' Creates a data frame "sR8.df" by cbinding the data frame "blackBox.ranks.df" -#' with the global ranks and global quantiles vectors in -#' "global.ranks.quantiles.df". Checks that all components of sR8.df have the -#' correct dimensions and are consistent in their ordering. If either the -#' number of rows or the order of the rows are inconsistent with those in -#' "blackBox.ranks.df" an error message is returned and the processing stops. -#' If sR8.df passes all QA tests it is written to the serverside as a data -#' frame with its name identified by the argument in -#' ds.ranksSecure. If that argument is NULL or unspecified the data frame -#' is called "main.ranks.df". The ranksSecureDS4 function also orders the -#' combined data frame () in one of two ways: if -#' the argument in ds.ranksSecure is set to "ID.orig" the -#' combined data frame is ordered in the same way as the original V2BR vector; -#' if the argument is set to vals.orig" the combined data frame -#' is ordered by the magnitude of the values of V2BR (ascending). Having -#' created the data frame () in this manner it can now be -#' directly cbinded to either the V2BR vector itself or to a data frame, tibble -#' or matrix containing V2BR (assuming they are also in the order corresponding -#' to the argument ) and this combined object can be used as the -#' basis of analysis based on the global ranks or quantiles including a range -#' of types of non-parametric analysis. -#' @param ranks.sort.by a character string taking two possible values. These -#' are "ID.orig" and "vals.orig". These define the order in which the -#' output.ranks.df and summary.output.ranks.df data frames are presented. This -#' argument is set by the argument with the same name in ds.ranksSecure. -#' Default value is "ID.orig". -#' @return Creates the data frame identified by the name given by the argument -#' () of the ds.ranksSecure function and writes it to the -#' serverside. If the argument is NULL or unspecified the -#' output data frame is called "main.ranks.df". The data frame is ordered -#' according to the argument in ds.ranksSecure. -#' @author Paul Burton 9th November, 2021 -#' @export -ranksSecureDS4 <- function(ranks.sort.by){ #START FUNC - -sR8.df<-cbind(blackbox.ranks.df,global.ranks.quantiles.df$real.ranks.global,global.ranks.quantiles.df$real.quantiles.global) -colnames(sR8.df)[ncol(sR8.df)-1]<-"final.ranks.global" -colnames(sR8.df)[ncol(sR8.df)]<-"final.quantiles.global" - -ord.by.ID.orig<-order(sR8.df$ID.seq.real.orig) - -if(ranks.sort.by!="ID.orig" && ranks.sort.by!="vals.orig"){ - error.message<- - paste0("FAILED: ranks.sort.by must be specified as either 'ID.orig' or 'vals.orig'") - stop(error.message, call. = FALSE) -} - -if(ranks.sort.by=="ID.orig") -{ -sR8.df<-sR8.df[ord.by.ID.orig,] -} - -if(ranks.sort.by=="vals.orig") -{ - sR8.df<-sR8.df -} - -lenx<-length(sR8.df$encrypted.input.var) - -if((length(sR8.df$global.ranks.input.from.sR5)!=lenx)|| - (length(sR8.df$global.ranks.after.blackbox)!=lenx)|| - (length(sR8.df$final.ranks.global)!=lenx)|| - (length(sR8.df$final.quantiles.global)!=lenx)) -{ - error.message<- - paste0("FAILED: ranking components of different lengths. This could reflect - modification of the clientside code which is not recommended. It can - also occur if the R session on one or more of the Armadillo/Opal data servers - runs out of memory") - stop(error.message, call. = FALSE) -} - -ranks.consistent<-1 - -if(sum(round(rank(sR8.df$global.ranks.input.from.sR5)-rank(sR8.df$global.ranks.after.blackbox),2)==0)!=lenx){ - ranks.consistent<-0 -} - -if(sum(round(rank(sR8.df$global.ranks.input.from.sR5)-rank(sR8.df$final.ranks.global),2)==0)!=lenx){ -ranks.consistent<-0 -} - -if(sum(round(rank(sR8.df$global.ranks.input.from.sR5)-rank(sR8.df$final.quantiles.global),2)==0)!=lenx){ - ranks.consistent<-0 -} - -if(ranks.consistent==0) -{ - error.message<- - paste0("FAILED: inconsistent ranking across different components of ranking matrix, - try a different seed. Altenatively this could reflect modification of the - clientside code which is not recommended. Finally, it can also occur - if the R session on one or more of the Armadillo/Opal data servers runs out - of memory") - stop(error.message, call. = FALSE) -} - -return(sR8.df) -} - -#ASSIGN -# ranksSecureDS4 diff --git a/R/ranksSecureDS5.R b/R/ranksSecureDS5.R deleted file mode 100644 index eafc6681..00000000 --- a/R/ranksSecureDS5.R +++ /dev/null @@ -1,53 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description Summarises the serverside data frame written by ranksSecureDS4 -#' which is identified by the name given by the argument () of -#' the ds.ranksSecure function to produce a new output data frame containing -#' only 5 key variables. -#' @details Serverside assign function called by clientside function -#' ds.ranksSecure. Takes the serverside data frame written by ranksSecureDS4 -#' which is identified by the name given by the argument () of -#' the ds.ranksSecure function. This holds 11 vectors including the final -#' global ranks across all studies and final global quantiles. The data frame -#' is ordered according to the argument in ds.ranksSecure. The -#' ranksSecureDS5 function then extracts 5 key vectors from the larger data -#' frame to produce a summary data frame that is given a name specified by -#' the argument () the ds.ranksSecure function. -#' This data frame includes the following components: (1) The values of a -#' sequential ID variable (ID.seq.real.orig) created to lie alongside the -#' original V2BR vector in the same order as that vector was itself ordered. -#' These ID values therefore reflect which row in the original data corresponds -#' to a given row in the output. If the argument in -#' ds.ranksSecure is set to "ID.orig" the values of the ID.seq.real.orig vector -#' in the output data frame simply run sequentially from 1 to N where N is the -#' number of individuals in the corresponding study. If is -#' set to "vals.orig" the values of the ID.seq.real.orig vector will be -#' determined by the magnitude of the corresponding V2BR value and will -#' appear to be ordered in a haphazard manner; (2) the original values of V2BR; -#' (3) the global ranks corresponding to the original values in V2BR, with ties -#' reflected appropriately; (4) the global quantiles corresponding to the -#' original values in V2BR, with ties reflected appropriately; (5) a studyid -#' vector in which all elements take the value n in the nth study. -#' @param output.ranks.df a character string which specifies an optional name -#' for the data.frame written to the serverside on each data source that -#' contains 11 of the key output variables from the ranking procedure pertaining -#' to that particular data source. This argument is set by the argument with -#' the same name in ds.ranksSecure. -#' @return extracts 5 key vectors from the larger data frame created by -#' ranksSecureDS4 to produce a summary data frame that is written to the -#' serverside. It is given a name specified by the argument. -#' @author Paul Burton 9th November, 2021 -#' @export -ranksSecureDS5 <- function(output.ranks.df){ #START FUNC -final.summary.df <- eval(parse(text=output.ranks.df), envir = parent.frame()) - - -final.summary.df<-final.summary.df[,c(1,2,10,11,7)] - -return(final.summary.df) -} - -#ASSIGN -# ranksSecureDS5 - - - diff --git a/R/recodeLevelsDS.R b/R/recodeLevelsDS.R deleted file mode 100644 index b4c47998..00000000 --- a/R/recodeLevelsDS.R +++ /dev/null @@ -1,29 +0,0 @@ -#' -#' @title Recodes the levels of a categorical variables -#' @description The functions uses the input factor and generates a new factor -#' with new levels. -#' @param x a factor vector -#' @param classes a character vector the levels of the newt factor vector -#' @return a factor vector with the new levels -#' @author Gaye, A. -#' @export -#' -recodeLevelsDS <- function (x=NULL, classes=NULL){ - - # Check Permissive Privacy Control Level. - dsBase::checkPermissivePrivacyControlLevel(c('permissive', 'banana', 'carrot')) - - # check if the input vector is valid (i.e. meets DataSHIELD criteria) - check <- .checkDisclosureSize(x) - - if(check){ - # generate the new variable with the specified levels - levels(x) <- classes - }else{ - # generate the new variable with the specified levels but with missing values - x[1:length(x)] <- NA - } - - return(x) - -} diff --git a/R/subsetByClassDS.R b/R/subsetByClassDS.R deleted file mode 100644 index e4063482..00000000 --- a/R/subsetByClassDS.R +++ /dev/null @@ -1,79 +0,0 @@ -#' -#' @title Breaks down a dataframe or a factor into its sub-classes -#' @description The function takes a categorical vector or dataframe as input and generates subset(s) -#' vectors or dataframes for each category. Subsets are considered invalid if they hold between 1 and -#' 4 observations. -#' @details If the input data object is a dataframe it is possible to specify the variables -#' to subset on. If a subset is not 'valid' all its the values are reported as missing (i.e. NA), -#' the name of the subsets is labelled as '_INVALID'. If no variables are specified to subset on, -#' the dataframe will be subset on each of its factor variables. -#' And if none of the columns holds a factor variable a message is issued as output. A message is also -#' issued as output if the input vector is not of type factor. -#' @param data a string character, the name of the dataframe or the factor vector -#' @param variables a vector of string characters, the names of the the variables to subset on. -#' @return a list which contains the subsetted datasets -#' @author Gaye, A. -#' @export -#' -subsetByClassDS <- function(data=NULL, variables=NULL){ - - # Check Permissive Privacy Control Level. - dsBase::checkPermissivePrivacyControlLevel(c('permissive', 'banana', 'carrot')) - - # this filter sets the minimum number of observations that are allowed - - ############################################################# - # MODULE 1: CAPTURE THE nfilter SETTINGS - thr <- dsBase::listDisclosureSettingsDS() - #nfilter.tab <- as.numeric(thr$nfilter.tab) - #nfilter.glm <- as.numeric(thr$nfilter.glm) - nfilter.subset <- as.numeric(thr$nfilter.subset) - #nfilter.string <- as.numeric(thr$nfilter.string) - ############################################################# - - # evaluate the string passed on to the function as an object - input <- eval(parse(text=data), envir = parent.frame()) - - # subsetting is carried out only of the input is of type factor or data.frame - if(is.factor(input)){ - # call the internal function that generates subsets if the input is a factor variable - Dname <- extract(data)[[2]] - output <- subsetByClassHelper1(input, Dname, nfilter.subset) - }else{ - # get the names of the variables on the dataset - varnames <- colnames(input) - - # set the number of loops depending on the number of variables specified - # if no variable was specified then loop through all the variables - if(is.null(variables)){ - loop <- c(1:dim(input)[2]) - }else{ - # if the user specified variables to subset on check if those are in the dataset to subset from, - # if none of the variables is on the dataset record a message to inform the user - indx <- which(varnames %in% variables) - - if(length(indx) > 1){ - loop <- indx - }else{ - loop <- 1 - } - } - - # loop through the variables and make a subset dataframe for each level - # of each factor variable and keep the generated subset dataframes in a list - if(length(loop) > 1){ - # call the function that gets the subsets if the user specified non or more than 1 variable - out.temp <- subsetByClassHelper2(input,loop,nfilter.subset) - subsets <- out.temp[[1]] - nonfactorvars <- out.temp[[2]] - }else{ - # call the function that gets the subsets if the user specified only one variable to subset by - out.temp <- subsetByClassHelper3(input,indx,nfilter.subset) - subsets <- out.temp[[1]] - nonfactorvars <- out.temp[[2]] - } - output <- subsets - } - - return(output) -} diff --git a/R/subsetByClassHelper1.R b/R/subsetByClassHelper1.R deleted file mode 100644 index 7c288da3..00000000 --- a/R/subsetByClassHelper1.R +++ /dev/null @@ -1,41 +0,0 @@ -#' -#' @title generates subsets vectors from a factor vector -#' @description This is an internal function called by the function 'subsetByClassDS'. -#' @details The function generates subsets if the input of 'subsetByClassDS' is a factor vector. -#' @param xvect a vector of type factor. -#' @param xname the name of the vector. -#' @param filter the minimum number observation (i.e. rows) that are allowed. -#' @return a list which contains the subsets. -#' @keywords internal -#' @noRd -#' @author Gaye, A. -#' -subsetByClassHelper1 <- function(xvect=NULL, xname=NULL, filter=NULL){ - vectname <- xname - subsets <- list() - names.of.subsets <- c() - categories <- levels(xvect) - for(i in 1:length(categories)){ - indices <- which(xvect == as.numeric(categories[i])) - if(!(length(indices) < filter)){ - subsets[[i]] <- xvect[indices] - name.of.subD <- paste(vectname,".level_", categories[i], sep="") - names.of.subsets <- append(names.of.subsets, name.of.subD) - }else{ - # if any one category has between 0 and 'filter' observation turn subset content into missing values - if(length(indices) == 0){ - subsets[[i]] <- xvect[-c(1:length(xvect))] - name.of.subD <- paste(vectname,".level_", categories[i], "_EMPTY", sep="") - }else{ - temp1 <- xvect[indices] - temp1[1:length(temp1)] <- NA - subsets[[i]] <- temp1 - name.of.subD <- paste(vectname,".level_", categories[i], "_INVALID", sep="") - } - names.of.subsets <- append(names.of.subsets, name.of.subD) - } - names(subsets) <- names.of.subsets - output <- subsets - } - return(output) -} diff --git a/R/subsetByClassHelper2.R b/R/subsetByClassHelper2.R deleted file mode 100644 index f59cc907..00000000 --- a/R/subsetByClassHelper2.R +++ /dev/null @@ -1,64 +0,0 @@ -#' -#' @title generates subset tables from a data frame -#' @description This is an internal function called by the function 'subsetByClassDS' -#' @details The function generates subsets if the input of 'subsetByClassDS' is a data frame -#' and if the number variables(columns) to subset by are greater than 1; i.e. this -#' function is called if the user specified more than one variable or no variable to subset by -#' (if no variables are specified the function 'subsetByClassDS' produces a subset for each category -#' in each variable). -#' @param df a data frame. -#' @param iter the indices of columns to loop trough. -#' @param filter the minimum number of observations (i.e. rows) that are allowed. -#' @return a list which contains the subsets, their names and an integer that indicates how many columns were -#' not factors. -#' @keywords internal -#' @noRd -#' @author Gaye, A. -#' -subsetByClassHelper2 <- function(df=NULL, iter=NULL, filter=NULL){ - # various counters and temporary variables to hold info - subsets <- list() - names.of.subsets <- c() - count <- 0 - nonfactorvars <- 0 - ncols <- length(colnames(df)) - for(i in iter){ - var <- df[,i] - varname <- colnames(df)[i] - if(is.factor(var)){ - # get the levels - categories <- levels(var) - # loop through the levels and generate a dataset for each level - # if the number of observations for that level > 0 and < 'filter' - for(j in 1:length(categories)){ - indices <- which(var == as.numeric(categories[j])) - if(!(length(indices) < filter)){ - count <- count+1 - subD <- df[indices,] - subsets[[count]] <- subD - name.of.subD <- paste(varname,".level_", categories[j], sep="") - names.of.subsets <- append(names.of.subsets, name.of.subD) - }else{ - # if any one category has between 1 and 'filter' number of observation turn subset content into missing values - count <- count+1 - if(length(indices) == 0){ - subsets[[count]] <- df[-c(1:dim(df)[1]),] - name.of.subD <- paste(varname,".level_", categories[j], "_EMPTY",sep="") - }else{ - subD <- df[indices,] - subD[] <- NA - subsets[[count]] <- subD - name.of.subD <- paste(varname,".level_", categories[j], "_INVALID",sep="") - } - colnames(subsets[[count]]) <- colnames(df) - names.of.subsets <- append(names.of.subsets, name.of.subD) - } - } - names(subsets) <- names.of.subsets - }else{ - # if a variable is not a factor increment the below counter - nonfactorvars <- nonfactorvars + 1 - } - } - return(list(subsets, nonfactorvars)) -} \ No newline at end of file diff --git a/R/subsetByClassHelper3.R b/R/subsetByClassHelper3.R deleted file mode 100644 index de401f62..00000000 --- a/R/subsetByClassHelper3.R +++ /dev/null @@ -1,59 +0,0 @@ -#' -#' @title generates subset tables from a data frame -#' @description This is an internal function called by the function 'subsetByClassDS' -#' @details The function generates subsets if the input of 'subsetByClassDS' is a data frame -#' and if the number of variables (columns) to subset by is 1; i.e. this -#' function is called if the user specified one variable to subset by. -#' @param df a data frame. -#' @param indx1 the column index of the variable specified by the user. -#' @param filter the minimum number of observations (i.e. rows) that are allowed. -#' @return a list which contains the subsets, their names and an integer that indicates if -#' the variable specified by user is a factor. -#' @keywords internal -#' @noRd -#' @author Gaye, A. -#' -subsetByClassHelper3 <- function(df=NULL, indx1=NULL, filter=NULL){ - # various counters and temporary variables to hold info - subsets <- list() - names.of.subsets <- c() - count <- 0 - nonfactorvars <- 0 - ncols <- length(colnames(df)) - var <- df[,indx1] - varname <- colnames(df)[indx1] - if(is.factor(var)){ - # get the levels - categories <- levels(var) - # loop through the levels and generate a dataset for each level - # if the number of observations for that level > 0 and < 'filter' - for(j in 1:length(categories)){ - indices <- which(var == as.numeric(categories[j])) - if(!(length(indices) < filter)){ - count <- count+1 - subD <- df[indices,] - subsets[[count]] <- subD - name.of.subD <- paste(varname,".level_", categories[j], sep="") - names.of.subsets <- append(names.of.subsets, name.of.subD) - }else{ - # if any one category has between 1 and 'filter' number of observations turn subset content into missing values - count <- count+1 - if(length(indices) == 0){ - subsets[[count]] <- df[-c(1:dim(df)[1]),] - name.of.subD <- paste(varname,".level_", categories[j], "_EMPTY",sep="") - }else{ - subD <- df[indices,] - subD[] <- NA - subsets[[count]] <- subD - name.of.subD <- paste(varname,".level_", categories[j], "_INVALID",sep="") - } - colnames(subsets[[count]]) <- colnames(df) - names.of.subsets <- append(names.of.subsets, name.of.subD) - } - } - names(subsets) <- names.of.subsets - }else{ - nonfactorvars <- 1 - } - return(list(subsets, nonfactorvars)) -} \ No newline at end of file diff --git a/R/subsetDS.R b/R/subsetDS.R deleted file mode 100644 index 2ab0a14c..00000000 --- a/R/subsetDS.R +++ /dev/null @@ -1,134 +0,0 @@ -#' -#' @title Generates a valid subset of a table or a vector -#' @description The function uses the R classical subsetting with squared brackets '[]' and allows also to -#' subset using a logical operator and a threshold. The object to subset from must be a vector (factor, numeric -#' or character) or a table (data.frame or matrix). -#' @details If the input data is a table: The user specifies the rows and/or columns to include in the subset if the input -#' object is a table; the columns can be referred to by their names. The name of a vector (i.e. a variable) can also be provided -#' with a logical operator and a threshold (see example 3). -#' If the input data is a vector: when the parameters 'rows', 'logical' and 'threshold' are all provided the last two are ignored ( -#' 'rows' has precedence over the other two parameters then). -#' If the requested subset is not valid (i.e. contains less than the allowed -#' number of observations), the subset is not generated, rather a table or a vector of missing values is generated to allow -#' for any subsequent process using the output of the function to proceed after informing the user via a message. -#' @param dt a string character, the name of the dataframe or the factor vector and the range of the subset. -#' @param complt a boolean that tells if the subset to subset should include only complete cases -#' @param rs a vector of two integers that give the range of rows de extract. -#' @param cs a vector of two integers or one or more characters; the indices of the columns to extract or the names of the columns (i.e. -#' names of the variables to extract). -#' @param lg a character, the logical parameter to use if the user wishes to subset a vector using a logical -#' operator. This parameter is ignored if the input data is not a vector. -#' @param th a numeric, the threshold to use in conjunction with the logical parameter. This parameter is ignored -#' if the input data is not a vector. -#' @param varname a character, if the input data is a table, if this parameter is provided along with the 'logical' and 'threshold' -#' parameters, a subtable is based the threshold applied to the specified variable. This parameter is however ignored if the parameter -#' 'rows' and/or 'cols' are provided. -#' @return a subset of the vector, matrix or dataframe as specified is stored on the server side -#' @author Gaye, A. -#' @export -#' -subsetDS <- function(dt=NULL, complt=NULL, rs=NULL, cs=NULL, lg=NULL, th=NULL, varname=NULL){ - - # Check Permissive Privacy Control Level. - dsBase::checkPermissivePrivacyControlLevel(c('permissive', 'banana', 'carrot')) - - # this filter sets the minimum number of observations that are allowed - - ############################################################# - # MODULE 1: CAPTURE THE nfilter SETTINGS - thr <- dsBase::listDisclosureSettingsDS() - nfilter.tab <- as.numeric(thr$nfilter.tab) - #nfilter.glm <- as.numeric(thr$nfilter.glm) - #nfilter.subset <- as.numeric(thr$nfilter.subset) - #nfilter.string <- as.numeric(thr$nfilter.string) - ############################################################# - - # the logical operators are given as integers change them into characters - if(!(is.null(lg))){ - if(lg == 1){lg <- ">"} - if(lg == 2){lg <- ">="} - if(lg == 3){lg <- "<"} - if(lg == 4){lg <- "<="} - if(lg == 5){lg <- "=="} - if(lg == 6){lg <- "!="} - } - - # evaluate the input data object - D <- eval(parse(text=dt), envir = parent.frame()) - - # if 'complt' is set to TRUE, get continue with a dataset with complete cases only - if(complt){ - cc <- stats::complete.cases(D) - xx <- which(cc == TRUE) - Dtemp <- D - if(is.vector(D) | is.factor(D)){ - D <- Dtemp[xx] - }else{ - D <- Dtemp[xx,] - } - } - - # carry out the subsetting - if(is.vector(D) | is.factor(D)){ # if the input data is a vector - - if(is.null(rs)){ - if(is.null(lg) | is.null(th)){ - subvect <- D - }else{ - exprs1 <- paste0("D[which(D", lg, th, ")]") - subvect <- eval(parse(text=exprs1)) - } - }else{ - subvect <- D[rs] - } - - if(length(subvect) < nfilter.tab){ - if(length(subvect) == 0){ - output <- D[-c(1:length(D))] - }else{ - temp1 <- subvect - temp1[1:length(temp1)] <- NA - output <- temp1 - } - }else{ - output <- subvect - } - }else{ # if the input data is a table - - if(!(is.null(rs)) | !(is.null(cs))){ - if(!(is.null(rs)) & !(is.null(cs))){ - subtable <- D[rs, cs] - }else{ - if(is.null(cs)){ - cs <- c(1:dim(D)[2]) - } - if(is.null(rs)){ - rs <- c(1:dim(D)[1]) - } - subtable <- D[rs,cs] - } - }else{ - if(is.null(varname)){ - subtable <- D - }else{ - idx <- which(colnames(D) == varname) - exprs2 <- paste0('D[which(D[,',idx,']', lg, th, '),]') - subtable <- eval(parse(text=exprs2)) - } - } - - if((dim(subtable)[1]) < nfilter.tab){ - if((dim(subtable)[1]) == 0){ - output <- D[-c(1:dim(D)[1]),] - }else{ - subD <- subtable - subD[] <- NA - output <- subD - } - }else{ - output <- subtable - } - } - - return(output) -} diff --git a/R/table2DDS.R b/R/table2DDS.R deleted file mode 100644 index 5b4f5dd1..00000000 --- a/R/table2DDS.R +++ /dev/null @@ -1,61 +0,0 @@ -#' -#' @title table2DDS (aggregate function) called by ds.table2D -#' @description This function generates a 2-dimensional contingency table where potentially disclosive cells -#' (based on a set threshold) are replaced by a missing value ('NA'). -#' @details It generates 2-dimensional contingency tables where valid (non-disclosive) tables are defined -#' as those where none of their cells have counts between 1 and the set threshold "nfilter.tab". When the output table -#' is invalid all cells except the total counts are replaced by missing values. Only the total counts are visible -#' on the table returned to the client side. A message is also returned with the 2-dimensional table; the message -#' says "invalid table - invalid counts present" if the table is invalid and 'valid table' otherwise. -#' @param xvect a numerical vector with discrete values - usually a factor. -#' @param yvect a numerical vector with discrete values - usually a factor. -#' @return a list which contains two elements: 'table', the 2-dimensional table and 'message' a message which -#' informs about the validity of the table. -#' @author Amadou Gaye, Paul Burton, Demetris Avraam for DataSHIELD Development Team -#' @export -#' -table2DDS <- function(xvect,yvect){ - - ############################################################# - #MODULE 1: CAPTURE THE nfilter SETTINGS - thr <- dsBase::listDisclosureSettingsDS() - nfilter.tab <- as.numeric(thr$nfilter.tab) - #nfilter.glm<-as.numeric(thr$nfilter.glm) - #nfilter.subset<-as.numeric(thr$nfilter.subset) - #nfilter.string<-as.numeric(thr$nfilter.string) - #nfilter.stringShort<-as.numeric(thr$nfilter.stringShort) - #nfilter.kNN<-as.numeric(thr$nfilter.kNN) - ############################################################# - - # tabulate the input vector and output the result in a data frame format - aa <- table(xvect, yvect) - bb <- matrix(NA, nrow=dim(aa)[1], ncol=dim(aa)[2]) - for(i in 1:dim(aa)[1]){ - bb[i,] <- aa[i,] - } - bb <- rbind(bb, colSums(bb)) - bb <- cbind(bb, rowSums(bb)) - cc <- as.data.frame(bb) - colnames(cc) <- c(levels(as.factor(yvect)), "Total") - rownames(cc) <- c(levels(as.factor(xvect)), "Total") - - # the minimum non-zero number of observations that is allowed in a single cell - nfilter <- nfilter.tab - - # check for invalid cells if any found change them to 'NA' and set the validity message accordingly - validity <- "valid Table" - for(i in 1: dim(cc)[2]){ - indx <- which(cc[1:(dim(cc)[1] - 1),i] > 0 & cc[1:(dim(cc)[1] - 1),i] < nfilter) - if(length(indx) > 0){ - cc[1:(dim(cc)[1] - 1), 1:(dim(cc)[2] - 1)] <- NA - validity <- "invalid table - invalid counts present" - break - } - } - - # return output table and message - return(list(table=cc, message=validity)) - -} -#AGGREGATE FUNCTION -# table2DDS diff --git a/R/testObjExistsDS.R b/R/testObjExistsDS.R deleted file mode 100644 index 9c3a26e7..00000000 --- a/R/testObjExistsDS.R +++ /dev/null @@ -1,33 +0,0 @@ -#' -#' @title testObjExistsDS -#' @description The server-side function called by ds.testObjExists -#' @details Tests whether a given object exists in -#' all sources. It is called at the end of all -#' recently written assign functions to check the new (assigned) object has been -#' created in all sources -#' @param test.obj.name a client-side provided character string specifying the variable -#' whose presence is to be tested in each data source -#' -#' @author Burton PR -#' -#' @return List with `test.obj.exists` and `test.obj.class` -#' @export -#' -testObjExistsDS <- function(test.obj.name=NULL){ - - test.obj.exists <- FALSE - test.obj.class <- NULL - - #Restrict tests to settings where name does exist to avoid error termination - - if(exists(test.obj.name, envir = parent.frame())){ - test.obj.exists <- TRUE - test.obj <- get(test.obj.name, envir = parent.frame()) - test.obj.class <- class(test.obj) - } - - return(list(test.obj.exists=test.obj.exists,test.obj.class=test.obj.class)) - -} -#AGGREGATE FUNCTION -# testObjExistsDS diff --git a/inst/DATASHIELD b/inst/DATASHIELD index e69da687..7835a403 100644 --- a/inst/DATASHIELD +++ b/inst/DATASHIELD @@ -11,8 +11,6 @@ AggregateMethods: covDS, dataFrameSubsetDS1, densityGridDS, - extractQuantilesDS1, - extractQuantilesDS2, dimDS, gamlssDS, glmDS1, @@ -40,16 +38,12 @@ AggregateMethods: mdPatternDS, meanDS, meanSdGpDS, - messageDS, metadataDS, miceDS, - minMaxRandDS, namesDS, numNaDS, quantileMeanDS, rangeDS, - ranksSecureDS1, - ranksSecureDS3, rmDS, scatterPlotDS, scoreVectDS, @@ -57,11 +51,9 @@ AggregateMethods: skewnessDS1, skewnessDS2, table1DDS, - table2DDS, tableDS, tableDS2, tapplyDS, - testObjExistsDS, varDS, exists=base::exists, is.character=base::is.character, @@ -84,8 +76,6 @@ AssignMethods: asLogicalDS, asMatrixDS, asNumericDS, - blackBoxDS, - blackBoxRanksDS, BooleDS, boxPlotGG_data_TreatmentDS, boxPlotGG_data_Treatment_numericDS, @@ -95,7 +85,6 @@ AssignMethods: changeRefGroupDS, completeCasesDS, dataFrameDS, - dataFrameFillDS, dataFrameSortDS, dataFrameSubsetDS2, dmtC2SDS, @@ -121,12 +110,8 @@ AssignMethods: mergeDS, nsDS, qlsplineDS, - ranksSecureDS2, - ranksSecureDS4, - ranksSecureDS5, rbindDS, rBinomDS, - recodeLevelsDS, recodeValuesDS, repDS, replaceNaDS, @@ -138,8 +123,6 @@ AssignMethods: sampleDS, seqDS, sqrtDS, - subsetByClassDS, - subsetDS, tableDS.assign, tapplyDS.assign, uniqueDS, diff --git a/inst/WORDLIST b/inst/WORDLIST index 23ca495f..351aee80 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -92,8 +92,6 @@ auc aucDS bfa blackBox -blackBoxDS -blackBoxRanksDS blackbox booleans bp @@ -119,7 +117,6 @@ cyc dataFrame dataFrameDS dataFrameFill -dataFrameFillDS dataFrameShort dataFrameSort dataFrameSortDS @@ -208,7 +205,6 @@ maxit mdata meanSdGp mergeDS -messageDS messageobj metafor mfa @@ -302,7 +298,6 @@ tableDS tapply tapplyDS testObjExists -testObjExistsDS th tibble timevar diff --git a/man/blackBoxDS.Rd b/man/blackBoxDS.Rd deleted file mode 100644 index 3621284b..00000000 --- a/man/blackBoxDS.Rd +++ /dev/null @@ -1,70 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/blackBoxDS.R -\name{blackBoxDS} -\alias{blackBoxDS} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -blackBoxDS(input.var.name = NULL, shared.seedval, synth.real.ratio, NA.manage) -} -\arguments{ -\item{input.var.name}{a character string specifying the name of V2BR. This -argument is set by the argument with the same name in the clientside function -ds.ranksSecure} - -\item{shared.seedval}{a pseudorandom number seed that ensures that the -processes generating the order and parameterisation of the encryption -algorithms are the same in each study. This argument is set by the argument - in the clientside function ds.ranksSecure. For more -details, including future plans to share this starting seed in a more secure -way, please see the associated document entitled "secure.global.ranking.docx" -and the header file for ds.ranksSecure.} - -\item{synth.real.ratio}{an integer value representing -the ratio of synthetic (pseudo-data) values to the real number of -values in V2BR. This argument is set by the argument with the same name -in the clientside function ds.ranksSecure. For more details, please see the -associated document entitled "secure.global.ranking.docx" and the header file -for ds.ranksSecure.} - -\item{NA.manage}{character string indicating how missing values (NAs) in -V2BR should be managed. It takes three possible values: "NA.delete", -"NA.low","NA.hi". This argument is set by the argument with the same name -in the clientside function ds.ranksSecure. For more details, please see the -associated document entitled "secure.global.ranking.docx" and the header file -for ds.ranksSecure.} -} -\value{ -writes a data frame object entitled blackbox.output.df to the -serverside. In each study this contains the encrypted -"combined real+pseudo data vector" and a range of other key components -from the first stage of the ranking procedure. For more details see the -associated document entitled "secure.global.ranking.docx" -} -\description{ -The first key serverside function that sets up the V2BR for -ranking in the client. -} -\details{ -Severside assign function called by ds.ranksSecure. -Creates pseudo-data by using the real distribution of values in V2BR -to create a large number of synthetic data with a similar distribution to -the values in V2BR but with a slightly broader distribution at both ends -to ensure that any extreme values in the "combined real+pseudo data vector" -are all pseudo-data. Also ensures that the number of decimal places of -the values in the V2BR is reflected by the number of decimal places in -the pseudodata. Finally, takes the "combined real+pseudo data vector" through -seven rounds of rank consistent encryption that involves algorithms -themselves generated by a pseudorandom process that selects which -transformation to apply and with what parameters. The encryption algorithms -are the same in each study ensuring that ranks also remain consistent between -studies. After encryption the encrypted "combined real+pseudo data vector" is -written to the serverside as a dataframe also including other key component -vectors from the first stage of the ranking procedure. -For more details about the cluster of functions that -collectively enable secure global ranking and estimation of global quantiles -see the associated document entitled "secure.global.ranking.docx". Also -see the header file for ds.ranksSecure -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/blackBoxRanksDS.Rd b/man/blackBoxRanksDS.Rd deleted file mode 100644 index f5446a31..00000000 --- a/man/blackBoxRanksDS.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/blackBoxRanksDS.R -\name{blackBoxRanksDS} -\alias{blackBoxRanksDS} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -blackBoxRanksDS(input.var.name = NULL, shared.seedval) -} -\arguments{ -\item{input.var.name}{a character string specifying the name of the -vector holding the global ranks. This argument is set automatically by -the clientside function ds.ranksSecure} - -\item{shared.seedval}{a pseudorandom number seed that ensures that the -processes generating the order and parameterisation of the encryption -algorithms are the same in each study. This argument is set by the argument - in the clientside function ds.ranksSecure. The -seed value shared by all studies in setting up the encryption procedures -in blackBoxRanksDS is arbitrarily changed from that used to set up the -encryption procedures in blackBoxDS, so the the set of 7 encryption -algorithms is deliberately different. For more -details, including future plans to share this starting seed in a more secure -way, please see the associated document entitled "secure.global.ranking.docx" -and the header file for ds.ranksSecure.} -} -\value{ -writes a data frame object entitled blackbox.ranks.df to the -serverside. In each study this contains the encrypted global ranks -and a range of other key components from the second stage (ranking of global -ranks for real observations only) of the ranking procedure. For more details -see the associated document entitled "secure.global.ranking.docx" -} -\description{ -The second key serverside function that prepares the global -ranks of the the real data only generated in the first stage of the -ranking procedure and encrypts them in preparation for generating global -ranks that correspond 1 to 1 with only the real data in V2BR. -} -\details{ -Severside assign function called by ds.ranksSecure. It takes the -global ranks currently held in sR5.df which reflect the global ranks based on -the "combined real+pseudo data vector" as encrypted by blackBoxDS -but with all pseudo-data stripped out. It then uses these global ranks (of -the real data) as if they were a new variable to be ranked. This is then -equivalent to blackBoxDS with the primary difference that no -pseudo-data are needed. This is because the global ranks are fundamentally -non-disclosive and so can be transferred to the clientside with no risk of -disclosure. However, in order to ensure that the client cannot compare -the list of global.ranks in sR4.df (after initial global ranking based on -ranking of real and pseudo-data combined) with the global.ranks to be -generated by blackBoxRanksDS (based solely on the real data they are -processed through seven more rounds of encryption as before in blackBoxDS. -In consequence the client remains unable to determine which of the original -global ranks corresponded to real data and which to pseudo-data. In -addition, blackBoxRanksDS does not need to determine the number of decimal -places in the data because it is only applied to ranks which are assumed to -be integers. For more details about the cluster of functions that -collectively enable secure global ranking and estimation of global quantiles -see the associated document entitled "secure.global.ranking.docx". Also -see the header file for ds.ranksSecure and the header file for blackBoxDS -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/dataFrameFillDS.Rd b/man/dataFrameFillDS.Rd deleted file mode 100644 index 65899c34..00000000 --- a/man/dataFrameFillDS.Rd +++ /dev/null @@ -1,45 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dataFrameFillDS.R -\name{dataFrameFillDS} -\alias{dataFrameFillDS} -\title{dataFrameFillDS} -\usage{ -dataFrameFillDS( - df.name, - allNames.transmit, - class.vect.transmit, - levels.vec.transmit -) -} -\arguments{ -\item{df.name}{a character string representing the name of the input data frame that will be -filled with extra columns with missing values if a number of variables is missing from it -compared to the data frames of the other studies used in the analysis.} - -\item{allNames.transmit}{unique names of all the variables that are included in the input -data frames from all the used datasources.} - -\item{class.vect.transmit}{the classes of all the variables that are included in the vector -\code{allNames.transmit}.} - -\item{levels.vec.transmit}{the levels of all factor variables. -The classes supported are 'numeric', 'integer', 'character', 'factor' and 'logical'.} -} -\value{ -Nothing is returned to the client. The generated object is written to the serverside. -} -\description{ -An assign function called by the clientside ds.dataFrameFill function. -} -\details{ -This function checks if each study has all the variables compared to the other studies -in the analysis. If a study does not have some of the variables, the function generates those -variables as vectors of missing values and combines them as columns to the input data frame. -Then, the "complete" in terms of the columns dataframe is saved in each server with a name -specified by the argument \code{newobj} on the clientside. -} -\author{ -Demetris Avraam for DataSHIELD Development Team - -Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands -} diff --git a/man/extractQuantilesDS1.Rd b/man/extractQuantilesDS1.Rd deleted file mode 100644 index 4aae2dfc..00000000 --- a/man/extractQuantilesDS1.Rd +++ /dev/null @@ -1,60 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/extractQuantilesDS1.R -\name{extractQuantilesDS1} -\alias{extractQuantilesDS1} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources -and use of these ranks to estimate global quantiles across all studies} -\usage{ -extractQuantilesDS1(extract.quantiles, extract.summary.output.ranks.df) -} -\arguments{ -\item{extract.quantiles}{one of a restricted set of character strings that -fix the set of quantile values for which the corresponding values across -all studies are to be estimated. For more details -see the associated document entitled "secure.global.ranking.docx", the -header for ds.ranksSecure and ds.extractQuantiles functions. -The value of this argument is set in choosing the value of the argument - in ds.ranksSecure.} - -\item{extract.summary.output.ranks.df}{character string specifying optional -name for the data.frame written to the serverside on each data source that -contains 5 of the key output variables from the ranking procedure pertaining -to that particular data source. This data frame represents the key source of -information - including global ranks - that determines the values of V2BR -that are identified as corresponding to the particular set of quantiles to -be estimated as specified by the argument of -function ds.ranksSecure (and the argument of -ds.extractQuantiles).} -} -\value{ -as a first step in creating the vector of values of values of V2BR -that correspond to each quantile value, extractQuantilesDS1 identifies the -two closest quantile values across all studies that span each key quantile -value. These are saved as the data frame "closest.bounds.df" on the -clientside and then saved on the serverside by ds.dmtC2S into the data frame -"global.bounds.df". Also if the number of observations across all studies is -too small, and a disclosure risk exists if the final.quantile.vector is made -available via the client, this function stops the processing and returns a -warning/error message. -} -\description{ -identify the global values of V2BR (i.e. the values across all -studies) that relate to a set of quantiles to be evaluated. -} -\details{ -Severside aggregate function called by ds.extractQuantiles via -ds.ranksSecure. As well as estimating the key values of V2BR that correspond -to the selected quantiles, this function also implements a disclosure control -trap. If the ratio of the total number of all observations across all studies -divided by the number of quantile values to be estimated is less than or -equal to nfilter.subset (which specifies the minimum size of a subset) the -process stops and an error message is returned suggesting that you might -try selecting a narrower range of quantiles with less quantile values to be -estimated as specified by the argument of the -function ds.ranksSecure. For more details about the cluster of functions that -collectively enable secure global ranking and estimation of global quantiles -see the associated document entitled "secure.global.ranking.docx" -} -\author{ -Paul Burton 11th November, 2021 -} diff --git a/man/extractQuantilesDS2.Rd b/man/extractQuantilesDS2.Rd deleted file mode 100644 index c4213f6b..00000000 --- a/man/extractQuantilesDS2.Rd +++ /dev/null @@ -1,60 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/extractQuantilesDS2.R -\name{extractQuantilesDS2} -\alias{extractQuantilesDS2} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources -and use of these ranks to estimate global quantiles across all studies} -\usage{ -extractQuantilesDS2(extract.summary.output.ranks.df) -} -\arguments{ -\item{extract.summary.output.ranks.df}{character string specifies an optional -name for the data.frame written to the serverside on each data source that -contains 5 of the key output variables from the ranking procedure pertaining -to that particular data source. This data frame represents the key source of -information - including global ranks - that determines the values of V2BR -that are identified as corresponding to the particular set of quantiles to -be estimated as specified by the argument of -function ds.ranksSecure (and the argument of -ds.extractQuantiles).} -} -\value{ -the single value of V2BR which best corresponds to each key quantile -value to be estimated as specified by the argument -A data frame (final.quantile.df)summarising the results of this analysis -is written to the clientside. This data frame consists of two vectors. The -first is named "evaluation.quantiles". It lists the full set of quantiles -you have requested for evaluation as specified by the argument -"quantiles.for.estimation" The second vector which is called -"final.quantile.vector" details the values of V2BR that correspond to the -the key quantiles listed in vector 1. -} -\description{ -identify the global values of V2BR (i.e. the values across all -studies) that relate to a set of quantiles to be evaluated. -} -\details{ -Severside aggregate function called by ds.extractQuantiles via -ds.ranksSecure. This takes the "global.bounds.df" data frame saved on the -serverside following construction by extractQuantilesDS1. This -data frame includes the two quantile values that most closely span each -quartile value to be estimated. If either of the values had been the correct -value for a given quantile, both the bounding values would have taken that -value in global.bounds.df. This is because the upper bound was defined as -the lowest value that was equal to or greater than the true value for that -quantile while the lower bound was defined as the highest value that was -equal to or lower than the true value. Next, the function extractQuantileDS2 -goes round study by study to identify the values of V2BR that actually -correspond to each of the spanning values around each quantile. Then the -function goes quantile by quantile and estimates the mean of the -two values of V2BR that correspond to the the spanning quantiles. If these -two values are the same it means that that value of V2BR is the -"true" value and the mean of two (or potentially several) instances of that -value is inevitably also equal to that true value. If the upper and lower -bounding values of V2BR differ, neither can be the precisely correct single -value of V2BR for that quantile (see above for explanation) and so the mean -of the two is a reasonable interpolated summary. -} -\author{ -Paul Burton 11th November, 2021 -} diff --git a/man/messageDS.Rd b/man/messageDS.Rd deleted file mode 100644 index b438a2b9..00000000 --- a/man/messageDS.Rd +++ /dev/null @@ -1,40 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/messageDS.R -\name{messageDS} -\alias{messageDS} -\title{messageDS} -\usage{ -messageDS(message.object.name) -} -\arguments{ -\item{message.object.name}{is a character string, containing the name of the list containing the -message. See the header of the client-side function ds.message for more details.} -} -\value{ -a list object from each study, containing whatever message has been written by -DataSHIELD into $studysideMessage. -} -\description{ -This function allows for error messages arising from the -running of a server-side assign function to be returned to the client-side -} -\details{ -Errors arising from aggregate server-side functions can be returned -directly to the client-side. But this is not possible for server-side assign -functions because they are designed specifically to write objects to the -server-side and to return no meaningful information to the client-side. -Otherwise, users may be able to use assign functions to return disclosive -output to the client-side. ds.message calls messageDS which looks -specifically for an object called $serversideMessage in a designated list on -the server-side. Server-side functions from which error messages are to be made -available, are designed to be able to write the designated error message to -the $serversideMessage object into the list that is saved on the server-side -as the primary output of that function. So only valid server-side functions of -DataSHIELD can write a $studysideMessage, and as additional protection against -unexpected ways that someone may try to get round this limitation, a -$studysideMessage is a string that cannot exceed a length of nfilter.string -a default of 80 characters. -} -\author{ -Burton PR -} diff --git a/man/minMaxRandDS.Rd b/man/minMaxRandDS.Rd deleted file mode 100644 index 82355434..00000000 --- a/man/minMaxRandDS.Rd +++ /dev/null @@ -1,35 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/minMaxRandDS.R -\name{minMaxRandDS} -\alias{minMaxRandDS} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -minMaxRandDS(input.var.name) -} -\arguments{ -\item{input.var.name}{a character string specifying the name of V2BR. This -argument is set by the argument with the same name in the clientside function -ds.ranksSecure} -} -\value{ -the data frame objects containing the global ranks and quantiles. -For more details see the associated document entitled -"secure.global.ranking.docx" -} -\description{ -Creates a minimum value that is more negative, and less positive -than any real value in V2BR and a maximum value that is more positive and -less negative than any value of V2BR. -} -\details{ -Severside aggregate function called by ds.ranksSecure. The minimum -and maximum values it creates are used to replace missing values -(NAs) in V2BR if the argument e is set to "NA.low" or "NA.hi" -respectively. For more details about the cluster of functions that -collectively enable secure global ranking and estimation of global quantiles -see the associated document entitled "secure.global.ranking.docx". Also -see the header file for ds.ranksSecure -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/ranksSecureDS1.Rd b/man/ranksSecureDS1.Rd deleted file mode 100644 index e809cdec..00000000 --- a/man/ranksSecureDS1.Rd +++ /dev/null @@ -1,35 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ranksSecureDS1.R -\name{ranksSecureDS1} -\alias{ranksSecureDS1} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -ranksSecureDS1() -} -\value{ -the non-disclosive elements of blackbox.output.df (see details) -on the serverside as a data frame object (called blackbox.output) -on the clientside. After processing to create the global ranks across all -studies, this is returned to the serverside as the data frame sR4.df using -the clientside function ds.dmtC2S -} -\description{ -takes key non-disclosive components of the serverside data frame -blackbox.output.df over to the clientside to enable global ranking. -} -\details{ -Severside aggregate function called by ds.ranksSecure. The -non-disclosive components of blackbox.output.df that are transmitted to the -clientside are: (1) final values of the "combined real+pseudo data vector" -after all seven rounds of encryption have been completed; (2) a set of -sequential IDs allocated after sorting the "combined real+pseudo data vector" -by value (in ascending order). This allows later re-linkage of values back on -the serverside and confirmation that that linkage is correct. For more -details about the cluster of functions that collectively enable secure global -ranking and estimation of global quantiles see the associated document -entitled "secure.global.ranking.docx". Also see the header file -for ds.ranksSecure -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/ranksSecureDS2.Rd b/man/ranksSecureDS2.Rd deleted file mode 100644 index c742d493..00000000 --- a/man/ranksSecureDS2.Rd +++ /dev/null @@ -1,44 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ranksSecureDS2.R -\name{ranksSecureDS2} -\alias{ranksSecureDS2} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -ranksSecureDS2() -} -\value{ -creates a new data frame sR5.df on the serverside containing -solely the real data and including key elements needed for next stage of the -ranking process. Most crucially these include "global.rank" and "ID.by.val" -sorted in ascending order of the magnitude of V2BR -} -\description{ -Checks that the data frame produced in creating the initial -global ranks (ranks based on real and pseudo-data after the running of -blackBoxDS)has the correct dimensions and order as the serverside data frames -to which it will now be appended. If either the number of rows or the order -of the rows are inconsistent with the pre-existing data frames on the -serverside an error message is returned and the processing stops. Then -strips out the pseudo-data leaving solely the global ranks based just on -the real data -} -\details{ -Severside assign function called by ds.ranksSecure. -It works on the on the output created by serverside function ranksSecureDS1 -and saved on the serverside in data frame sR4.df by ds.dmtC2S. Having -checked QA it strips out all rows corresponding to pseudo-data. The resultant -data frame contains the following vectors: (1) the fully encrypted V2BR -(after application of blackBoxDS);(2) "ID.by.val" the sequential -ID associated with the "combined real+pseudo data vector" sorted by -value (ascending); (3) "studyid", a vector consisting solely of value n in -the nth study; (4) "global.rank" the vector containing global ranks created by -the clientside code in ds.ranksSecure after ranksSecureDS1 is called and up -to the point where ds.dmtC2S sends sR4.df to the serverside. For more -details about the cluster of functions that collectively enable secure global -ranking and estimation of global quantiles see the associated document -entitled "secure.global.ranking.docx". Also see the header file -for ds.ranksSecure -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/ranksSecureDS3.Rd b/man/ranksSecureDS3.Rd deleted file mode 100644 index 286f77ad..00000000 --- a/man/ranksSecureDS3.Rd +++ /dev/null @@ -1,46 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ranksSecureDS3.R -\name{ranksSecureDS3} -\alias{ranksSecureDS3} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -ranksSecureDS3() -} -\value{ -the non-disclosive elements of blackbox.output.df (see details) -on the serverside as a data frame object (called sR6.df) -on the clientside. After processing within ds.ranksSecure to create the -global ranks and global quantiles (of real data only) across all studies, -this is returned to the serverside as data frame "global.ranks.quantiles.df" -using the clientside function ds.dmtC2S. To illustrate the difference between -ranks and quantiles, if there are a total of 1000 original real observations -across all studies and one particular observation has the rank 250, it will -have quantile value 0.25 (i.e. 25%th value in the overall data ordered by -increasing value). Both ranks and quantiles can have ties. For more details -about the cluster of functions that collectively enable secure global ranking -and estimation of global quantiles see the associated document entitled -"secure.global.ranking.docx". Also see the header file for ds.ranksSecure -} -\description{ -takes key non-disclosive components of the serverside data frame -blackbox.ranks.df over to the clientside to enable global re-ranking of the -global ranks just applying to the real data (not the pseudo-data). -} -\details{ -Severside aggregate function called by ds.ranksSecure. The -non-disclosive components of blackbox.ranks.df that are transmitted to the -clientside are: (1) final values of the encrypted global ranks vector -after all seven rounds of encryption have been completed; (2) a set of -sequential IDs allocated to the global ranks vector in each study in their -current order based on increasing value of V2BR. This allows later re-linkage -of values back on the serverside and confirmation that that linkage is -correct. (3) a studyid vector with all values n in the nth study. This -facilitates data management on the serverside during the global ranking -of global ranks. For more details about the cluster of functions that -collectively enable secure global ranking and estimation of global quantiles -see the associated document entitled "secure.global.ranking.docx". Also see -the header file for ds.ranksSecure -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/ranksSecureDS4.Rd b/man/ranksSecureDS4.Rd deleted file mode 100644 index 7835282c..00000000 --- a/man/ranksSecureDS4.Rd +++ /dev/null @@ -1,55 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ranksSecureDS4.R -\name{ranksSecureDS4} -\alias{ranksSecureDS4} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -ranksSecureDS4(ranks.sort.by) -} -\arguments{ -\item{ranks.sort.by}{a character string taking two possible values. These -are "ID.orig" and "vals.orig". These define the order in which the -output.ranks.df and summary.output.ranks.df data frames are presented. This -argument is set by the argument with the same name in ds.ranksSecure. -Default value is "ID.orig".} -} -\value{ -Creates the data frame identified by the name given by the argument -() of the ds.ranksSecure function and writes it to the -serverside. If the argument is NULL or unspecified the -output data frame is called "main.ranks.df". The data frame is ordered -according to the argument in ds.ranksSecure. -} -\description{ -Creates a data frame "sR8.df" by cbinding the data frame -"blackBox.ranks.df" with the global ranks and global quantiles vectors in -"global.ranks.quantiles.df". Performs QA on this matrix and orders the -sR8.df data frame according to the argument in ds.ranksSecure -} -\details{ -Severside assign function called by ds.ranksSecure. -Creates a data frame "sR8.df" by cbinding the data frame "blackBox.ranks.df" -with the global ranks and global quantiles vectors in -"global.ranks.quantiles.df". Checks that all components of sR8.df have the -correct dimensions and are consistent in their ordering. If either the -number of rows or the order of the rows are inconsistent with those in -"blackBox.ranks.df" an error message is returned and the processing stops. -If sR8.df passes all QA tests it is written to the serverside as a data -frame with its name identified by the argument in -ds.ranksSecure. If that argument is NULL or unspecified the data frame -is called "main.ranks.df". The ranksSecureDS4 function also orders the -combined data frame () in one of two ways: if -the argument in ds.ranksSecure is set to "ID.orig" the -combined data frame is ordered in the same way as the original V2BR vector; -if the argument is set to vals.orig" the combined data frame -is ordered by the magnitude of the values of V2BR (ascending). Having -created the data frame () in this manner it can now be -directly cbinded to either the V2BR vector itself or to a data frame, tibble -or matrix containing V2BR (assuming they are also in the order corresponding -to the argument ) and this combined object can be used as the -basis of analysis based on the global ranks or quantiles including a range -of types of non-parametric analysis. -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/ranksSecureDS5.Rd b/man/ranksSecureDS5.Rd deleted file mode 100644 index 6851ff90..00000000 --- a/man/ranksSecureDS5.Rd +++ /dev/null @@ -1,55 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ranksSecureDS5.R -\name{ranksSecureDS5} -\alias{ranksSecureDS5} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -ranksSecureDS5(output.ranks.df) -} -\arguments{ -\item{output.ranks.df}{a character string which specifies an optional name -for the data.frame written to the serverside on each data source that -contains 11 of the key output variables from the ranking procedure pertaining -to that particular data source. This argument is set by the argument with -the same name in ds.ranksSecure.} -} -\value{ -extracts 5 key vectors from the larger data frame created by -ranksSecureDS4 to produce a summary data frame that is written to the -serverside. It is given a name specified by the argument. -} -\description{ -Summarises the serverside data frame written by ranksSecureDS4 -which is identified by the name given by the argument () of -the ds.ranksSecure function to produce a new output data frame containing -only 5 key variables. -} -\details{ -Serverside assign function called by clientside function -ds.ranksSecure. Takes the serverside data frame written by ranksSecureDS4 -which is identified by the name given by the argument () of -the ds.ranksSecure function. This holds 11 vectors including the final -global ranks across all studies and final global quantiles. The data frame -is ordered according to the argument in ds.ranksSecure. The -ranksSecureDS5 function then extracts 5 key vectors from the larger data -frame to produce a summary data frame that is given a name specified by -the argument () the ds.ranksSecure function. -This data frame includes the following components: (1) The values of a -sequential ID variable (ID.seq.real.orig) created to lie alongside the -original V2BR vector in the same order as that vector was itself ordered. -These ID values therefore reflect which row in the original data corresponds -to a given row in the output. If the argument in -ds.ranksSecure is set to "ID.orig" the values of the ID.seq.real.orig vector -in the output data frame simply run sequentially from 1 to N where N is the -number of individuals in the corresponding study. If is -set to "vals.orig" the values of the ID.seq.real.orig vector will be -determined by the magnitude of the corresponding V2BR value and will -appear to be ordered in a haphazard manner; (2) the original values of V2BR; -(3) the global ranks corresponding to the original values in V2BR, with ties -reflected appropriately; (4) the global quantiles corresponding to the -original values in V2BR, with ties reflected appropriately; (5) a studyid -vector in which all elements take the value n in the nth study. -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/recodeLevelsDS.Rd b/man/recodeLevelsDS.Rd deleted file mode 100644 index 9067227a..00000000 --- a/man/recodeLevelsDS.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/recodeLevelsDS.R -\name{recodeLevelsDS} -\alias{recodeLevelsDS} -\title{Recodes the levels of a categorical variables} -\usage{ -recodeLevelsDS(x = NULL, classes = NULL) -} -\arguments{ -\item{x}{a factor vector} - -\item{classes}{a character vector the levels of the newt factor vector} -} -\value{ -a factor vector with the new levels -} -\description{ -The functions uses the input factor and generates a new factor -with new levels. -} -\author{ -Gaye, A. -} diff --git a/man/subsetByClassDS.Rd b/man/subsetByClassDS.Rd deleted file mode 100644 index c56e6537..00000000 --- a/man/subsetByClassDS.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/subsetByClassDS.R -\name{subsetByClassDS} -\alias{subsetByClassDS} -\title{Breaks down a dataframe or a factor into its sub-classes} -\usage{ -subsetByClassDS(data = NULL, variables = NULL) -} -\arguments{ -\item{data}{a string character, the name of the dataframe or the factor vector} - -\item{variables}{a vector of string characters, the names of the the variables to subset on.} -} -\value{ -a list which contains the subsetted datasets -} -\description{ -The function takes a categorical vector or dataframe as input and generates subset(s) -vectors or dataframes for each category. Subsets are considered invalid if they hold between 1 and -4 observations. -} -\details{ -If the input data object is a dataframe it is possible to specify the variables -to subset on. If a subset is not 'valid' all its the values are reported as missing (i.e. NA), -the name of the subsets is labelled as '_INVALID'. If no variables are specified to subset on, -the dataframe will be subset on each of its factor variables. -And if none of the columns holds a factor variable a message is issued as output. A message is also -issued as output if the input vector is not of type factor. -} -\author{ -Gaye, A. -} diff --git a/man/subsetDS.Rd b/man/subsetDS.Rd deleted file mode 100644 index 188d140f..00000000 --- a/man/subsetDS.Rd +++ /dev/null @@ -1,57 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/subsetDS.R -\name{subsetDS} -\alias{subsetDS} -\title{Generates a valid subset of a table or a vector} -\usage{ -subsetDS( - dt = NULL, - complt = NULL, - rs = NULL, - cs = NULL, - lg = NULL, - th = NULL, - varname = NULL -) -} -\arguments{ -\item{dt}{a string character, the name of the dataframe or the factor vector and the range of the subset.} - -\item{complt}{a boolean that tells if the subset to subset should include only complete cases} - -\item{rs}{a vector of two integers that give the range of rows de extract.} - -\item{cs}{a vector of two integers or one or more characters; the indices of the columns to extract or the names of the columns (i.e. -names of the variables to extract).} - -\item{lg}{a character, the logical parameter to use if the user wishes to subset a vector using a logical -operator. This parameter is ignored if the input data is not a vector.} - -\item{th}{a numeric, the threshold to use in conjunction with the logical parameter. This parameter is ignored -if the input data is not a vector.} - -\item{varname}{a character, if the input data is a table, if this parameter is provided along with the 'logical' and 'threshold' -parameters, a subtable is based the threshold applied to the specified variable. This parameter is however ignored if the parameter -'rows' and/or 'cols' are provided.} -} -\value{ -a subset of the vector, matrix or dataframe as specified is stored on the server side -} -\description{ -The function uses the R classical subsetting with squared brackets '[]' and allows also to -subset using a logical operator and a threshold. The object to subset from must be a vector (factor, numeric -or character) or a table (data.frame or matrix). -} -\details{ -If the input data is a table: The user specifies the rows and/or columns to include in the subset if the input -object is a table; the columns can be referred to by their names. The name of a vector (i.e. a variable) can also be provided -with a logical operator and a threshold (see example 3). -If the input data is a vector: when the parameters 'rows', 'logical' and 'threshold' are all provided the last two are ignored ( -'rows' has precedence over the other two parameters then). -If the requested subset is not valid (i.e. contains less than the allowed -number of observations), the subset is not generated, rather a table or a vector of missing values is generated to allow -for any subsequent process using the output of the function to proceed after informing the user via a message. -} -\author{ -Gaye, A. -} diff --git a/man/table2DDS.Rd b/man/table2DDS.Rd deleted file mode 100644 index 2e760e28..00000000 --- a/man/table2DDS.Rd +++ /dev/null @@ -1,31 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/table2DDS.R -\name{table2DDS} -\alias{table2DDS} -\title{table2DDS (aggregate function) called by ds.table2D} -\usage{ -table2DDS(xvect, yvect) -} -\arguments{ -\item{xvect}{a numerical vector with discrete values - usually a factor.} - -\item{yvect}{a numerical vector with discrete values - usually a factor.} -} -\value{ -a list which contains two elements: 'table', the 2-dimensional table and 'message' a message which -informs about the validity of the table. -} -\description{ -This function generates a 2-dimensional contingency table where potentially disclosive cells -(based on a set threshold) are replaced by a missing value ('NA'). -} -\details{ -It generates 2-dimensional contingency tables where valid (non-disclosive) tables are defined -as those where none of their cells have counts between 1 and the set threshold "nfilter.tab". When the output table -is invalid all cells except the total counts are replaced by missing values. Only the total counts are visible -on the table returned to the client side. A message is also returned with the 2-dimensional table; the message -says "invalid table - invalid counts present" if the table is invalid and 'valid table' otherwise. -} -\author{ -Amadou Gaye, Paul Burton, Demetris Avraam for DataSHIELD Development Team -} diff --git a/man/testObjExistsDS.Rd b/man/testObjExistsDS.Rd deleted file mode 100644 index 3c49f15c..00000000 --- a/man/testObjExistsDS.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/testObjExistsDS.R -\name{testObjExistsDS} -\alias{testObjExistsDS} -\title{testObjExistsDS} -\usage{ -testObjExistsDS(test.obj.name = NULL) -} -\arguments{ -\item{test.obj.name}{a client-side provided character string specifying the variable -whose presence is to be tested in each data source} -} -\value{ -List with `test.obj.exists` and `test.obj.class` -} -\description{ -The server-side function called by ds.testObjExists -} -\details{ -Tests whether a given object exists in -all sources. It is called at the end of all -recently written assign functions to check the new (assigned) object has been -created in all sources -} -\author{ -Burton PR -} diff --git a/tests/testthat/test-arg-dataFrameFillDS.R b/tests/testthat/test-arg-dataFrameFillDS.R deleted file mode 100644 index 19c710aa..00000000 --- a/tests/testthat/test-arg-dataFrameFillDS.R +++ /dev/null @@ -1,55 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("dataFrameFillDS::arg::setup") - -# -# Tests -# - -# context("dataFrameFillDS::arg") -test_that("simple dataFrameFillDS, ascending, numeric", { - df <- data.frame(v1 = c(-2.0, -3.0, 4.0, 2.0, 1.0, 0.0, -1.0, 3.0), v2 = c(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)) - allNames.transmit <- "v1,v2,v3,v4,v5,v6,v7" - class.vect.transmit <- "numeric,numeric,numeric,foo,bar,factor,logical" - levels.vec.transmit <- NULL - - expect_error(res <- dataFrameFillDS("df", allNames.transmit, class.vect.transmit, levels.vec.transmit), "Unexpected missing class specified: 'foo'", fixed = TRUE) - - expect_true(! exists("res")) -}) - -test_that("simple dataFrameFillDS, ascending, numeric", { - df <- data.frame(v1 = c(-2.0, -3.0, 4.0, 2.0, 1.0, 0.0, -1.0, 3.0), v2 = c(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)) - allNames.transmit <- "v1,v2,v3,v4,v5,v6,v7" - class.vect.transmit <- "numeric,numeric,numeric,foo,bar,factor,logical" - levels.vec.transmit <- NULL - - expect_error(res <- dataFrameFillDS("df", allNames.transmit, class.vect.transmit, levels.vec.transmit), "Unexpected missing class specified: 'foo'", fixed = TRUE) - - expect_true(! exists("res")) -}) - -# -# Shutdown -# - -# context("dataFrameFillDS::arg::shutdown") - -# -# Done -# - -# context("dataFrameFillDS::arg::done") diff --git a/tests/testthat/test-smk-dataFrameFillDS.R b/tests/testthat/test-smk-dataFrameFillDS.R deleted file mode 100644 index 326c6c85..00000000 --- a/tests/testthat/test-smk-dataFrameFillDS.R +++ /dev/null @@ -1,110 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("dataFrameFillDS::smk::setup") - -# -# Tests -# - -# context("dataFrameFillDS::smk") -test_that("simple dataFrameFillDS, ascending, numeric", { - df <- data.frame(v1 = c(-2.0, -3.0, 4.0, 2.0, 1.0, 0.0, -1.0, 3.0), v2 = c(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)) - allNames.transmit <- "v1,v2,v3,v4,v5,v6,v7" - class.vect.transmit <- "numeric,numeric,numeric,integer,character,factor,logical" - levels.vec.transmit <- "1,2,3" - - res <- dataFrameFillDS("df", allNames.transmit, class.vect.transmit, levels.vec.transmit) - - expect_equal(class(res), "data.frame") - expect_length(res, 7) - - res.colnames <- colnames(res) - expect_length(res.colnames, 7) - expect_equal(res.colnames[1], 'v1') - expect_equal(res.colnames[2], 'v2') - expect_equal(res.colnames[3], 'v3') - expect_equal(res.colnames[4], 'v4') - expect_equal(res.colnames[5], 'v5') - expect_equal(res.colnames[6], 'v6') - expect_equal(res.colnames[7], 'v7') - - expect_length(res$v1, 8) - expect_length(res$v2, 8) - expect_length(res$v3, 8) - expect_length(res$v4, 8) - expect_length(res$v5, 8) - expect_length(res$v6, 8) - expect_length(res$v7, 8) - - expect_equal(class(res$v1), "numeric") - expect_equal(class(res$v2), "numeric") - expect_equal(class(res$v3), "numeric") - expect_equal(class(res$v4), "integer") - expect_equal(class(res$v5), "character") - expect_equal(class(res$v6), "factor") - expect_equal(class(res$v7), "logical") - - expect_equal(res$v1[1], -2.0) - expect_equal(res$v2[1], 0.0) - expect_equal(res$v1[2], -3.0) - expect_equal(res$v2[2], 1.0) - expect_equal(res$v1[3], 4.0) - expect_equal(res$v2[3], 2.0) - expect_equal(res$v1[4], 2.0) - expect_equal(res$v2[4], 3.0) - expect_equal(res$v1[5], 1.0) - expect_equal(res$v2[5], 4.0) - expect_equal(res$v1[6], 0.0) - expect_equal(res$v2[6], 5.0) - expect_equal(res$v1[7], -1.0) - expect_equal(res$v2[7], 6.0) - expect_equal(res$v1[8], 3.0) - expect_equal(res$v2[8], 7.0) - - for (index in 1:8) - { - expect_true(is.na(res$v3[index]), info = paste0('index=', index, ', column=v3')) - expect_true(is.na(res$v4[index]), info = paste0('index=', index, ', column=v4')) - expect_true(is.na(res$v5[index]), info = paste0('index=', index, ', column=v5')) - expect_true(is.na(res$v6[index]), info = paste0('index=', index, ', column=v6')) - expect_true(is.na(res$v7[index]), info = paste0('index=', index, ', column=v7')) - } - - res.v6.levels <- levels(res$v6) - - expect_equal(res.v6.levels[1], "1") - expect_equal(res.v6.levels[2], "2") - expect_equal(res.v6.levels[3], "3") -}) - -test_that("dataFrameFillDS errors when object does not exist", { - expect_error( - dataFrameFillDS("nonexistent_object", "a,b", "numeric,numeric", NULL), - regexp = "does not exist" - ) -}) - -# -# Shutdown -# - -# context("dataFrameFillDS::smk::shutdown") - -# -# Done -# - -# context("dataFrameFillDS::smk::done") diff --git a/tests/testthat/test-smk-messageDS.R b/tests/testthat/test-smk-messageDS.R deleted file mode 100644 index 91ec685b..00000000 --- a/tests/testthat/test-smk-messageDS.R +++ /dev/null @@ -1,92 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("messageDS::smk::setup") - -set.standard.disclosure.settings() - -# -# Tests -# - -# context("messageDS::smk") -test_that("simple messageDS", { - expect_warning(base::rm("object"), "object 'object' not found", fixed = TRUE) - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "Error: the object does not exist in this datasource") -}) - -test_that("simple messageDS", { - object <- NULL - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "ALL OK: there are no studysideMessage(s) on this datasource") -}) - -test_that("simple messageDS", { - object <- list() - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "Outcome object is a list without names. So a studysideMessage may be hidden. Please check output is OK") -}) - - -test_that("simple messageDS", { - object <- list("a", "b", "c", "d") - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "Outcome object is a list without names. So a studysideMessage may be hidden. Please check output is OK") -}) - -test_that("simple messageDS", { - object <- list(v1 = "a", v2 = "b", v3 = "c", v4 = "d") - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "ALL OK: there are no studysideMessage(s) on this datasource") -}) - -test_that("simple messageDS", { - object <- list(v1 = "a", v2 = "b", studysideMessage = "message", v3 = "c", v4 = "d") - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "NOT ALL OK: there are studysideMessage(s) on this datasource") -}) - -# -# Done -# - -# context("messageDS::smk::shutdown") - -# context("messageDS::smk::done") diff --git a/tests/testthat/test-smk-minMaxRandDS.R b/tests/testthat/test-smk-minMaxRandDS.R deleted file mode 100644 index 0e057e5a..00000000 --- a/tests/testthat/test-smk-minMaxRandDS.R +++ /dev/null @@ -1,38 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("minMaxRandDS::smk::setup") - -# -# Tests -# - -test_that("minMaxRandDS", { - input <- read.csv(file = 'data_files/DASIM/DASIM1.csv') - - res <- minMaxRandDS(input) - - expect_equal(class(res), "numeric") - expect_length(res, 2) - expect_true("numeric" %in% class(res[1])) - expect_true("numeric" %in% class(res[2])) -}) - -# -# Done -# - -# context("minMaxRandDS::smk::shutdown") - -# context("minMaxRandDS::smk::done") diff --git a/tests/testthat/test-smk-recodeLevelsDS.R b/tests/testthat/test-smk-recodeLevelsDS.R deleted file mode 100644 index 9e365836..00000000 --- a/tests/testthat/test-smk-recodeLevelsDS.R +++ /dev/null @@ -1,47 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("recodeLevelsDS::smk::setup") - -# -# Tests -# - -test_that("simple recodeLevelsDS", { - input <- c(1, 2, 3, 4, 1, 3) - classes <- c("one", "two", "three", "four") - - res <- recodeLevelsDS(input, classes) - - expect_equal(class(res), "numeric") - expect_length(res, 6) - - res.levels <- levels(res) - - expect_equal(class(res.levels), "character") - expect_length(res.levels, 4) - expect_equal(res.levels[1], "one") - expect_equal(res.levels[2], "two") - expect_equal(res.levels[3], "three") - expect_equal(res.levels[4], "four") -}) - -# -# Done -# - -# context("recodeLevelsDS::smk::shutdown") - -# context("recodeLevelsDS::smk::done") diff --git a/tests/testthat/test-smk-subsetByClassDS.R b/tests/testthat/test-smk-subsetByClassDS.R deleted file mode 100644 index 82ccab5d..00000000 --- a/tests/testthat/test-smk-subsetByClassDS.R +++ /dev/null @@ -1,88 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("subsetByClassDS::smk::setup") - -set.standard.disclosure.settings() - -# -# Tests -# - -# context("subsetByClassDS::smk") -test_that("simple subsetByClassDS, data.frame, unspecified variables", { - data <- data.frame(v1 = factor(c(0, 0, 0, 1, 1, 1, 2, 1, 2, 2)), v2 = c(4.0, 0.0, 3.0, 1.0, 2.0, 2.0, 1.0, 3.0, 0.0, 4.0), v3 = c(1:10), v4 = c(1:10)) - variables <- NULL - - res <- subsetByClassDS("data", variables) - - expect_equal(class(res), "list") - expect_length(res, 3) - - expect_equal(class(res$v1.level_0), "data.frame") - expect_length(res$v1.level_0, 4) - - expect_equal(class(res$v1.level_1), "data.frame") - expect_length(res$v1.level_1, 4) - - expect_equal(class(res$v1.level_2), "data.frame") - expect_length(res$v1.level_2, 4) -}) - -test_that("simple subsetByClassDS, data.frame, specified variables", { - data <- data.frame(v1 = factor(c(0, 0, 0, 1, 1, 1, 2, 1, 2, 2)), v2 = c(4.0, 0.0, 3.0, 1.0, 2.0, 2.0, 1.0, 3.0, 0.0, 4.0), v3 = c(1:10), v4 = c(1:10)) - variables <- c("v1") - - res <- subsetByClassDS("data", variables) - - expect_equal(class(res), "list") - expect_length(res, 3) - - expect_equal(class(res$v1.level_0), "data.frame") - expect_length(res$v1.level_0, 4) - - expect_equal(class(res$v1.level_1), "data.frame") - expect_length(res$v1.level_1, 4) - - expect_equal(class(res$v1.level_2), "data.frame") - expect_length(res$v1.level_2, 4) -}) - -test_that("simple subsetByClassDS, factor vector, specified variables", { - data <- factor(c(0, 0, 0, 1, 1, 1, 2, 1, 2, 2)) - variables <- NULL - - res <- subsetByClassDS("data", variables) - - expect_equal(class(res), "list") - expect_length(res, 3) - - expect_equal(class(res$data.level_0), "factor") - expect_length(res$data.level_0, 3) - - expect_equal(class(res$data.level_1), "factor") - expect_length(res$data.level_1, 4) - - expect_equal(class(res$data.level_2), "factor") - expect_length(res$data.level_2, 3) -}) - -# -# Done -# - -# context("subsetByClassDS::smk::shutdown") - -# context("subsetByClassDS::smk::done") diff --git a/tests/testthat/test-smk-subsetDS.R b/tests/testthat/test-smk-subsetDS.R deleted file mode 100644 index 53d291c4..00000000 --- a/tests/testthat/test-smk-subsetDS.R +++ /dev/null @@ -1,126 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("subsetDS::smk::setup") - -set.standard.disclosure.settings() - -# -# Tests -# - -# context("subsetDS::smk") -test_that("simple subsetDS, no NAs", { - data <- data.frame(v1 = c(0, 0, 1, 1, 2, 2, 3, 3, 4, 4), v2 = c(4.0, 0.0, 3.0, 1.0, 2.0, 2.0, 1.0, 3.0, 0.0, 4.0)) - complt <- FALSE - rs <- NULL - cs <- NULL - lg <- 2 - th <- 2 - varname <- "v1" - - res <- subsetDS("data", complt, rs, cs, lg, th, varname) - - expect_equal(class(res), "data.frame") - expect_length(res, 2) - - expect_equal(class(res$v1), "numeric") - expect_length(res$v1, 6) - expect_equal(res$v1[1], 2) - expect_equal(res$v1[2], 2) - expect_equal(res$v1[3], 3) - expect_equal(res$v1[4], 3) - expect_equal(res$v1[5], 4) - expect_equal(res$v1[6], 4) - - expect_equal(class(res$v2), "numeric") - expect_length(res$v2, 6) - expect_equal(res$v2[1], 2.0) - expect_equal(res$v2[2], 2.0) - expect_equal(res$v2[3], 1.0) - expect_equal(res$v2[4], 3.0) - expect_equal(res$v2[5], 0.0) - expect_equal(res$v2[6], 4.0) -}) - -test_that("simple subsetDS, NAs, complete.case FALSE", { - data <- data.frame(v1 = c(0, 0, 1, 1, 2, 2, 3, 3, 4, 4), v2 = c(4.0, 0.0, 3.0, 1.0, 2.0, 2.0, 1.0, NA, NA, 4.0)) - complt <- FALSE - rs <- NULL - cs <- NULL - lg <- 2 - th <- 2 - varname <- "v1" - - res <- subsetDS("data", complt, rs, cs, lg, th, varname) - - expect_equal(class(res), "data.frame") - expect_length(res, 2) - - expect_equal(class(res$v1), "numeric") - expect_length(res$v1, 6) - expect_equal(res$v1[1], 2) - expect_equal(res$v1[2], 2) - expect_equal(res$v1[3], 3) - expect_equal(res$v1[4], 3) - expect_equal(res$v1[5], 4) - expect_equal(res$v1[6], 4) - - expect_equal(class(res$v2), "numeric") - expect_length(res$v2, 6) - expect_equal(res$v2[1], 2.0) - expect_equal(res$v2[2], 2.0) - expect_equal(res$v2[3], 1.0) - expect_true(is.na(res$v2[4])) - expect_true(is.na(res$v2[5])) - expect_equal(res$v2[6], 4.0) -}) - -test_that("simple subsetDS, NAs, complete.case TRUE", { - data <- data.frame(v1 = c(0, 0, 1, 1, 2, 2, 3, 3, 4, 4), v2 = c(4.0, 0.0, 3.0, 1.0, 2.0, 2.0, 1.0, NA, NA, 4.0)) - complt <- TRUE - rs <- NULL - cs <- NULL - lg <- 2 - th <- 2 - varname <- "v1" - - res <- subsetDS("data", complt, rs, cs, lg, th, varname) - - expect_equal(class(res), "data.frame") - expect_length(res, 2) - - expect_equal(class(res$v1), "numeric") - expect_length(res$v1, 4) - expect_equal(res$v1[1], 2) - expect_equal(res$v1[2], 2) - expect_equal(res$v1[3], 3) - expect_equal(res$v1[4], 4) - - expect_equal(class(res$v2), "numeric") - expect_length(res$v2, 4) - expect_equal(res$v2[1], 2.0) - expect_equal(res$v2[2], 2.0) - expect_equal(res$v2[3], 1.0) - expect_equal(res$v2[4], 4.0) -}) - -# -# Done -# - -# context("subsetDS::smk::shutdown") - -# context("subsetDS::smk::done") diff --git a/tests/testthat/test-smk-testObjExistsDS.R b/tests/testthat/test-smk-testObjExistsDS.R deleted file mode 100644 index 705948d0..00000000 --- a/tests/testthat/test-smk-testObjExistsDS.R +++ /dev/null @@ -1,270 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("testObjExistsDS::smk::setup") - -# -# Tests -# - -# context("testObjExistsDS::smk::character") -test_that("simple testObjExistsDS, character", { - input <- "value" - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "character") -}) - -test_that("simple testObjExistsDS, character vector", { - input <- c("value1", "value2", "value3", "value4") - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "character") -}) - -# context("testObjExistsDS::smk::integer") -test_that("simple testObjExistsDS, integer", { - input <- 1L - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "integer") -}) - -test_that("simple testObjExistsDS, integer vector", { - input <- c(1L, 2L, 3L, 4L) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "integer") -}) - -# context("testObjExistsDS::smk::numeric") -test_that("simple testObjExistsDS, numeric", { - input <- 1.1 - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "numeric") -}) - -test_that("simple testObjExistsDS, numeric vector", { - input <- c(1.1, 2.1, 3.1, 4.1) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "numeric") -}) - -# context("testObjExistsDS::smk::logical") -test_that("simple testObjExistsDS, logical, FALSE", { - input <- FALSE - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "logical") -}) - -test_that("simple testObjExistsDS, logical, TRUE", { - input <- TRUE - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "logical") -}) - -test_that("simple testObjExistsDS, logical vector", { - input <- c(FALSE, TRUE, FALSE, TRUE) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "logical") -}) - -# context("testObjExistsDS::smk::data.frame") -test_that("simple testObjExistsDS, data.frame", { - input <- data.frame(v1 = c(0.0, 1.0, 2.0, 3.0, 4.0), v2 = c(4.0, 3.0, 2.0, 1.0, 0.0)) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "data.frame") -}) - -# context("testObjExistsDS::smk::array") -test_that("simple testObjExistsDS, array", { - input <- array(c(0.0, 1.0, 2.0, 3.0, 4.0)) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "array") -}) - -# context("testObjExistsDS::smk::matrix") -test_that("simple testObjExistsDS, matrix", { - input <- matrix(c(0.0, 1.0, 2.0, 3.0, 4.0)) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - if (base::getRversion() < '4.0.0') - { - expect_length(res$test.obj.class, 1) - expect_true("matrix" %in% res$test.obj.class) - } - else - { - expect_length(res$test.obj.class, 2) - expect_true("matrix" %in% res$test.obj.class) - expect_true("array" %in% res$test.obj.class) - } -}) - -# context("testObjExistsDS::smk::data.matrix") -test_that("simple testObjExistsDS, data.matrix", { - input <- data.matrix(data.frame(v1 = c(0.0, 1.0, 2.0, 3.0, 4.0), v2 = c(4.0, 3.0, 2.0, 1.0, 0.0))) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - - if (base::getRversion() < '4.0.0') - { - expect_length(res$test.obj.class, 1) - expect_true("matrix" %in% res$test.obj.class) - } - else - { - expect_length(res$test.obj.class, 2) - expect_true("matrix" %in% res$test.obj.class) - expect_true("array" %in% res$test.obj.class) - } -}) - -# context("testObjExistsDS::smk::date") -test_that("simple testObjExistsDS, date", { - input <- Sys.Date() - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "Date") -}) - -# context("testObjExistsDS::smk::formula") -test_that("simple testObjExistsDS, formula", { - input <- X ~ A + B - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "formula") -}) - -# context("testObjExistsDS::smk::environment") -test_that("simple testObjExistsDS, environment", { - input <- environment() - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "environment") -}) - -# context("testObjExistsDS::smk::NA") -test_that("special testObjExistsDS, NA", { - input <- NA - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "logical") -}) - -# context("testObjExistsDS::smk::NULL") -test_that("special testObjExistsDS, NULL", { - input <- NULL - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "NULL") -}) - -# context("testObjExistsDS::smk::not exists") -test_that("special testObjExistsDS, not exists", { - res <- testObjExistsDS("XXXinputXXX") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, FALSE) - expect_equal(res$test.obj.class, NULL) -}) - -# -# Done -# - -# context("testObjExistsDS::smk::shutdown") - -# context("testObjExistsDS::smk::done") From 6ec4f2fb5ed09f8b31752baf2577962594fe291e Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Wed, 21 Oct 2026 11:22:35 +0100 Subject: [PATCH 32/38] Removed 'PULL_REQUEST_TEMPLATE.md' --- PULL_REQUEST_TEMPLATE.md | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 PULL_REQUEST_TEMPLATE.md diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1cbc8c4a..00000000 --- a/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,20 +0,0 @@ -## Instructions & checklist for PR author - -### Description of changes -[Add descriptions of changes made] - -### Refactor instructions -- [ ] Replaced `x <- eval(parse(text = x.name), envir = parent.frame())` with `x <- .loadServersideObject(x)` -- [ ] If necessary, check the class of the object using `.checkClass()` - -### Testing instructions -- [ ] Writen server-side unit tests for unhappy flow -- [ ] Run `devtools::test(filter = "smk-|disc|arg")` and check it passes -- [ ] Run `devtools::check(args = '--no-tests')` and check it passes (we run tests separately to skip performance checks) -- [ ] Run `devtools::build()` and check it builds without errors - -## Instructions & checklist for PR reviewers -- [ ] Run `devtools::test(filter = "smk-|disc|arg")` and check it passes -- [ ] Run `devtools::check(args = '--no-tests')` and check it passes (we run tests separately to skip performance checks) -- [ ] Run `devtools::build()` and check it builds without errors - From cd69354238d3483985e78b5e272bcd0e88dedd46 Mon Sep 17 00:00:00 2001 From: Stuart Wheater Date: Wed, 21 Oct 2026 12:00:13 +0100 Subject: [PATCH 33/38] Upgrade to 'roxygen2' version: 8.1.1 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d733e042..f3411680 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -82,4 +82,4 @@ Suggests: Encoding: UTF-8 Language: en-GB Config/testthat/edition: 3 -Config/roxygen2/version: 8.1.0 +Config/roxygen2/version: 8.1.1 From 6bed97d0958a25a7148714591551729400dccf46 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Fri, 23 Oct 2026 13:21:38 +0200 Subject: [PATCH 34/38] last couple of fixes --- R/corDS.R | 6 +++--- R/covDS.R | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/corDS.R b/R/corDS.R index 9653900a..aba34ece 100644 --- a/R/corDS.R +++ b/R/corDS.R @@ -30,17 +30,17 @@ corDS <- function(x=NULL, y=NULL){ ############################################################# x.val <- .loadServersideObject(x) - .checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) + .checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "factor", "matrix", "data.frame")) if (!is.null(y) && !any(class(x.val) %in% c("matrix", "data.frame"))){ y.val <- .loadServersideObject(y) - .checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) + .checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "factor", "matrix", "data.frame")) } else{ y.val <- NULL } - if (is.null(y.val) && any(class(x.val) %in% c("numeric", "integer"))) { + if (is.null(y.val) && any(class(x.val) %in% c("numeric", "integer", "factor"))) { stop("If x is a numeric vector, y must also be a numeric vector.", call. = FALSE) } diff --git a/R/covDS.R b/R/covDS.R index 84f8f66b..d31858dd 100644 --- a/R/covDS.R +++ b/R/covDS.R @@ -39,17 +39,17 @@ covDS <- function(x=NULL, y=NULL, use=NULL){ ############################################################# x.val <- .loadServersideObject(x) - .checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) + .checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "factor", "matrix", "data.frame")) if (!is.null(y) && !any(class(x.val) %in% c("matrix", "data.frame"))){ y.val <- .loadServersideObject(y) - .checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) + .checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "factor", "matrix", "data.frame")) } else{ y.val <- NULL } - if (is.null(y.val) && any(class(x.val) %in% c("numeric", "integer"))) { + if (is.null(y.val) && any(class(x.val) %in% c("numeric", "integer", "factor"))) { stop("If x is a numeric vector, y must also be a numeric vector.", call. = FALSE) } From d12edd16fa6867bc3f95aff8daf5dcfd3533c034 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Fri, 23 Oct 2026 13:21:48 +0200 Subject: [PATCH 35/38] remove asList from aggregate methods --- inst/DATASHIELD | 1 - 1 file changed, 1 deletion(-) diff --git a/inst/DATASHIELD b/inst/DATASHIELD index 7835a403..3e08f68e 100644 --- a/inst/DATASHIELD +++ b/inst/DATASHIELD @@ -1,6 +1,5 @@ AggregateMethods: asFactorDS1, - asListDS, aucDS, boxPlotGGDS, checkNegValueDS, From 411a74fb97749ad891a40b19e0ae66f1777fbb47 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Fri, 23 Oct 2026 13:21:54 +0200 Subject: [PATCH 36/38] update tests --- tests/testthat/test-smk-corDS.R | 10 ++++++++++ tests/testthat/test-smk-covDS.R | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/testthat/test-smk-corDS.R b/tests/testthat/test-smk-corDS.R index ba51e096..059be9ad 100644 --- a/tests/testthat/test-smk-corDS.R +++ b/tests/testthat/test-smk-corDS.R @@ -764,6 +764,16 @@ test_that("corDS gives the same result for a matrix as for a data.frame", { expect_equal(res.matrix[names(res.matrix) != "class"], res.df[names(res.df) != "class"]) }) +test_that("corDS accepts a factor x, correlating on its level codes", { + fvar <- factor(c("m", "f", "m", "f", "m", "f", "m", "f", "m", "f")) + yvar <- c(1.0, 5.0, 2.0, 6.0, 3.0, 7.0, 2.0, 8.0, 1.0, 9.0) + + res <- corDS("fvar", "yvar") + + expect_equal(res$class, "factor") + expect_equal(res$sums[1, 2], sum(as.integer(fvar))) +}) + # # Done # diff --git a/tests/testthat/test-smk-covDS.R b/tests/testthat/test-smk-covDS.R index d44f98bb..9bb4e517 100644 --- a/tests/testthat/test-smk-covDS.R +++ b/tests/testthat/test-smk-covDS.R @@ -278,6 +278,16 @@ test_that("covDS gives the same result for a matrix as for a data.frame", { expect_equal(res.matrix[names(res.matrix) != "class"], res.df[names(res.df) != "class"]) }) +test_that("covDS accepts a factor x, using its level codes", { + fvar <- factor(c("m", "f", "m", "f", "m", "f", "m", "f", "m", "f")) + yvar <- c(1.0, 5.0, 2.0, 6.0, 3.0, 7.0, 2.0, 8.0, 1.0, 9.0) + + res <- covDS("fvar", "yvar", "pairwise.complete") + + expect_equal(res$class, "factor") + expect_equal(res$sums[1, 2], sum(as.integer(fvar))) +}) + # # Done # From d71fcf61787ce26ba4d410806861edcf55349b8c Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Thu, 29 Oct 2026 11:31:33 +0100 Subject: [PATCH 37/38] update and pin lme4 version and fix tests as estimates slightly changed --- DESCRIPTION | 2 +- R/glmSLMADS.assign.R | 4 ++-- tests/testthat/test-smk-glmerSLMADS.assign.R | 4 ++-- tests/testthat/test-smk-glmerSLMADS2.R | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f3411680..81cc2e1c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -63,7 +63,7 @@ Depends: Imports: RANN, stringr, - lme4, + lme4 (>= 2.1-0), dplyr, tibble, purrr, diff --git a/R/glmSLMADS.assign.R b/R/glmSLMADS.assign.R index 68fe6929..3448aed3 100644 --- a/R/glmSLMADS.assign.R +++ b/R/glmSLMADS.assign.R @@ -27,10 +27,10 @@ glmSLMADS.assign <- function(formula, family, offsetName, weightsName, dataName) # Correctly name offset, weights and data objects in function call # (to allow glmPredict to work correctly later) - calltext <- paste0("mg<-glm(formula,family=",family,",offset=", + calltext <- paste0("glm(formula,family=",family,",offset=", offsetName,",weights=",weightsName,",data=", dataName,",x=TRUE)") - eval(parse(text=calltext)) + mg <- eval(parse(text=calltext), envir = list(formula = formula), enclos = parent.frame()) # update the call object to include the actual formula mg$call$formula <- formula diff --git a/tests/testthat/test-smk-glmerSLMADS.assign.R b/tests/testthat/test-smk-glmerSLMADS.assign.R index 9277ffad..e675bb9d 100644 --- a/tests/testthat/test-smk-glmerSLMADS.assign.R +++ b/tests/testthat/test-smk-glmerSLMADS.assign.R @@ -29,10 +29,10 @@ test_that("simple glmerSLMADS.assign, binomial random intercept", { expect_true(methods::is(res, "glmerMod")) expect_equal(nobs(res), 50) - expect_equal(as.numeric(lme4::fixef(res)), c(-1.4299523, 0.2248647), tolerance = 1e-5) + expect_equal(as.numeric(lme4::fixef(res)), c(-1.4340652, 0.2255225), tolerance = 1e-5) vc <- as.data.frame(lme4::VarCorr(res)) - expect_equal(vc$vcov, 2.7451347, tolerance = 1e-5) + expect_equal(vc$vcov, 2.7493590, tolerance = 1e-5) }) test_that("glmerSLMADS.assign throws error when dataName does not exist", { diff --git a/tests/testthat/test-smk-glmerSLMADS2.R b/tests/testthat/test-smk-glmerSLMADS2.R index 94821cea..adb47e47 100644 --- a/tests/testthat/test-smk-glmerSLMADS2.R +++ b/tests/testthat/test-smk-glmerSLMADS2.R @@ -35,7 +35,7 @@ test_that("simple glmerSLMADS2, binomial random intercept", { expect_equal(res$Nmissing, 0) expect_equal(dim(res$coefficients), c(2, 4)) expect_equal(res$coefficients[, "Estimate"], - c(`(Intercept)` = -1.4299523, x = 0.2248647), tolerance = 1e-5) + c(`(Intercept)` = -1.4340652, x = 0.2255225), tolerance = 1e-5) expect_equal(res$family, "binomial") }) From 0f719041d42e354b7815b5f7e7687d293589c0d3 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Thu, 29 Oct 2026 18:31:27 +0100 Subject: [PATCH 38/38] List the calling environment in lsDS --- R/lsDS.R | 10 ++++------ tests/testthat/test-smk-lsDS.R | 13 +++++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/R/lsDS.R b/R/lsDS.R index 7558b8e0..e75b4141 100644 --- a/R/lsDS.R +++ b/R/lsDS.R @@ -37,11 +37,9 @@ nfilter.string<-as.numeric(thr$nfilter.string) # #datashield.privacyLevel<-as.numeric(thr$datashield.privacyLevel) # ######################################################################### -envir.text<-".GlobalEnv" - if(env.to.search==1L) { -envir.2.search<-eval(parse(text=envir.text)) +envir.2.search<-parent.frame() }else{ envir.2.search<-as.environment(env.to.search) } @@ -51,7 +49,7 @@ j<-0 if(is.null(search.filter)) { -outobj<-ls(pos=env.to.search) +outobj<-ls(envir=envir.2.search) outlist<-list(environment.searched=environmentName(envir.2.search),objects.found=outobj) @@ -92,10 +90,10 @@ return(outlist) search.filter.final<-paste(search.filter.temp1,collapse="") - outobj<-ls(pos=env.to.search,pattern=utils::glob2rx(search.filter.final)) + outobj<-ls(envir=envir.2.search,pattern=utils::glob2rx(search.filter.final)) }else{ - outobj<-ls(pos=env.to.search,pattern=utils::glob2rx(search.filter)) + outobj<-ls(envir=envir.2.search,pattern=utils::glob2rx(search.filter)) search.filter.final<-search.filter } diff --git a/tests/testthat/test-smk-lsDS.R b/tests/testthat/test-smk-lsDS.R index b96eb0ec..4427f195 100644 --- a/tests/testthat/test-smk-lsDS.R +++ b/tests/testthat/test-smk-lsDS.R @@ -28,7 +28,7 @@ test_that("simple lsDS", { search.filter <- NULL env.to.search <- 1L - res <- lsDS(search.filter, env.to.search) + res <- eval(call("lsDS", search.filter, env.to.search), envir = .GlobalEnv) expect_equal(class(res), "list") expect_length(res, 2) @@ -44,7 +44,7 @@ test_that("simple lsDS", { search.filter <- "_:A:_" env.to.search <- 1L - res <- lsDS(search.filter, env.to.search) + res <- eval(call("lsDS", search.filter, env.to.search), envir = .GlobalEnv) expect_equal(class(res), "list") expect_length(res, 3) @@ -55,6 +55,15 @@ test_that("simple lsDS", { expect_equal(res$search.filter.final, "*") }) +# context("lsDS::smk::calling environment") +test_that("lsDS lists the environment it is called from", { + local.obj <- "value" + + res <- lsDS(NULL, 1L) + + expect_true("local.obj" %in% res$objects.found) +}) + # # Done #