Skip to content

Commit b2c00a5

Browse files
Merge branch 'datashield:v7.0-dev' into v7.0-dev
2 parents bc1e6cc + 0e88c63 commit b2c00a5

92 files changed

Lines changed: 1143 additions & 1215 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

R/ds.cor.R

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
#' @param datasources a list of \code{\link[DSI]{DSConnection-class}} objects obtained after login.
3131
#' If the \code{datasources} argument is not specified
3232
#' the default set of connections will be used: see \code{\link[DSI]{datashield.connections_default}}.
33+
#' @template classConsistencyCheckTrue
3334
#' @return \code{ds.cor} returns a list containing the number of missing values in each variable,
3435
#' the number of missing variables casewise, the correlation matrix,
3536
#' the number of used complete cases. The function applies two disclosure controls. The first disclosure
3637
#' control checks that the number of variables is not bigger than a percentage of the individual-level records (the allowed
3738
#' percentage is pre-specified by the 'nfilter.glm'). The second disclosure control checks that none of them is dichotomous
3839
#' with a level having fewer counts than the pre-specified 'nfilter.tab' threshold.
3940
#' @author DataSHIELD Development Team
41+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
4042
#' @examples
4143
#' \dontrun{
4244
#'
@@ -79,56 +81,25 @@
7981
#' }
8082
#' @export
8183
#'
82-
ds.cor <- function(x=NULL, y=NULL, type="split", datasources=NULL){
84+
ds.cor <- function(x=NULL, y=NULL, type="split", datasources=NULL, classConsistencyCheck=TRUE){
8385

84-
# look for DS connections
85-
if(is.null(datasources)){
86-
datasources <- datashield.connections_find()
87-
}
88-
89-
# ensure datasources is a list of DSConnection-class
90-
if(!(is.list(datasources) && all(unlist(lapply(datasources, function(d) {methods::is(d,"DSConnection")}))))){
91-
stop("The 'datasources' were expected to be a list of DSConnection-class objects", call.=FALSE)
92-
}
86+
datasources <- .set_datasources(datasources)
9387

9488
if(is.null(x)){
9589
stop("x=NULL. Please provide the name of a matrix or dataframe or the names of two numeric vectors!", call.=FALSE)
96-
}else{
97-
isDefined(datasources, x)
98-
}
99-
100-
# check the type of the input objects
101-
typ <- checkClass(datasources, x)
102-
103-
if(('numeric' %in% typ) | ('integer' %in% typ) | ('factor' %in% typ)){
104-
if(is.null(y)){
105-
stop("If x is a numeric vector, y must be a numeric vector!", call.=FALSE)
106-
}else{
107-
isDefined(datasources, y)
108-
typ2 <- checkClass(datasources, y)
109-
}
110-
}
111-
112-
if(('matrix' %in% typ) | ('data.frame' %in% typ) & !(is.null(y))){
113-
y <- NULL
114-
warning("x is a matrix or a dataframe; y will be ignored and a correlation matrix computed for x!")
11590
}
11691

11792
# name of the studies to be used in the output
11893
stdnames <- names(datasources)
11994

12095
# call the server side function
121-
if(('matrix' %in% typ) | ('data.frame' %in% typ)){
122-
calltext <- call("corDS", x, NULL)
123-
}else{
124-
if(!(is.null(y))){
125-
calltext <- call("corDS", x, y)
126-
}else{
127-
calltext <- call("corDS", x, NULL)
128-
}
129-
}
96+
calltext <- call("corDS", x, y)
13097
output <- DSI::datashield.aggregate(datasources, calltext)
131-
98+
99+
if(classConsistencyCheck){
100+
.checkClassConsistency(output)
101+
}
102+
132103
if (type=="split"){
133104
covariance <- list()
134105
sqrt.diag <- list()

R/ds.corTest.R

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
#' @param datasources a list of \code{\link[DSI]{DSConnection-class}}
2323
#' objects obtained after login. If the \code{datasources} argument is not specified
2424
#' the default set of connections will be used: see \code{\link[DSI]{datashield.connections_default}}.
25+
#' @template classConsistencyCheckFalse
2526
#' @return \code{ds.corTest} returns to the client-side the results of the correlation test.
2627
#' @author DataSHIELD Development Team
28+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
2729
#' @export
2830
#' @examples
2931
#' \dontrun{
@@ -63,17 +65,9 @@
6365
#'
6466
#' }
6567
#'
66-
ds.corTest <- function(x=NULL, y=NULL, method="pearson", exact=NULL, conf.level=0.95, type='split', datasources=NULL){
68+
ds.corTest <- function(x=NULL, y=NULL, method="pearson", exact=NULL, conf.level=0.95, type='split', datasources=NULL, classConsistencyCheck=FALSE){
6769

68-
# look for DS connections
69-
if(is.null(datasources)){
70-
datasources <- datashield.connections_find()
71-
}
72-
73-
# ensure datasources is a list of DSConnection-class
74-
if(!(is.list(datasources) && all(unlist(lapply(datasources, function(d) {methods::is(d,"DSConnection")}))))){
75-
stop("The 'datasources' were expected to be a list of DSConnection-class objects", call.=FALSE)
76-
}
70+
datasources <- .set_datasources(datasources)
7771

7872
if(is.null(x)){
7973
stop("x=NULL. Please provide the names of the 1st numeric vector!", call.=FALSE)
@@ -85,19 +79,18 @@ ds.corTest <- function(x=NULL, y=NULL, method="pearson", exact=NULL, conf.level=
8579
if(!(method %in% c("pearson", "kendall", "spearman"))){
8680
stop('Function argument "method" has to be either "pearson", "kendall" or "spearman"', call.=FALSE)
8781
}
88-
89-
# check if the input objects are defined in all the studies
90-
isDefined(datasources, x)
91-
isDefined(datasources, y)
92-
93-
# call the internal function that checks the input objects are of the same class in all studies.
94-
typ <- checkClass(datasources, x)
95-
typ <- checkClass(datasources, y)
9682

9783
# call the server side function
9884
cally <- call("corTestDS", x, y, method, exact, conf.level)
9985
out <- DSI::datashield.aggregate(datasources, cally)
10086

87+
if(classConsistencyCheck){
88+
.checkClassConsistency(out)
89+
}
90+
91+
# strip class field from results before returning
92+
out <- lapply(out, function(r) { r$class <- NULL; r })
93+
10194
if(type=="split"){
10295
return(out)
10396
}else{

R/ds.cov.R

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#' \code{'pairwise.complete'}. Default \code{'pairwise.complete'}. For more information see details.
3636
#' @param type a character string that represents the type of analysis to carry out.
3737
#' This must be set to \code{'split'} or \code{'combine'}. Default \code{'split'}. For more information see details.
38+
#' @template classConsistencyCheckTrue
3839
#' @param datasources a list of \code{\link[DSI]{DSConnection-class}} objects obtained after login.
3940
#' If the \code{datasources} argument is not specified
4041
#' the default set of connections will be used: see \code{\link[DSI]{datashield.connections_default}}.
@@ -47,6 +48,7 @@
4748
#' the disclosure controls then all the output values are replaced with NAs. If all the variables are valid and pass
4849
#' the controls, then the output matrices are returned and also an error message is returned but it is replaced by NA.
4950
#' @author DataSHIELD Development Team
51+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
5052
#' @examples
5153
#' \dontrun{
5254
#'
@@ -96,56 +98,25 @@
9698
#' }
9799
#' @export
98100
#'
99-
ds.cov <- function(x=NULL, y=NULL, naAction='pairwise.complete', type="split", datasources=NULL){
101+
ds.cov <- function(x=NULL, y=NULL, naAction='pairwise.complete', type="split", datasources=NULL, classConsistencyCheck=TRUE){
100102

101-
# look for DS connections
102-
if(is.null(datasources)){
103-
datasources <- datashield.connections_find()
104-
}
105-
106-
# ensure datasources is a list of DSConnection-class
107-
if(!(is.list(datasources) && all(unlist(lapply(datasources, function(d) {methods::is(d,"DSConnection")}))))){
108-
stop("The 'datasources' were expected to be a list of DSConnection-class objects", call.=FALSE)
109-
}
103+
datasources <- .set_datasources(datasources)
110104

111105
if(is.null(x)){
112106
stop("x=NULL. Please provide the name of a matrix or dataframe or the names of two numeric vectors!", call.=FALSE)
113-
}else{
114-
isDefined(datasources, x)
115-
}
116-
117-
# check the type of the input objects
118-
typ <- checkClass(datasources, x)
119-
120-
if(('numeric' %in% typ) | ('integer' %in% typ) | ('factor' %in% typ)){
121-
if(is.null(y)){
122-
stop("If x is a numeric vector, y must be a numeric vector!", call.=FALSE)
123-
}else{
124-
isDefined(datasources, y)
125-
typ2 <- checkClass(datasources, y)
126-
}
127-
}
128-
129-
if(('matrix' %in% typ) | ('data.frame' %in% typ) & !(is.null(y))){
130-
y <- NULL
131-
warning("x is a matrix or a dataframe; y will be ignored and a covariance matrix computed for x!")
132107
}
133108

134109
# name of the studies to be used in the output
135110
stdnames <- names(datasources)
136111

137112
# call the server side function
138-
if(('matrix' %in% typ) | ('data.frame' %in% typ)){
139-
calltext <- call("covDS", x, NULL, naAction)
140-
}else{
141-
if(!(is.null(y))){
142-
calltext <- call("covDS", x, y, naAction)
143-
}else{
144-
calltext <- call("covDS", x, NULL, naAction)
145-
}
146-
}
113+
calltext <- call("covDS", x, y, naAction)
147114
output <- DSI::datashield.aggregate(datasources, calltext)
148-
115+
116+
if(classConsistencyCheck){
117+
.checkClassConsistency(output)
118+
}
119+
149120
if (type=="split"){
150121
covariance <- list()
151122
results <- list()

R/ds.dim.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' the dimension is returned separately for each study.
1818
#' If \code{type} is set to \code{'both'} or \code{'b'}, both sets of outputs are produced.
1919
#' Default \code{'both'}.
20-
#' @template classConsistencyCheck
20+
#' @template classConsistencyCheckTrue
2121
#' @param datasources a list of \code{\link[DSI]{DSConnection-class}}
2222
#' objects obtained after login. If the \code{datasources} argument is not specified
2323
#' the default set of connections will be used: see \code{\link[DSI]{datashield.connections_default}}.
@@ -78,7 +78,7 @@
7878
#'
7979
#' }
8080
#'
81-
ds.dim <- function(x=NULL, type='both', classConsistencyCheck=TRUE, datasources=NULL) {
81+
ds.dim <- function(x=NULL, type='both', datasources=NULL, classConsistencyCheck=TRUE) {
8282

8383
datasources <- .set_datasources(datasources)
8484

R/ds.isNA.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#'
99
#' Server function called: \code{isNaDS}
1010
#' @param x a character string specifying the name of the vector to check.
11-
#' @template classConsistencyCheck
11+
#' @template classConsistencyCheckTrue
1212
#' @param datasources a list of \code{\link[DSI]{DSConnection-class}}
1313
#' objects obtained after login. If the \code{datasources} argument is not specified
1414
#' the default set of connections will be used: see \code{\link[DSI]{datashield.connections_default}}.
@@ -57,7 +57,7 @@
5757
#'
5858
#' }
5959
#'
60-
ds.isNA <- function(x=NULL, classConsistencyCheck=TRUE, datasources=NULL){
60+
ds.isNA <- function(x=NULL, datasources=NULL, classConsistencyCheck=TRUE){
6161

6262
datasources <- .set_datasources(datasources)
6363

R/ds.kurtosis.R

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,19 @@
1717
#' if \code{type} is set to 'split', 'splits' or 's', the kurtosis is returned separately for each study.
1818
#' if \code{type} is set to 'both' or 'b', both sets of outputs are produced.
1919
#' The default value is set to 'both'.
20+
#' @template classConsistencyCheckFalse
2021
#' @param datasources a list of \code{\link[DSI]{DSConnection-class}} objects obtained after login.
2122
#' If the \code{datasources} argument is not specified
2223
#' the default set of connections will be used: see \code{\link[DSI]{datashield.connections_default}}.
23-
#' @return a matrix showing the kurtosis of the input numeric variable, the number of valid observations and
24-
#' the validity message.
24+
#' @return a matrix showing the kurtosis of the input numeric variable and
25+
#' the number of valid observations.
2526
#' @author Demetris Avraam, for DataSHIELD Development Team
27+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
2628
#' @export
2729
#'
28-
ds.kurtosis <- function(x=NULL, method=1, type='both', datasources=NULL){
29-
30-
# if no opal login details are provided look for 'opal' objects in the environment
31-
if(is.null(datasources)){
32-
datasources <- datashield.connections_find()
33-
}
30+
ds.kurtosis <- function(x=NULL, method=1, type='both', datasources=NULL, classConsistencyCheck=FALSE){
3431

35-
# ensure datasources is a list of DSConnection-class
36-
if(!(is.list(datasources) && all(unlist(lapply(datasources, function(d) {methods::is(d,"DSConnection")}))))){
37-
stop("The 'datasources' were expected to be a list of DSConnection-class objects", call.=FALSE)
38-
}
32+
datasources <- .set_datasources(datasources)
3933

4034
if(is.null(x)){
4135
stop("Please provide the name of the input vector!", call.=FALSE)
@@ -53,26 +47,17 @@ ds.kurtosis <- function(x=NULL, method=1, type='both', datasources=NULL){
5347
stop('Function argument "type" has to be either "both", "combine" or "split"', call.=FALSE)
5448
}
5549

56-
# check if the input object is defined in all the studies
57-
isDefined(datasources, x)
58-
59-
# call the internal function that checks the input object is of the same class in all studies.
60-
typ <- checkClass(datasources, x)
61-
62-
# the input object must be a numeric or an integer vector
63-
if(typ != 'integer' & typ != 'numeric'){
64-
message(paste0(x, " is of type ", typ, "!"))
65-
stop("The input object must be an integer or numeric vector.", call.=FALSE)
66-
}
67-
6850
if (type=='split' | type=='both'){
6951
calltext.split <- call("kurtosisDS1", x, method)
7052
output.split <- DSI::datashield.aggregate(datasources, calltext.split)
71-
mat.split <- matrix(as.numeric(matrix(unlist(output.split), nrow=length(datasources), byrow=TRUE)[,1:2]),nrow=length(datasources))
72-
validity <- matrix(unlist(output.split), nrow=length(datasources), byrow=TRUE)[,3]
73-
mat.split <- data.frame(cbind(mat.split, validity))
53+
if(classConsistencyCheck){
54+
.checkClassConsistency(output.split)
55+
}
56+
mat.split <- data.frame(
57+
Kurtosis = sapply(output.split, function(r) r$Kurtosis),
58+
Nvalid = sapply(output.split, function(r) r$Nvalid)
59+
)
7460
rownames(mat.split) <- names(output.split)
75-
colnames(mat.split) <- c('Kurtosis', 'Nvalid', 'ValidityMessage')
7661
}
7762

7863
if (type=='combine' | type=='both'){
@@ -84,6 +69,9 @@ ds.kurtosis <- function(x=NULL, method=1, type='both', datasources=NULL){
8469
}else{
8570
calltext.combined <- call("kurtosisDS2", x, global.mean)
8671
output.combined <- DSI::datashield.aggregate(datasources, calltext.combined)
72+
if(classConsistencyCheck){
73+
.checkClassConsistency(output.combined)
74+
}
8775

8876
Global.sum.quartics <- 0
8977
Global.sum.squares <- 0
@@ -98,19 +86,15 @@ ds.kurtosis <- function(x=NULL, method=1, type='both', datasources=NULL){
9886

9987
if(method==1){
10088
Global.kurtosis <- g2.global
101-
combinedMessage <- "VALID ANALYSIS"
10289
}
10390
if(method==2){
10491
Global.kurtosis <- ((Global.Nvalid + 1) * g2.global + 6) * (Global.Nvalid - 1)/((Global.Nvalid - 2) * (Global.Nvalid - 3))
105-
combinedMessage <- "VALID ANALYSIS"
10692
}
10793
if(method==3){
10894
Global.kurtosis <- (g2.global + 3) * (1 - 1/Global.Nvalid)^2 - 3
109-
combinedMessage <- "VALID ANALYSIS"
11095
}
111-
mat.combined <- data.frame(cbind(Global.kurtosis, Global.Nvalid, combinedMessage))
96+
mat.combined <- data.frame(Kurtosis = Global.kurtosis, Nvalid = Global.Nvalid)
11297
rownames(mat.combined) <- 'studiesCombined'
113-
colnames(mat.combined) <- c('Kurtosis', 'Nvalid', 'ValidityMessage')
11498

11599
}
116100
}

R/ds.length.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#' if \code{type} is set to \code{'both'} or \code{'b'},
1515
#' both sets of outputs are produced.
1616
#' Default \code{'both'}.
17-
#' @template classConsistencyCheck
17+
#' @template classConsistencyCheckTrue
1818
#' @param datasources a list of \code{\link[DSI]{DSConnection-class}}
1919
#' objects obtained after login. If the \code{datasources} argument is not specified
2020
#' the default set of connections will be used: see \code{\link[DSI]{datashield.connections_default}}.
@@ -73,7 +73,7 @@
7373
#' datashield.logout(connections)
7474
#' }
7575
#'
76-
ds.length <- function(x=NULL, type='both', classConsistencyCheck=TRUE, datasources=NULL){
76+
ds.length <- function(x=NULL, type='both', datasources=NULL, classConsistencyCheck=TRUE){
7777

7878
datasources <- .set_datasources(datasources)
7979

0 commit comments

Comments
 (0)