|
7 | 7 | #' from every single study and the pooled dimension of the object by summing up the individual |
8 | 8 | #' dimensions returned from each study. |
9 | 9 | #' |
10 | | -#' In \code{checks} parameter is suggested that checks should only be undertaken once the |
11 | | -#' function call has failed. |
12 | | -#' |
13 | 10 | #' Server function called: \code{dimDS} |
14 | | -#' |
15 | | -#' @param x a character string providing the name of the input object. |
16 | | -#' @param type a character string that represents the type of analysis to carry out. |
| 11 | +#' |
| 12 | +#' @param x a character string providing the name of the input object. |
| 13 | +#' @param type a character string that represents the type of analysis to carry out. |
17 | 14 | #' If \code{type} is set to \code{'combine'}, \code{'combined'}, \code{'combines'} or \code{'c'}, |
18 | | -#' the global dimension is returned. |
19 | | -#' If \code{type} is set to \code{'split'}, \code{'splits'} or \code{'s'}, |
| 15 | +#' the global dimension is returned. |
| 16 | +#' If \code{type} is set to \code{'split'}, \code{'splits'} or \code{'s'}, |
20 | 17 | #' the dimension is returned separately for each study. |
21 | 18 | #' If \code{type} is set to \code{'both'} or \code{'b'}, both sets of outputs are produced. |
22 | | -#' Default \code{'both'}. |
23 | | -#' @param checks logical. If TRUE undertakes all DataSHIELD checks (time-consuming). |
24 | | -#' Default FALSE. |
| 19 | +#' Default \code{'both'}. |
| 20 | +#' @template classConsistencyCheck |
25 | 21 | #' @param datasources a list of \code{\link[DSI]{DSConnection-class}} |
26 | 22 | #' objects obtained after login. If the \code{datasources} argument is not specified |
27 | 23 | #' the default set of connections will be used: see \code{\link[DSI]{datashield.connections_default}}. |
28 | 24 | #' @return \code{ds.dim} retrieves to the client-side the dimension of the object |
29 | 25 | #' in the form of a vector where the first |
30 | 26 | #' element indicates the number of rows and the second element indicates the number of columns. |
31 | 27 | #' @author DataSHIELD Development Team |
| 28 | +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands |
32 | 29 | #' @seealso \code{\link{ds.dataFrame}} to generate a table of the type data frame. |
33 | 30 | #' @seealso \code{\link{ds.changeRefGroup}} to change the reference level of a factor. |
34 | 31 | #' @seealso \code{\link{ds.colnames}} to obtain the column names of a matrix or a data frame |
|
67 | 64 | #' # Calculate the dimension |
68 | 65 | #' ds.dim(x="D", |
69 | 66 | #' type="combine", #global dimension |
70 | | -#' checks = FALSE, |
71 | | -#' datasources = connections)#all opal servers are used |
| 67 | +#'#' datasources = connections)#all opal servers are used |
72 | 68 | #' ds.dim(x="D", |
73 | 69 | #' type = "both",#separate dimension for each study |
74 | 70 | #' #and the pooled dimension (default) |
75 | | -#' checks = FALSE, |
76 | | -#' datasources = connections)#all opal servers are used |
| 71 | +#'#' datasources = connections)#all opal servers are used |
77 | 72 | #' ds.dim(x="D", |
78 | 73 | #' type="split", #separate dimension for each study |
79 | | -#' checks = FALSE, |
80 | | -#' datasources = connections[1])#only the first opal server is used ("study1") |
| 74 | +#'#' datasources = connections[1])#only the first opal server is used ("study1") |
81 | 75 | #' |
82 | 76 | #' # clear the Datashield R sessions and logout |
83 | 77 | #' datashield.logout(connections) |
84 | 78 | #' |
85 | 79 | #' } |
86 | 80 | #' |
87 | | -ds.dim <- function(x=NULL, type='both', checks=FALSE, datasources=NULL) { |
| 81 | +ds.dim <- function(x=NULL, type='both', classConsistencyCheck=TRUE, datasources=NULL) { |
88 | 82 |
|
89 | | - # look for DS connections |
90 | | - if(is.null(datasources)){ |
91 | | - datasources <- datashield.connections_find() |
92 | | - } |
93 | | - |
94 | | - # ensure datasources is a list of DSConnection-class |
95 | | - if(!(is.list(datasources) && all(unlist(lapply(datasources, function(d) {methods::is(d,"DSConnection")}))))){ |
96 | | - stop("The 'datasources' were expected to be a list of DSConnection-class objects", call.=FALSE) |
97 | | - } |
| 83 | + datasources <- .set_datasources(datasources) |
98 | 84 |
|
99 | 85 | if(is.null(x)){ |
100 | 86 | stop("Please provide the name of a data.frame or matrix!", call.=FALSE) |
101 | 87 | } |
102 | 88 |
|
103 | | - ######################################################################################################## |
104 | | - # MODULE: GENERIC OPTIONAL CHECKS TO ENSURE CONSISTENT STRUCTURE OF KEY VARIABLES IN DIFFERENT SOURCES # |
105 | | - # beginning of optional checks - the process stops and reports as soon as one check fails # |
106 | | - # # |
107 | | - if(checks){ # |
108 | | - message(" -- Verifying the variables in the model") # |
109 | | - # check if the input object(s) is(are) defined in all the studies # |
110 | | - defined <- isDefined(datasources, x) # # |
111 | | - # call the internal function that checks the input object is suitable in all studies # |
112 | | - typ <- checkClass(datasources, x) # |
113 | | - # throw a message and stop if input is not table structure # |
114 | | - if(!('data.frame' %in% typ) & !('matrix' %in% typ)){ # |
115 | | - stop("The input object must be a table structure!", call.=FALSE) # |
116 | | - } # |
117 | | - } # |
118 | | - ######################################################################################################## |
119 | | - |
120 | | - |
121 | 89 | ################################################################################################### |
122 | 90 | #MODULE: EXTEND "type" argument to include "both" and enable valid aliases # |
123 | 91 | if(type == 'combine' | type == 'combined' | type == 'combines' | type == 'c') type <- 'combine' # |
124 | 92 | if(type == 'split' | type == 'splits' | type == 's') type <- 'split' # |
125 | 93 | if(type == 'both' | type == 'b' ) type <- 'both' # |
126 | | - # |
127 | | - #MODIFY FUNCTION CODE TO DEAL WITH ALL THREE TYPES # |
128 | 94 | ################################################################################################### |
129 | 95 |
|
130 | 96 | cally <- call("dimDS", x) |
131 | | - dimensions <- DSI::datashield.aggregate(datasources, cally) |
| 97 | + results <- DSI::datashield.aggregate(datasources, cally) |
| 98 | + |
| 99 | + if(classConsistencyCheck){ |
| 100 | + .checkClassConsistency(results) |
| 101 | + } |
| 102 | + |
| 103 | + # extract dimensions from results |
| 104 | + dimensions <- lapply(results, function(r) r$dim) |
132 | 105 |
|
133 | 106 | # names of the studies to be used in the output |
134 | 107 | stdnames <- names(datasources) |
|
0 commit comments