Skip to content

Commit d2f5b78

Browse files
authored
Merge pull request #470 from datashield/refactor/perf-batch-2
Refactor/perf batch 2
2 parents 24d7959 + c74488d commit d2f5b78

27 files changed

Lines changed: 273 additions & 180 deletions

R/classDS.R

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@
55
#' @param x a string character, the name of an object
66
#' @return the class of the input object
77
#' @author Stuart Wheater, for DataSHIELD Development Team
8+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
89
#' @export
910
#'
1011
classDS <- function(x){
11-
12-
x.val <- eval(parse(text=x), envir = parent.frame())
13-
14-
# find the class of the input object
12+
x.val <- .loadServersideObject(x)
1513
out <- class(x.val)
16-
17-
# return the class
1814
return(out)
19-
2015
}
2116
#AGGREGATE FUNCTION
2217
# classDS

R/completeCasesDS.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#' without problems no studysideMessage will have been saved and ds.message("newobj")
3232
#' will return the message: "ALL OK: there are no studysideMessage(s) on this datasource".
3333
#' @author Paul Burton for DataSHIELD Development Team
34+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
3435
#' @export
3536
#'
3637
completeCasesDS <- function(x1.transmit){
@@ -111,10 +112,9 @@ completeCasesDS <- function(x1.transmit){
111112
}
112113

113114
#Activate target object
114-
#x1.transmit is the name of a serverside data.frame, matrix or vector
115-
x1.use <- eval(parse(text=x1.transmit), envir = parent.frame())
115+
x1.use <- .loadServersideObject(x1.transmit)
116116
complete.rows <- stats::complete.cases(x1.use)
117-
117+
118118
if(is.matrix(x1.use) || is.data.frame(x1.use)){
119119
output.object <- x1.use[complete.rows,]
120120
}else if(is.atomic(x1.use) || is.factor(x1.use)){

R/dimDS.R

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
#' @description This function is similar to R function \code{dim}.
44
#' @details The function returns the dimension of the input dataframe or matrix
55
#' @param x a string character, the name of a dataframe or matrix
6-
#' @return the dimension of the input object
6+
#' @return a list with two elements: \code{dim} (the dimension of the input object)
7+
#' and \code{class} (the class of the input object, for client-side consistency checking)
78
#' @author Demetris Avraam, for DataSHIELD Development Team
9+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
810
#' @export
911
#'
1012
dimDS <- function(x){
11-
12-
x.var <- eval(parse(text=x), envir = parent.frame())
13-
14-
# find the dim of the input dataframe or matrix
15-
out <- dim(x.var)
16-
17-
# return the dimension
18-
return(out)
19-
13+
x.val <- .loadServersideObject(x)
14+
.checkClass(obj = x.val, obj_name = x, permitted_classes = c("data.frame", "matrix"))
15+
list(dim = dim(x.val), class = class(x.val))
2016
}
2117
#AGGREGATE FUNCTION
2218
# dimDS

R/isNaDS.R

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
#'
2-
#' @title Checks if a vector is empty
3-
#' @description this function is similar to R function \code{is.na} but instead of a vector
1+
#'
2+
#' @title Checks if a vector is empty
3+
#' @description this function is similar to R function \code{is.na} but instead of a vector
44
#' of booleans it returns just one boolean to tell if all the element are missing values.
5-
#' @param xvect a numerical or character vector
6-
#' @return the integer '1' if the vector contains on NAs and '0' otherwise
5+
#' @param x a character string, the name of a server-side vector
6+
#' @return a list with two elements: \code{is.na} (TRUE if the vector contains
7+
#' only NAs, FALSE otherwise) and \code{class} (the class of the input object,
8+
#' for client-side consistency checking)
79
#' @author Gaye, A.
10+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
811
#' @export
912
#'
10-
isNaDS <- function(xvect){
11-
13+
isNaDS <- function(x){
14+
xvect <- .loadServersideObject(x)
15+
.checkClass(obj = xvect, obj_name = x, permitted_classes = c("character", "factor", "integer", "logical", "numeric", "data.frame", "matrix"))
1216
out <- is.na(xvect)
1317
total <- sum(out, na.rm=TRUE)
14-
if(total==(1*length(out))){
15-
return(TRUE)
16-
}else{
17-
return(FALSE)
18-
}
18+
is_na <- total == (1 * length(out))
19+
list(is.na = is_na, class = class(xvect))
1920
}

R/lengthDS.R

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@
33
#' @description This function is similar to R function \code{length}.
44
#' @details The function returns the length of the input vector or list.
55
#' @param x a string character, the name of a vector or list
6-
#' @return a numeric, the number of elements of the input vector or list.
6+
#' @return a list with two elements: \code{length} (the number of elements of the input
7+
#' vector or list) and \code{class} (the class of the input object, for client-side
8+
#' consistency checking)
79
#' @author Demetris Avraam, for DataSHIELD Development Team
10+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
811
#' @export
912
#'
1013
lengthDS <- function(x){
11-
12-
x.var <- eval(parse(text=x), envir = parent.frame())
13-
14-
# find the length of the input vector or list
15-
out <- length(x.var)
16-
17-
# return output length
18-
return(out)
19-
14+
x.val <- .loadServersideObject(x)
15+
.checkClass(obj = x.val, obj_name = x, permitted_classes = c("character", "factor", "integer", "logical", "numeric", "list", "data.frame"))
16+
list(length = length(x.val), class = class(x.val))
2017
}
2118
#AGGREGATE FUNCTION
2219
# lengthDS

R/levelsDS.R

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,36 @@
33
#' @description This function is similar to R function \code{levels}.
44
#' @details The function returns the levels of the input vector or list.
55
#' @param x a factor vector
6-
#' @return a list, the factor levels present in the vector
6+
#' @return a list with one element: \code{Levels} (the factor levels present
7+
#' in the vector)
78
#' @author Alex Westerberg, for DataSHIELD Development Team
9+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
810
#' @export
911
#'
1012
levelsDS <- function(x){
11-
13+
14+
x.val <- .loadServersideObject(x)
15+
.checkClass(obj = x.val, obj_name = x, permitted_classes = "factor")
16+
1217
# Check Permissive Privacy Control Level.
1318
dsBase::checkPermissivePrivacyControlLevel(c('permissive', 'banana', 'carrot'))
14-
19+
1520
##################################################################
1621
#MODULE 1: CAPTURE THE nfilter SETTINGS #
1722
thr <- dsBase::listDisclosureSettingsDS() #
18-
#nfilter.tab <- as.numeric(thr$nfilter.tab) #
19-
#nfilter.glm <- as.numeric(thr$nfilter.glm) #
20-
#nfilter.subset <- as.numeric(thr$nfilter.subset) #
21-
#nfilter.string <- as.numeric(thr$nfilter.string) #
22-
#nfilter.stringShort <- as.numeric(thr$nfilter.stringShort) #
23-
#nfilter.kNN <- as.numeric(thr$nfilter.kNN) #
24-
#nfilter.noise <- as.numeric(thr$nfilter.noise) #
2523
nfilter.levels.density <- as.numeric(thr$nfilter.levels.density) #
26-
#nfilter.levels.max <- as.numeric(thr$nfilter.levels.max) #
2724
##################################################################
28-
25+
2926
# find the levels of the input vector
30-
out <- levels(x)
31-
input.length <- length(x)
27+
out <- levels(x.val)
28+
input.length <- length(x.val)
3229
output.length <- length(out)
33-
studysideMessage <- "VALID ANALYSIS"
3430

3531
if((input.length * nfilter.levels.density) < output.length) {
36-
out <- NA
37-
studysideMessage <- "FAILED: Result length less than nfilter.levels.density of input length."
38-
stop(studysideMessage, call. = FALSE)
32+
stop("FAILED: Result length less than nfilter.levels.density of input length.", call. = FALSE)
3933
}
40-
41-
out.obj <- list(Levels=out,ValidityMessage=studysideMessage)
34+
35+
out.obj <- list(Levels=out)
4236
return(out.obj)
4337
}
4438
#AGGREGATE FUNCTION

R/namesDS.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#' @return \code{namesDS} returns to the client-side the names
1717
#' of a list object stored on the server-side.
1818
#' @author Amadou Gaye, updated by Paul Burton 25/06/2020
19+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
1920
#' @export
2021
#'
2122
namesDS <- function(xname.transmit){
@@ -50,14 +51,14 @@ nfilter.stringShort<-as.numeric(thr$nfilter.stringShort) #
5051
stop(studysideMessage, call. = FALSE)
5152
}
5253

53-
list.obj<-eval(parse(text=xname.transmit), envir = parent.frame())
54-
55-
trace.message<-class(list.obj)
56-
54+
list.obj <- .loadServersideObject(xname.transmit)
5755

5856
if(!is.list(list.obj)){
59-
error.message <- "The input object is not of class <list>"
60-
stop(paste0(error.message,trace.message), call. = FALSE)
57+
stop(
58+
"The input object is not of class <list>. '", xname.transmit, "' is type ",
59+
paste(class(list.obj), collapse = ", "),
60+
call. = FALSE
61+
)
6162
}
6263

6364

R/numNaDS.R

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
#'
1+
#'
22
#' @title Counts the number of missing values
3-
#' @description this function just counts the number of missing entries
4-
#' in a vector.
5-
#' @param xvect a vector
6-
#' @return an integer, the number of missing values
3+
#' @description this function just counts the number of missing entries
4+
#' in a vector.
5+
#' @param x a character string, the name of a server-side vector
6+
#' @return a list with two elements: \code{numNA} (an integer, the number of
7+
#' missing values) and \code{class} (the class of the input object, for
8+
#' client-side consistency checking)
79
#' @author Gaye, A.
10+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
811
#' @export
912
#'
10-
numNaDS <- function(xvect){
11-
13+
numNaDS <- function(x){
14+
xvect <- .loadServersideObject(x)
1215
out <- length(which(is.na(xvect)))
13-
return (out)
14-
16+
list(numNA = out, class = class(xvect))
1517
}

R/uniqueDS.R

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,12 @@
66
#' @return the object specified by the \code{newobj} argument
77
#' which is written to the server-side.
88
#' @author Stuart Wheater for DataSHIELD Development Team
9+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
910
#' @export
1011
#'
1112
uniqueDS <- function(x.name.transmit = NULL){
12-
# Check 'x.name.transmit' contains a name
13-
if (is.null(x.name.transmit))
14-
stop("Variable's name can't be NULL", call. = FALSE)
15-
16-
if ((! is.character(x.name.transmit)) || (length(x.name.transmit) != 1))
17-
stop("Variable's name isn't a single character vector", call. = FALSE)
18-
19-
# Check object exists
20-
x.value <- eval(parse(text=x.name.transmit), envir = parent.frame())
21-
22-
if (is.null(x.value))
23-
stop("Variable can't be NULL", call. = FALSE)
24-
25-
# Compute the unique's value
13+
x.value <- .loadServersideObject(x.name.transmit)
2614
out <- base::unique(x.value)
27-
28-
# assign the outcome to the data servers
2915
return(out)
3016
}
3117
# ASSIGN FUNCTION

man/classDS.Rd

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

0 commit comments

Comments
 (0)