|
| 1 | +#' |
| 2 | +#' @title Ensures that the requested subset is not larger than the original object |
| 3 | +#' @description Compares subset and original object sizes and eventually carries out subsetting. |
| 4 | +#' @details This function is called by the function \code{ds.subset} to ensure that the requested subset |
| 5 | +#' is not larger than the original object. |
| 6 | +#' |
| 7 | +#' This function is internal. |
| 8 | +#' |
| 9 | +#' Server function called: \code{dimDS} |
| 10 | +#' @param dts a list of \code{\link[DSI]{DSConnection-class}} |
| 11 | +#' objects obtained after login. If the \code{datasources} argument is not specified |
| 12 | +#' the default set of connections will be used: see \code{\link[DSI]{datashield.connections_default}}. |
| 13 | +#' @param data a character string specifying the name of the data frame or |
| 14 | +#' the factor vector and the range of the subset. |
| 15 | +#' @param rs a vector of two integers specifying the indices of the rows de extract. |
| 16 | +#' @param cs a vector of two integers or one or more characters. |
| 17 | +#' @keywords internal |
| 18 | +#' @return \code{subsetHelper} returns a message or the class of the object if the |
| 19 | +#' object has the same class in all studies. |
| 20 | +#' @examples |
| 21 | +#' \dontrun{ |
| 22 | +#' |
| 23 | +#' ## Version 6, for version 5 see the Wiki |
| 24 | +#' |
| 25 | +#' # connecting to the Opal servers |
| 26 | +#' |
| 27 | +#' require('DSI') |
| 28 | +#' require('DSOpal') |
| 29 | +#' require('dsBaseClient') |
| 30 | +#' |
| 31 | +#' builder <- DSI::newDSLoginBuilder() |
| 32 | +#' builder$append(server = "study1", |
| 33 | +#' url = "http://192.168.56.100:8080/", |
| 34 | +#' user = "administrator", password = "datashield_test&", |
| 35 | +#' table = "CNSIM.CNSIM1", driver = "OpalDriver") |
| 36 | +#' builder$append(server = "study2", |
| 37 | +#' url = "http://192.168.56.100:8080/", |
| 38 | +#' user = "administrator", password = "datashield_test&", |
| 39 | +#' table = "CNSIM.CNSIM2", driver = "OpalDriver") |
| 40 | +#' builder$append(server = "study3", |
| 41 | +#' url = "http://192.168.56.100:8080/", |
| 42 | +#' user = "administrator", password = "datashield_test&", |
| 43 | +#' table = "CNSIM.CNSIM3", driver = "OpalDriver") |
| 44 | +#' logindata <- builder$build() |
| 45 | +#' |
| 46 | +#' connections <- DSI::datashield.login(logins = logindata, assign = TRUE, symbol = "D") |
| 47 | +#' |
| 48 | +#' subsetHelper(dts = connections, |
| 49 | +#' data = "D", |
| 50 | +#' rs = 1:10, |
| 51 | +#' cs = c("D$LAB_TSC","D$LAB_TRIG")) |
| 52 | +#' |
| 53 | +#' # clear the Datashield R sessions and logout |
| 54 | +#' datashield.logout(connections) |
| 55 | +#' } |
| 56 | +#' |
| 57 | +subsetHelper <- function(dts, data, rs=NULL, cs=NULL){ |
| 58 | + |
| 59 | + # if the size of the requested subset is greater than that of original inform the user and stop the process |
| 60 | + dims <- DSI::datashield.aggregate(dts, call("dimDS", data)) |
| 61 | + fail <- c(0,0) |
| 62 | + |
| 63 | + if(!(is.null(rs))){ |
| 64 | + if(length(rs) > dims[[1]][1] ){ |
| 65 | + fail[1] <- 1 |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + if(!(is.null(cs))){ |
| 70 | + if(length(cs) > dims[[1]][2]){ |
| 71 | + fail[2] <- 1 |
| 72 | + } |
| 73 | + } |
| 74 | + return(fail) |
| 75 | + |
| 76 | +} |
0 commit comments