Skip to content

Commit d206026

Browse files
Merge branch 'v7.0-dev-feat/performance' into v6.3.5-dev
2 parents 2105be0 + bdb5476 commit d206026

2 files changed

Lines changed: 39 additions & 33 deletions

File tree

R/ds.colnames.R

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
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[DSI]{DSConnection-class}} objects obtained after login.
1010
#' If the \code{datasources} argument is not specified
1111
#' 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.
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,17 +65,6 @@ 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-
7968
cally <- call("colnamesDS", x)
8069
column_names <- DSI::datashield.aggregate(datasources, cally)
8170

tests/testthat/test-smk-ds.colnames.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ test_that("setup", {
2525
# Tests
2626
#
2727

28+
options(datashield.errors.print = TRUE)
2829
# context("ds.colnames::smk")
2930
test_that("simple colnames", {
3031
myvectors <- c("D$LAB_TSC", "D$LAB_TRIG")
@@ -44,6 +45,22 @@ test_that("simple colnames", {
4445
expect_equal(res$sim3[2], "LAB_TRIG")
4546
})
4647

48+
test_that("fails if the object does not exist", {
49+
expect_error(
50+
ds.colnames("non_existing_df"),
51+
regexp = "'non_existing_df' does not exist",
52+
ignore.case = TRUE
53+
)
54+
})
55+
56+
test_that("fails if object is not a data frame or matrix", {
57+
expect_error(
58+
ds.colnames("D$LAB_TSC"),
59+
regexp = "must be of type data.frame or matrix",
60+
ignore.case = TRUE
61+
)
62+
})
63+
4764
#
4865
# Done
4966
#

0 commit comments

Comments
 (0)