Skip to content

Commit e276da3

Browse files
authored
Merge pull request #464 from datashield/perf-batch-1-v5
Refactor: performance improvement batch 1
2 parents a79e87a + b3fcee9 commit e276da3

38 files changed

Lines changed: 359 additions & 145 deletions

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
^\.github$
1313
^cran-comments\.md$
1414
^pull_request_template$
15+
PULL_REQUEST_TEMPLATE.md

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export(densityGridDS)
3939
export(dimDS)
4040
export(dmtC2SDS)
4141
export(elsplineDS)
42+
export(expDS)
4243
export(extractQuantilesDS1)
4344
export(extractQuantilesDS2)
4445
export(gamlssDS)
@@ -72,6 +73,7 @@ export(listDS)
7273
export(listDisclosureSettingsDS)
7374
export(lmerSLMADS.assign)
7475
export(lmerSLMADS2)
76+
export(logDS)
7577
export(lsDS)
7678
export(lsplineDS)
7779
export(matrixDS)

R/absDS.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
#' @export
1313
#'
1414
absDS <- function(x) {
15-
x.var <- eval(parse(text = x), envir = parent.frame())
15+
x.var <- .loadServersideObject(x)
16+
.checkClass(obj = x.var, obj_name = x, permitted_classes = c("numeric", "integer"))
1617

17-
# compute the absolute values of x
1818
out <- abs(x.var)
19-
20-
# assign the outcome to the data servers
2119
return(out)
2220
}
2321
# ASSIGN FUNCTION

R/asCharacterDS.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#' @export
1414
#'
1515
asCharacterDS <- function(x.name) {
16-
x <- eval(parse(text = x.name), envir = parent.frame())
16+
x <- .loadServersideObject(x.name)
1717

1818
output <- as.character(x)
1919
return(output)

R/asDataMatrixDS.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,9 @@
1717
#' @author Paul Burton for DataSHIELD Development Team
1818
#' @export
1919
asDataMatrixDS <- function(x.name) {
20-
if (is.character(x.name)) {
21-
x <- eval(parse(text = x.name), envir = parent.frame())
22-
} else {
23-
studysideMessage <- "ERROR: x.name must be specified as a character string"
24-
stop(studysideMessage, call. = FALSE)
25-
}
20+
x <- .loadServersideObject(x.name)
2621

2722
output <- data.matrix(x)
28-
2923
return(output)
3024
}
3125
# ASSIGN FUNCTION

R/asIntegerDS.R

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,10 @@
1414
#' @export
1515
#'
1616
asIntegerDS <- function(x.name){
17-
18-
if(is.character(x.name)){
19-
x <- eval(parse(text=x.name), envir = parent.frame())
20-
}else{
21-
studysideMessage <- "ERROR: x.name must be specified as a character string"
22-
stop(studysideMessage, call. = FALSE)
23-
}
17+
x <- .loadServersideObject(x.name)
2418

2519
output <- as.integer(as.character(x))
26-
2720
return(output)
28-
2921
}
3022
# ASSIGN FUNCTION
3123
# asIntegerDS

R/asListDS.R

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,10 @@
2222
#' @author Amadou Gaye, Paul Burton for DataSHIELD Development Team
2323
#' @export
2424
asListDS <- function (x.name, newobj){
25+
x <- .loadServersideObject(x.name)
2526

26-
newobj.class <- NULL
27-
if(is.character(x.name)){
28-
active.text<-paste0(newobj,"<-as.list(",x.name,")")
29-
eval(parse(text=active.text), envir = parent.frame())
30-
31-
active.text2<-paste0("class(",newobj,")")
32-
assign("newobj.class", eval(parse(text=active.text2), envir = parent.frame()))
33-
34-
}else{
35-
studysideMessage<-"ERROR: x.name must be specified as a character string"
36-
stop(studysideMessage, call. = FALSE)
37-
}
38-
39-
return.message<-paste0("New object <",newobj,"> created")
40-
object.class.text<-paste0("Class of <",newobj,"> is '",newobj.class,"'")
41-
42-
return(list(return.message=return.message,class.of.newobj=object.class.text))
27+
result <- as.list(x)
28+
assign(newobj, result, envir = parent.frame())
4329
}
44-
# AGGEGATE FUNCTION
30+
# AGGREGATE FUNCTION
4531
# asListDS

R/asLogicalDS.R

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
1-
#' @title Coerces an R object into class numeric
2-
#' @description this function is based on the native R function \code{as.numeric}
1+
#' @title Coerces an R object into class logical
2+
#' @description this function is based on the native R function \code{as.logical}
33
#' @details See help for function \code{as.logical} in native R
44
#' @param x.name the name of the input object to be coerced to class
5-
#' numeric. Must be specified in inverted commas. But this argument is
5+
#' logical. Must be specified in inverted commas. But this argument is
66
#' usually specified directly by <x.name> argument of the clientside function
7-
#' \code{ds.aslogical}
7+
#' \code{ds.asLogical}
88
#' @return the object specified by the <newobj> argument (or its default name
99
#' <x.name>.logic) which is written to the serverside. For further
1010
#' details see help on the clientside function \code{ds.asLogical}
1111
#' @author Amadou Gaye, Paul Burton for DataSHIELD Development Team
1212
#' @export
1313
asLogicalDS <- function (x.name){
14-
15-
if(is.character(x.name)){
16-
x<-eval(parse(text=x.name), envir = parent.frame())
17-
18-
}else{
19-
studysideMessage<-"ERROR: x.name must be specified as a character string"
20-
stop(studysideMessage, call. = FALSE)
21-
}
22-
23-
if(!is.numeric(x)&&!is.integer(x)&&!is.character(x)&&!is.matrix(x)){
24-
studysideMessage<-"ERROR: for ds.asLogical function, x.name must specify an input object of class numeric, integer, character or matrix"
25-
stop(studysideMessage, call. = FALSE)
26-
}
14+
x <- .loadServersideObject(x.name)
15+
.checkClass(obj = x, obj_name = x.name, permitted_classes = c("numeric", "integer", "character", "matrix"))
2716

2817
output <- as.logical(x)
29-
3018
return(output)
3119
}
3220
#ASSIGN FUNCTION

R/asMatrixDS.R

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,9 @@
1111
#' @author Amadou Gaye, Paul Burton for DataSHIELD Development Team
1212
#' @export
1313
asMatrixDS <- function (x.name){
14-
15-
if(is.character(x.name)){
16-
x<-eval(parse(text=x.name), envir = parent.frame())
17-
18-
}else{
19-
studysideMessage<-"ERROR: x.name must be specified as a character string"
20-
stop(studysideMessage, call. = FALSE)
21-
}
14+
x <- .loadServersideObject(x.name)
2215

2316
output <- as.matrix(x)
24-
2517
return(output)
2618
}
2719
#ASSIGN FUNCTION

R/asNumericDS.R

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@
1414
#' @export
1515
#'
1616
asNumericDS <- function(x.name){
17-
18-
if(is.character(x.name)){
19-
x <- eval(parse(text=x.name), envir = parent.frame())
20-
}else{
21-
studysideMessage <- "ERROR: x.name must be specified as a character string"
22-
stop(studysideMessage, call. = FALSE)
23-
}
17+
x <- .loadServersideObject(x.name)
2418

2519
# Check that it doesn't match any non-number
2620
numbers_only <- function(vec) !grepl("\\D", vec)
@@ -36,7 +30,6 @@ asNumericDS <- function(x.name){
3630
}
3731

3832
return(output)
39-
4033
}
4134
# ASSIGN FUNCTION
4235
# asNumericDS

0 commit comments

Comments
 (0)