|
12 | 12 | #' objects obtained after login. If the \code{datasources} argument is not specified |
13 | 13 | #' the default set of connections will be used: see \code{\link[DSI]{datashield.connections_default}}. |
14 | 14 | #' @return \code{ds.asDataMatrix} returns the object converted into a matrix |
15 | | -#' that is written to the server-side. Also, two validity messages are returned |
16 | | -#' to the client-side |
17 | | -#' indicating the name of the \code{newobj} which |
18 | | -#' has been created in each data source and if |
19 | | -#' it is in a valid form. |
| 15 | +#' that is written to the server-side. |
20 | 16 | #' @examples |
21 | 17 | #' \dontrun{ |
22 | 18 | #' ## Version 6, for version 5 see the Wiki |
|
54 | 50 | #' |
55 | 51 | #' } |
56 | 52 | #' @author DataSHIELD Development Team |
| 53 | +#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands |
57 | 54 | #' @export |
58 | 55 | #' |
59 | 56 | ds.asDataMatrix <- function(x.name=NULL, newobj=NULL, datasources=NULL){ |
60 | 57 |
|
61 | | - # look for DS connections |
62 | | - if(is.null(datasources)){ |
63 | | - datasources <- datashield.connections_find() |
64 | | - } |
65 | | - |
66 | | - # ensure datasources is a list of DSConnection-class |
67 | | - if(!(is.list(datasources) && all(unlist(lapply(datasources, function(d) {methods::is(d,"DSConnection")}))))){ |
68 | | - stop("The 'datasources' were expected to be a list of DSConnection-class objects", call.=FALSE) |
69 | | - } |
| 58 | + datasources <- .set_datasources(datasources) |
70 | 59 |
|
71 | 60 | if(is.null(x.name)){ |
72 | 61 | stop("Please provide the name of the input vector!", call.=FALSE) |
73 | 62 | } |
74 | 63 |
|
75 | | - # check if the input object is defined in all the studies |
76 | | - isDefined(datasources, x.name) |
77 | | - |
78 | | - # create a name by default if user did not provide a name for the new variable |
79 | 64 | if(is.null(newobj)){ |
80 | 65 | newobj <- "asdatamatrix.newobj" |
81 | 66 | } |
82 | 67 |
|
83 | | - # call the server side function that does the job |
84 | 68 | calltext <- call("asDataMatrixDS", x.name) |
85 | 69 | DSI::datashield.assign(datasources, newobj, calltext) |
86 | 70 |
|
87 | | - |
88 | | -############################################################################################################# |
89 | | -#DataSHIELD CLIENTSIDE MODULE: CHECK KEY DATA OBJECTS SUCCESSFULLY CREATED # |
90 | | - # |
91 | | -#SET APPROPRIATE PARAMETERS FOR THIS PARTICULAR FUNCTION # |
92 | | -test.obj.name<-newobj # |
93 | | - # # |
94 | | - # |
95 | | -# CALL SEVERSIDE FUNCTION # |
96 | | -calltext <- call("testObjExistsDS", test.obj.name) # |
97 | | - # |
98 | | -object.info<-DSI::datashield.aggregate(datasources, calltext) # |
99 | | - # |
100 | | -# CHECK IN EACH SOURCE WHETHER OBJECT NAME EXISTS # |
101 | | -# AND WHETHER OBJECT PHYSICALLY EXISTS WITH A NON-NULL CLASS # |
102 | | -num.datasources<-length(object.info) # |
103 | | - # |
104 | | - # |
105 | | -obj.name.exists.in.all.sources<-TRUE # |
106 | | -obj.non.null.in.all.sources<-TRUE # |
107 | | - # |
108 | | -for(j in 1:num.datasources){ # |
109 | | - if(!object.info[[j]]$test.obj.exists){ # |
110 | | - obj.name.exists.in.all.sources<-FALSE # |
111 | | - } # |
112 | | - if(is.null(object.info[[j]]$test.obj.class) || ("ABSENT" %in% object.info[[j]]$test.obj.class)){ # |
113 | | - obj.non.null.in.all.sources<-FALSE # |
114 | | - } # |
115 | | - } # |
116 | | - # |
117 | | -if(obj.name.exists.in.all.sources && obj.non.null.in.all.sources){ # |
118 | | - # |
119 | | - return.message<- # |
120 | | - paste0("A data object <", test.obj.name, "> has been created in all specified data sources") # |
121 | | - # |
122 | | - # |
123 | | - }else{ # |
124 | | - # |
125 | | - return.message.1<- # |
126 | | - paste0("Error: A valid data object <", test.obj.name, "> does NOT exist in ALL specified data sources") # |
127 | | - # |
128 | | - return.message.2<- # |
129 | | - paste0("It is either ABSENT and/or has no valid content/class,see return.info above") # |
130 | | - # |
131 | | - return.message.3<- # |
132 | | - paste0("Please use ds.ls() to identify where missing") # |
133 | | - # |
134 | | - # |
135 | | - return.message<-list(return.message.1,return.message.2,return.message.3) # |
136 | | - # |
137 | | - } # |
138 | | - # |
139 | | - calltext <- call("messageDS", test.obj.name) # |
140 | | - studyside.message<-DSI::datashield.aggregate(datasources, calltext) # |
141 | | - # |
142 | | - no.errors<-TRUE # |
143 | | - for(nd in 1:num.datasources){ # |
144 | | - if(studyside.message[[nd]]!="ALL OK: there are no studysideMessage(s) on this datasource"){ # |
145 | | - no.errors<-FALSE # |
146 | | - } # |
147 | | - } # |
148 | | - # |
149 | | - # |
150 | | - if(no.errors){ # |
151 | | - validity.check<-paste0("<",test.obj.name, "> appears valid in all sources") # |
152 | | - return(list(is.object.created=return.message,validity.check=validity.check)) # |
153 | | - } # |
154 | | - # |
155 | | -if(!no.errors){ # |
156 | | - validity.check<-paste0("<",test.obj.name,"> invalid in at least one source. See studyside.messages:") # |
157 | | - return(list(is.object.created=return.message,validity.check=validity.check, # |
158 | | - studyside.messages=studyside.message)) # |
159 | | - } # |
160 | | - # |
161 | | -#END OF CHECK OBJECT CREATED CORECTLY MODULE # |
162 | | -############################################################################################################# |
163 | | - |
164 | | - |
165 | 71 | } |
166 | | -# ds.asDataMatrix |
0 commit comments