Skip to content

Commit c9961e2

Browse files
Merge pull request #58 from datashield/v6.4.0-dev
V6.4.0 dev
2 parents 5ce26a2 + afcfffc commit c9961e2

19 files changed

Lines changed: 289 additions & 34 deletions

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export(ds.Boole)
44
export(ds.abs)
55
export(ds.asCharacter)
6+
export(ds.asDataFrame)
67
export(ds.asDataMatrix)
78
export(ds.asFactor)
89
export(ds.asFactorSimple)

R/ds.Boole.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ ds.Boole<-function(V1=NULL, V2=NULL, Boolean.operator=NULL, numeric.output=TRUE,
172172
stop(paste0("An unrecognized Boolean operator, ", Boolean.operator, ", has provide"), call.=FALSE)
173173
}
174174

175-
# if no value spcified for output object, then specify a default
175+
# if no value specified for output object, then specify a default
176176
if(is.null(newobj)){
177177
newobj <- paste0(V1,"_Boole")
178178
}
179179

180180
# CALL THE MAIN SERVER SIDE FUNCTION
181-
calltext <- call("BooleDS", V1, V2, BO.n, na.assign,numeric.output)
181+
calltext <- call("BooleDS", V1, V2, BO.n, na.assign, numeric.output)
182182
DSI::datashield.assign(datasources, newobj, calltext)
183183

184184
#############################################################################################################

R/ds.asCharacter.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#' it is in a valid form.
1919
#' @examples
2020
#' \dontrun{
21-
#' ## Version 6, for version 5 see the Wiki
2221
#'
2322
#' # connecting to the Opal servers
2423
#'

R/ds.asDataFrame.R

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#' @title Converts a server-side R object into a data frame
2+
#' @description Coerces an R object into a data frame maintaining original
3+
#' class for all columns in data frames.
4+
#' @details This function is based on the native R function \code{data.frame}.
5+
#'
6+
#' Server function called: \code{asDataFrameDS}.
7+
#' @param x.name a character string providing the name of the input object to be coerced to
8+
#' a data frame
9+
#' @param newobj a character string that provides the name for the output object
10+
#' that is stored on the data servers. Default \code{asdataframe.newobj}.
11+
#' @param datasources a list of \code{\link{DSConnection-class}}
12+
#' objects obtained after login. If the \code{datasources} argument is not specified
13+
#' the default set of connections will be used: see \code{\link{datashield.connections_default}}.
14+
#' @return \code{ds.asDataFrame} returns the object converted into a data frame
15+
#' that is written to the server-side.
16+
#' @examples
17+
#' \dontrun{
18+
#' ## Version 6, for version 5 see the Wiki
19+
#'
20+
#' # connecting to the Opal servers
21+
#'
22+
#' require('DSI')
23+
#' require('DSOpal')
24+
#' require('dsBaseClient')
25+
#'
26+
#' builder <- DSI::newDSLoginBuilder()
27+
#' builder$append(server = "study1",
28+
#' url = "http://192.168.56.100:8080/",
29+
#' user = "administrator", password = "datashield_test&",
30+
#' table = "CNSIM.CNSIM1", driver = "OpalDriver")
31+
#' builder$append(server = "study2",
32+
#' url = "http://192.168.56.100:8080/",
33+
#' user = "administrator", password = "datashield_test&",
34+
#' table = "CNSIM.CNSIM2", driver = "OpalDriver")
35+
#' builder$append(server = "study3",
36+
#' url = "http://192.168.56.100:8080/",
37+
#' user = "administrator", password = "datashield_test&",
38+
#' table = "CNSIM.CNSIM3", driver = "OpalDriver")
39+
#' logindata <- builder$build()
40+
#'
41+
#' connections <- DSI::datashield.login(logins = logindata, assign = TRUE, symbol = "D")
42+
#'
43+
#' # Converting the R object into a data frame
44+
#' ds.asDataFrame(x.name = "D",
45+
#' newobj = "mat.obj",
46+
#' datasources = connections[1]) #only the first server is used ("study1")
47+
#'
48+
#' # Clear the Datashield R sessions and logout
49+
#' datashield.logout(connections)
50+
#'
51+
#' }
52+
#' @author Tim Cadman
53+
#' @export
54+
ds.asDataFrame <- function(x.name=NULL, newobj=NULL, datasources=NULL){
55+
56+
# look for DS connections
57+
if(is.null(datasources)){
58+
datasources <- datashield.connections_find()
59+
}
60+
61+
# ensure datasources is a list of DSConnection-class
62+
if(!(is.list(datasources) && all(unlist(lapply(datasources, function(d) {methods::is(d,"DSConnection")}))))){
63+
stop("The 'datasources' were expected to be a list of DSConnection-class objects", call.=FALSE)
64+
}
65+
66+
if(is.null(x.name)){
67+
stop("Please provide the name of the input vector!", call.=FALSE)
68+
}
69+
70+
# check if the input object is defined in all the studies
71+
isDefined(datasources, x.name)
72+
73+
# create a name by default if user did not provide a name for the new variable
74+
if(is.null(newobj)){
75+
newobj <- "asdataframe.newobj"
76+
}
77+
78+
# call the server side function that does the job
79+
calltext <- call("asDataFrameDS", x.name)
80+
DSI::datashield.assign(datasources, newobj, calltext)
81+
82+
}

R/ds.boxPlot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ ds.boxPlot <- function(x, variables = NULL, group = NULL, group2 = NULL, xlabel
135135
}
136136
}
137137

138-
# Once all checks are passed, call the appropiate server functions
138+
# Once all checks are passed, call the appropriate server functions
139139
if("data.frame" %in% cls){
140140
ds.boxPlotGG_table(x, variables, group, group2, xlabel, ylabel, type, datasources)
141141
}

R/ds.glm.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#'
1818
#' Many GLMs can be fitted very simply using a formula such as:
1919
#'
20-
#' \deqn{y~a+b+c+d}
20+
#' \code{y~a+b+c+d}
2121
#'
2222
#' which simply means fit a GLM with \code{y} as the outcome variable and
2323
#' \code{a}, \code{b}, \code{c} and \code{d} as covariates.
@@ -26,7 +26,7 @@
2626
#' Instead, if you need to fit a more complex
2727
#' model, for example:
2828
#'
29-
#' \deqn{EVENT~1+TID+SEXF*AGE.60}
29+
#' \code{EVENT~1+TID+SEXF*AGE.60}
3030
#'
3131
#' In the above model the outcome variable is \code{EVENT}
3232
#' and the covariates

R/ds.glmSLMA.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#'
6262
#' Many glms can be fitted very simply using a formula such as:
6363
#'
64-
#' \deqn{y~a+b+c+d}
64+
#' \code{y~a+b+c+d}
6565
#'
6666
#' which simply means fit a glm with \code{y} as the outcome variable and
6767
#' \code{a}, \code{b}, \code{c} and \code{d} as covariates.
@@ -70,7 +70,7 @@
7070
#' Instead, if you need to fit a more complex
7171
#' model, for example:
7272
#'
73-
#' \deqn{EVENT~1+TID+SEXF*AGE.60}
73+
#' \code{EVENT~1+TID+SEXF*AGE.60}
7474
#'
7575
#' In the above model the outcome variable is \code{EVENT}
7676
#' and the covariates
@@ -121,7 +121,7 @@
121121
#' \item{\code{"quasibinomial"}}{: a model with a binomial variance function - if P
122122
#' is the expected proportion of successes, and N is the number of "trials" (always
123123
#' 1 if analysing binary data which are formally described as having a Bernoulli
124-
#' distribution (binomial distribution with N=1) the variance function is N*(P)*(1-P).
124+
#' distribution (binomial distribution with N=1) the variance function is \code{N*(P)*(1-P)}.
125125
#' But the residual variance which is fixed to be 1.00 in
126126
#' a binomial model can take any value. This is achieved by a dispersion parameter
127127
#' which is estimated during the model fit (see quasipoisson information above).}}

R/ds.glmerSLMA.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
#' In \code{formula} most shortcut notation allowed by \code{glmer()} function is
1919
#' also allowed by \code{ds.glmerSLMA}.
2020
#' Many GLMEs can be fitted very simply using a formula like:
21-
#' \deqn{y~a+b+(1|c)}
21+
#' \code{y~a+b+(1|c)}
2222
#' which simply means fit an GLME with \code{y} as the outcome variable (e.g.
2323
#' a binary case-control using a logistic regression model or a count or a survival
2424
#' time using a Poisson regression model), \code{a} and \code{b}
2525
#' as fixed effects, and \code{c} as a random effect or grouping factor.
2626
#'
2727
#' It is also possible to fit models with random slopes by specifying a model such as
28-
#' \deqn{y~a+b+(1+b|c)}
28+
#' \code{y~a+b+(1+b|c)}
2929
#' where the effect of \code{b} can vary randomly between groups defined by \code{c}.
30-
#' Implicit nesting can be specified with formulas such as: \eqn{y~a+b+(1|c/d)}
31-
#' or \eqn{y~a+b+(1|c)+(1|c:d)}.
30+
#' Implicit nesting can be specified with formulas such as: \code{y~a+b+(1|c/d)}
31+
#' or \code{y~a+b+(1|c)+(1|c:d)}.
3232
#'
3333
#'
3434
#' The \code{dataName} argument avoids you having to specify the name of the
@@ -228,9 +228,9 @@
228228
#'
229229
#' # Fit a Logistic regression model
230230
#'
231-
#' ds.glmerSLMA(formula = "Male ~ incid_rate +diabetes + (1 | age)",
231+
#' ds.glmerSLMA(formula = "Male ~ incid_rate +diabetes + (1 | age)",
232232
#' dataName = "D",
233-
#' datasources = connections[2],#only the second server is used (study2)
233+
#' datasources = connections[2], # only the second server is used (study2)
234234
#' family = "binomial")
235235
#'
236236
#'

R/ds.kurtosis.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44
#' @details The function calculates the kurtosis of an input variable x with three different methods.
55
#' The method is specified by the argument \code{method}. If x contains any missings, the function removes those before
66
#' the calculation of the kurtosis. If \code{method} is set to 1 the following formula is used
7-
#' \eqn{ kurtosis= \frac{\sum_{i=1}^{N} (x_i - \bar(x))^4 /N}{(\sum_{i=1}^{N} ((x_i - \bar(x))^2) /N)^(2) } - 3},
7+
#'
8+
#' \eqn{ kurtosis= \frac{\sum_{i=1}^{N} (x_i - \bar{x})^4 /N}{(\sum_{i=1}^{N} ((x_i - \bar{x})^2) /N)^2 } - 3},
9+
#'
810
#' where \eqn{ \bar{x} } is the mean of x and \eqn{N} is the number of observations. If \code{method} is set to 2
9-
#' the following formula is used \eqn{ kurtosis= ((N+1)*(\frac{\sum_{i=1}^{N} (x_i - \bar(x))^4 /N}{(\sum_{i=1}^{N} ((x_i - \bar(x))^2) /N)^(2) } - 3) + 6)*((N-1)/((N-2)*(N-3)))}.
10-
#' If \code{method} is set to 3 the following formula is used \eqn{ kurtosis= (\frac{\sum_{i=1}^{N} (x_i - \bar(x))^4 /N}{(\sum_{i=1}^{N} ((x_i - \bar(x))^2) /N)^(2) })*(1-1/N)^2 - 3}.
11+
#' the following formula is used
12+
#'
13+
#' \eqn{ kurtosis= ((N+1)*(\frac{\sum_{i=1}^{N} (x_i - \bar{x})^4 /N}{(\sum_{i=1}^{N} ((x_i - \bar{x})^2) /N)^2 } - 3) + 6)*((N-1)/((N-2)*(N-3)))}.
14+
#'
15+
#' If \code{method} is set to 3 the following formula is used
16+
#'
17+
#' \eqn{ kurtosis= (\frac{\sum_{i=1}^{N} (x_i - \bar{x})^4 /N}{(\sum_{i=1}^{N} ((x_i - \bar{x})^2) /N)^2 })*(1-1/N)^2 - 3}.
18+
#'
1119
#' This function is similar to the function \code{kurtosis} in R package \code{e1071}.
1220
#' @param x a string character, the name of a numeric variable.
1321
#' @param method an integer between 1 and 3 selecting one of the algorithms for computing kurtosis

man/ds.asCharacter.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)