Skip to content

Commit 73f6273

Browse files
committed
refactor: move checks to serverside
1 parent e276da3 commit 73f6273

11 files changed

Lines changed: 57 additions & 31 deletions

File tree

R/corDS.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ corDS <- function(x=NULL, y=NULL){
2727
nfilter.glm <- as.numeric(thr$nfilter.glm)
2828
#############################################################
2929

30-
x.val <- eval(parse(text=x), envir = parent.frame())
30+
x.val <- .loadServersideObject(x)
31+
.checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "matrix", "data.frame"))
32+
3133
if (!is.null(y)){
32-
y.val <- eval(parse(text=y), envir = parent.frame())
34+
y.val <- .loadServersideObject(y)
35+
.checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "matrix", "data.frame"))
3336
}
3437
else{
3538
y.val <- NULL

R/corTestDS.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
#'
1818
corTestDS <- function(x, y, method, exact, conf.level){
1919

20-
x.var <- eval(parse(text=x), envir = parent.frame())
21-
y.var <- eval(parse(text=y), envir = parent.frame())
20+
x.var <- .loadServersideObject(x)
21+
.checkClass(obj = x.var, obj_name = x, permitted_classes = c("numeric", "integer"))
22+
y.var <- .loadServersideObject(y)
23+
.checkClass(obj = y.var, obj_name = y, permitted_classes = c("numeric", "integer"))
2224

2325
# get the number of pairwise complete cases
2426
n <- sum(stats::complete.cases(x.var, y.var))

R/covDS.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ covDS <- function(x=NULL, y=NULL, use=NULL){
3636
#nfilter.string <- as.numeric(thr$nfilter.string)
3737
#############################################################
3838

39-
x.val <- eval(parse(text=x), envir = parent.frame())
39+
x.val <- .loadServersideObject(x)
40+
.checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "matrix", "data.frame"))
41+
4042
if (!is.null(y)){
41-
y.val <- eval(parse(text=y), envir = parent.frame())
43+
y.val <- .loadServersideObject(y)
44+
.checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "matrix", "data.frame"))
4245
}
4346
else{
4447
y.val <- NULL

R/kurtosisDS1.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ kurtosisDS1 <- function (x, method){
1919
nfilter.tab <- as.numeric(thr$nfilter.tab)
2020
#############################################################
2121

22-
x <- eval(parse(text=x), envir = parent.frame())
23-
x <- x[stats::complete.cases(x)]
22+
x.val <- .loadServersideObject(x)
23+
.checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer"))
24+
x <- x.val[stats::complete.cases(x.val)]
2425

2526
if(length(x) < nfilter.tab){
2627
kurtosis.out <- NA

R/kurtosisDS2.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ kurtosisDS2 <- function(x, global.mean){
2323
nfilter.tab <- as.numeric(thr$nfilter.tab)
2424
#############################################################
2525

26-
x <- eval(parse(text=x), envir = parent.frame())
27-
x <- x[stats::complete.cases(x)]
26+
x.val <- .loadServersideObject(x)
27+
.checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer"))
28+
x <- x.val[stats::complete.cases(x.val)]
2829

2930
if(length(x) < nfilter.tab){
3031
sum_quartics.out <- NA

R/meanDS.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#' @description Calculates the mean value.
44
#' @details if the length of input vector is less than the set filter
55
#' a missing value is returned.
6-
#' @param xvect a vector
6+
#' @param x a character string, the name of a numeric or integer vector
77
#' @return a numeric, the statistical mean
88
#' @author Gaye A, Burton PR
99
#' @export
1010
#'
11-
meanDS <- function(xvect){
11+
meanDS <- function(x){
1212

1313
#############################################################
1414
# MODULE 1: CAPTURE THE nfilter SETTINGS
@@ -19,6 +19,9 @@ meanDS <- function(xvect){
1919
#nfilter.string <- as.numeric(thr$nfilter.string)
2020
#############################################################
2121

22+
xvect <- .loadServersideObject(x)
23+
.checkClass(obj = xvect, obj_name = x, permitted_classes = c("numeric", "integer"))
24+
2225
out.mean <- mean(xvect, na.rm=TRUE)
2326
out.numNa <- length(which(is.na(xvect)))
2427
out.totN <- length(xvect)

R/meanSdGpDS.R

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
#' @description Server-side function called by ds.meanSdGp
44
#' @details Computes the mean and standard deviation across groups defined by one
55
#' factor
6-
#' @param X a client-side supplied character string identifying the variable for which
6+
#' @param x a client-side supplied character string identifying the variable for which
77
#' means/SDs are to be calculated
8-
#' @param INDEX a client-side supplied character string identifying the factor across
8+
#' @param index a client-side supplied character string identifying the factor across
99
#' which means/SDs are to be calculated
1010
#' @author Burton PR
11-
#'
11+
#'
1212
#' @return List with results from the group statistics
1313
#' @export
1414
#'
15-
meanSdGpDS <- function (X, INDEX){
16-
15+
meanSdGpDS <- function (x, index){
16+
1717
#############################################################
1818
# MODULE 1: CAPTURE THE nfilter SETTINGS
1919
thr <- dsBase::listDisclosureSettingsDS()
@@ -23,9 +23,14 @@ meanSdGpDS <- function (X, INDEX){
2323
#nfilter.string <- as.numeric(thr$nfilter.string)
2424
#############################################################
2525

26+
X <- .loadServersideObject(x)
27+
.checkClass(obj = X, obj_name = x, permitted_classes = c("numeric", "integer"))
28+
INDEX <- .loadServersideObject(index)
29+
.checkClass(obj = INDEX, obj_name = index, permitted_classes = c("factor", "character", "integer"))
30+
2631
FUN.mean <- function(x) {mean(x,na.rm=TRUE)}
2732
FUN.var <- function(x) {stats::var(x,na.rm=TRUE)}
28-
33+
2934
#Strip missings from both X and INDEX
3035
analysis.matrix<-cbind(X,INDEX)
3136

R/quantileMeanDS.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
#' @title Generates quantiles and mean information without maximum and minimum
33
#' @description the probabilities 5%, 10%, 25%, 50%, 75%, 90%, 95% and the mean
44
#' are used to compute the corresponding quantiles.
5-
#' @param xvect a numerical vector
6-
#' @return a numeric vector that represents the sample quantiles
5+
#' @param x a character string, the name of a numeric or integer vector
6+
#' @return a numeric vector that represents the sample quantiles
77
#' @export
88
#' @author Burton, P.; Gaye, A.
9-
#'
10-
quantileMeanDS <- function (xvect) {
11-
9+
#'
10+
quantileMeanDS <- function (x) {
11+
12+
xvect <- .loadServersideObject(x)
13+
.checkClass(obj = xvect, obj_name = x, permitted_classes = c("numeric", "integer"))
14+
1215
# check if the input vector is valid (i.e. meets DataSHIELD criteria)
1316
check <- isValidDS(xvect)
14-
17+
1518
if(check){
16-
# if the input vector is valid
19+
# if the input vector is valid
1720
qq <- stats::quantile(xvect,c(0.05,0.1,0.25,0.5,0.75,0.9,0.95), na.rm=TRUE)
1821
mm <- mean(xvect,na.rm=TRUE)
1922
quantile.obj <- c(qq, mm)

R/skewnessDS1.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ skewnessDS1 <- function(x, method){
1919
nfilter.tab <- as.numeric(thr$nfilter.tab)
2020
#############################################################
2121

22-
x <- eval(parse(text=x), envir = parent.frame())
23-
x <- x[stats::complete.cases(x)]
22+
x.val <- .loadServersideObject(x)
23+
.checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer"))
24+
x <- x.val[stats::complete.cases(x.val)]
2425

2526
if(length(x) < nfilter.tab){
2627
skewness.out <- NA

R/skewnessDS2.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ skewnessDS2 <- function(x, global.mean){
2323
nfilter.tab <- as.numeric(thr$nfilter.tab)
2424
#############################################################
2525

26-
x <- eval(parse(text=x), envir = parent.frame())
27-
x <- x[stats::complete.cases(x)]
26+
x.val <- .loadServersideObject(x)
27+
.checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer"))
28+
x <- x.val[stats::complete.cases(x.val)]
2829

2930
if(length(x) < nfilter.tab){
3031
sum_cubes.out <- NA

0 commit comments

Comments
 (0)