11# '
22# ' @title Produces column names of the R object in the server-side
3- # ' @description Retrieves column names of an R object on the server-side.
3+ # ' @description Retrieves column names of an R object on the server-side.
44# ' This function is similar to R function \code{colnames}.
5- # ' @details The input is restricted to the object of type \code{data.frame} or \code{matrix}.
6- # '
5+ # ' @details The input is restricted to the object of type \code{data.frame} or \code{matrix}.
6+ # '
77# ' Server function called: \code{colnamesDS}
88# ' @param x a character string providing the name of the input data frame or matrix.
9- # ' @param datasources a list of \code{\link[DSI] {DSConnection-class}} objects obtained after login.
9+ # ' @param datasources a list of \code{\link{DSConnection-class}} objects obtained after login.
1010# ' If the \code{datasources} argument is not specified
11- # ' the default set of connections will be used: see \code{\link[DSI] {datashield.connections_default}}.
12- # ' @return \code{ds.colnames} returns the column names of
13- # ' the specified server-side data frame or matrix.
11+ # ' the default set of connections will be used: see \code{\link{datashield.connections_default}}.
12+ # ' @return \code{ds.colnames} returns the column names of
13+ # ' the specified server-side data frame or matrix.
1414# ' @author DataSHIELD Development Team
1515# ' @seealso \code{\link{ds.dim}} to obtain the dimensions of a matrix or a data frame.
16- # ' @examples
16+ # ' @examples
1717# ' \dontrun{
18- # '
18+ # '
1919# ' ## Version 6, for version 5 see the Wiki
2020# ' # Connecting to the Opal servers
21- # '
21+ # '
2222# ' require('DSI')
2323# ' require('DSOpal')
2424# ' require('dsBaseClient')
25- # '
25+ # '
2626# ' builder <- DSI::newDSLoginBuilder()
27- # ' builder$append(server = "study1",
28- # ' url = "http://192.168.56.100:8080/",
29- # ' user = "administrator", password = "datashield_test&",
27+ # ' builder$append(server = "study1",
28+ # ' url = "http://192.168.56.100:8080/",
29+ # ' user = "administrator", password = "datashield_test&",
3030# ' table = "CNSIM.CNSIM1", driver = "OpalDriver")
31- # ' builder$append(server = "study2",
32- # ' url = "http://192.168.56.100:8080/",
33- # ' user = "administrator", password = "datashield_test&",
31+ # ' builder$append(server = "study2",
32+ # ' url = "http://192.168.56.100:8080/",
33+ # ' user = "administrator", password = "datashield_test&",
3434# ' table = "CNSIM.CNSIM2", driver = "OpalDriver")
3535# ' builder$append(server = "study3",
36- # ' url = "http://192.168.56.100:8080/",
37- # ' user = "administrator", password = "datashield_test&",
36+ # ' url = "http://192.168.56.100:8080/",
37+ # ' user = "administrator", password = "datashield_test&",
3838# ' table = "CNSIM.CNSIM3", driver = "OpalDriver")
3939# ' logindata <- builder$build()
40- # '
40+ # '
4141# ' # Log onto the remote Opal training servers
42- # ' connections <- DSI::datashield.login(logins = logindata, assign = TRUE, symbol = "D")
43- # '
42+ # ' connections <- DSI::datashield.login(logins = logindata, assign = TRUE, symbol = "D")
43+ # '
4444# ' # Getting column names of the R objects stored in the server-side
4545# ' ds.colnames(x = "D",
4646# ' datasources = connections[1]) #only the first server ("study1") is used
4747# ' # Clear the Datashield R sessions and logout
48- # ' datashield.logout(connections)
48+ # ' datashield.logout(connections)
4949# ' }
5050# ' @export
5151# '
@@ -65,6 +65,17 @@ ds.colnames <- function(x=NULL, datasources=NULL) {
6565 stop(" Please provide the name of a data.frame or matrix!" , call. = FALSE )
6666 }
6767
68+ # check if the input object(s) is(are) defined in all the studies
69+ defined <- isDefined(datasources , x )
70+
71+ # call the internal function that checks the input object is of the same class in all studies.
72+ typ <- checkClass(datasources , x )
73+
74+ # if the input object is not a matrix or a dataframe stop
75+ if (! (' data.frame' %in% typ ) & ! (' matrix' %in% typ )){
76+ stop(" The input vector must be of type 'data.frame' or a 'matrix'!" , call. = FALSE )
77+ }
78+
6879 cally <- call(" colnamesDS" , x )
6980 column_names <- DSI :: datashield.aggregate(datasources , cally )
7081
0 commit comments