Skip to content

Commit 323e86a

Browse files
Merge branch 'datashield:refactor/perf-batch-10' into refactor/perf-batch-10
2 parents a77ac73 + 119ee0f commit 323e86a

24 files changed

Lines changed: 590 additions & 191 deletions

‎R/boxPlotGGDS.R‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' parameters are passed. There are three different cases depending if there are grouping variables.
66
#' The outliers are also removed from the graphical parameters.
77
#'
8-
#' @param data_table \code{data frame} Table that holds the information to be plotted, arranged as: \cr
8+
#' @param data_table.name \code{character} Name of a server-side data frame that holds the information to be plotted, arranged as: \cr
99
#'
1010
#' Column 'x': Names on the X axis of the boxplot, aka variables to plot \cr
1111
#' Column 'value': Values for that variable (raw data of columns rbinded) \cr
@@ -18,11 +18,14 @@
1818
#' @return \code{list} with: \cr
1919
#' -\code{data frame} Geometrical parameters (identity stats of ggplot) \cr
2020
#' -\code{character} Type of plot (single_group, double_group or no_group) \cr
21-
#'
21+
#'
22+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
2223
#' @export
2324

24-
boxPlotGGDS <- function(data_table, group = NULL, group2 = NULL){
25-
25+
boxPlotGGDS <- function(data_table.name, group = NULL, group2 = NULL){
26+
27+
data_table <- .loadServersideObject(data_table.name)
28+
2629
###################################################################
2730
# MODULE 1: CAPTURE THE subset filter SETTINGS #
2831
thr <- dsBase::listDisclosureSettingsDS() #

‎R/boxPlotGG_data_TreatmentDS.R‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
11
#' @title Arrange data frame to pass it to the boxplot function
22
#'
3-
#' @param table \code{data frame} Table that holds the information to be plotted later
3+
#' @param table.name \code{character} Name of a server-side data frame that holds the information to be plotted later
44
#' @param variables \code{character vector} Name of the column(s) of the data frame to include on the boxplot
5-
#' @param group \code{character} (default \code{NULL}) Name of the first grouping variable.
6-
#' @param group2 \code{character} (default \code{NULL}) Name of the second grouping variable.
5+
#' @param group \code{character} (default \code{NULL}) Name of the first grouping variable.
6+
#' @param group2 \code{character} (default \code{NULL}) Name of the second grouping variable.
77
#'
88
#' @return \code{data frame} with the following structure: \cr
9-
#'
9+
#'
1010
#' Column 'x': Names on the X axis of the boxplot, aka variables to plot \cr
1111
#' Column 'value': Values for that variable (raw data of columns rbinded) \cr
1212
#' Column 'group': (Optional) Values of the grouping variable \cr
1313
#' Column 'group2': (Optional) Values of the second grouping variable \cr
14-
#'
14+
#'
15+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
1516
#' @export
1617

17-
boxPlotGG_data_TreatmentDS <- function(table, variables, group = NULL, group2 = NULL){
18+
boxPlotGG_data_TreatmentDS <- function(table.name, variables, group = NULL, group2 = NULL){
19+
20+
table <- .loadServersideObject(table.name)
21+
22+
for(variable in variables){
23+
.checkClass(obj = table[[variable]], obj_name = variable, permitted_classes = c("numeric", "integer"))
24+
}
1825

1926
if(is.null(group) & !is.null(group2)){
2027
group <- group2
2128
group2 <- NULL
2229
}
23-
30+
2431
if(is.null(group2)){
2532
if(is.null(group)){
2633
data <- table[, c(variables)]
2734
}
2835
else{
29-
if(! any(c("factor") %in% class(table[[group]]))) {
30-
stop("Grouping variable must be of class factor")
31-
}
36+
.checkClass(obj = table[[group]], obj_name = group, permitted_classes = c("factor"))
3237
data <- table[, c(variables, group)]
3338
}
34-
39+
3540
}
3641
else{
37-
if((! any(c("factor") %in% class(table[[group]]))) | (! any(c("factor") %in% class(table[[group2]])))){
38-
stop("Grouping variable must be of class factor")
39-
}
42+
.checkClass(obj = table[[group]], obj_name = group, permitted_classes = c("factor"))
43+
.checkClass(obj = table[[group2]], obj_name = group2, permitted_classes = c("factor"))
4044
data <- table[, c(variables, group, group2)]
4145
# Handle case group == group2
4246
if(group == group2){
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
#' @title Arrange vector to pass it to the boxplot function
22
#'
3-
#' @param vector \code{numeric vector} Vector to arrange to be plotted later
3+
#' @param vector.name \code{character} Name of a server-side numeric vector to arrange to be plotted later
44
#'
55
#' @return \code{data frame} with the following structure: \cr
6-
#'
7-
#' Column 'x': Names on the X axis of the boxplot, aka name of the vector (vector argument) \cr
6+
#'
7+
#' Column 'x': Names on the X axis of the boxplot, aka name of the vector (vector.name argument) \cr
88
#' Column 'value': Values for that variable \cr
9-
#'
9+
#'
10+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
1011
#' @export
1112

12-
boxPlotGG_data_Treatment_numericDS <- function(vector){
13-
14-
data <- data.frame(x = deparse(substitute(vector)), value = vector)
15-
13+
boxPlotGG_data_Treatment_numericDS <- function(vector.name){
14+
15+
vector <- .loadServersideObject(vector.name)
16+
.checkClass(obj = vector, obj_name = vector.name, permitted_classes = c("numeric", "integer"))
17+
18+
data <- data.frame(x = vector.name, value = vector)
19+
1620
return(data)
17-
21+
1822
}

‎R/densityGridDS.R‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,31 @@
33
#' @description Generates a density grid that can then be used for heatmap or contour plots.
44
#' @details Invalid cells (cells with count < to the set filter value for the minimum allowed
55
#' counts in table cells) are turn to 0.
6-
#' @param xvect a numerical vector
7-
#' @param yvect a numerical vector
6+
#' @param x a character string providing the name of a server-side numerical vector
7+
#' @param y a character string providing the name of a server-side numerical vector
88
#' @param limits a logical expression for whether or not limits of the density grid are defined by
9-
#' a user. If \code{limits} is set to "FALSE", min and max of xvect and yvect are used as a range.
9+
#' a user. If \code{limits} is set to "FALSE", min and max of x and y are used as a range.
1010
#' If \code{limits} is set to "TRUE", limits defined by x.min, x.max, y.min and y.max are used.
1111
#' @param x.min a minimum value for the x axis of the grid density object, if needed
1212
#' @param x.max a maximum value for the x axis of the grid density object, if needed
1313
#' @param y.min a minimum value for the y axis of the grid density object, if needed
1414
#' @param y.max a maximum value for the y axis of the grid density object, if needed
1515
#' @param numints a number of intervals for the grid density object, by default is 20
16-
#' @return a grid density matrix
16+
#' @return a list with the grid density matrix (\code{grid}) and the classes of the x and y inputs
17+
#' (\code{class.x} and \code{class.y})
1718
#' @author Julia Isaeva, Amadou Gaye, Demetris Avraam for DataSHIELD Development Team
19+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
1820
#' @export
19-
#'
20-
densityGridDS <- function(xvect, yvect, limits=FALSE, x.min=NULL, x.max=NULL, y.min=NULL, y.max=NULL, numints=20){
21-
21+
#'
22+
densityGridDS <- function(x, y, limits=FALSE, x.min=NULL, x.max=NULL, y.min=NULL, y.max=NULL, numints=20){
23+
24+
xvect <- .loadServersideObject(x)
25+
yvect <- .loadServersideObject(y)
26+
.checkClass(obj = xvect, obj_name = x, permitted_classes = c("numeric", "integer"))
27+
.checkClass(obj = yvect, obj_name = y, permitted_classes = c("numeric", "integer"))
28+
2229
#############################################################
23-
# MODULE 1: CAPTURE THE nfilter SETTINGS
30+
# MODULE 1: CAPTURE THE nfilter SETTINGS
2431
thr <- dsBase::listDisclosureSettingsDS()
2532
nfilter.tab <- as.numeric(thr$nfilter.tab)
2633
#nfilter.glm <- as.numeric(thr$nfilter.glm)
@@ -93,9 +100,9 @@ densityGridDS <- function(xvect, yvect, limits=FALSE, x.min=NULL, x.max=NULL, y
93100

94101
names(dimnames(grid.density.obj))[2] <- title.text
95102
names(dimnames(grid.density.obj))[1] <- ''
96-
97-
return(grid.density.obj)
98-
103+
104+
return(list(grid=grid.density.obj, class.x=class(xvect), class.y=class(yvect)))
105+
99106
}
100107
# AGGREGATE FUNCTION
101108
# densityGridDS

‎R/heatmapPlotDS.R‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,27 @@
99
#' neighbours and the y-coordinate of the centroid is the average of the y-coordinates of the n nearest
1010
#' neighbours. The coordinates of the centroids return to the client side function and can be used for the
1111
#' plot of non-disclosive graphs (e.g. scatter plots, heatmap plots, contour plots, etc).
12-
#' @param x the name of a numeric vector, the x-variable.
13-
#' @param y the name of a numeric vector, the y-variable.
12+
#' @param x.name a character string providing the name of a server-side numeric vector, the x-variable.
13+
#' @param y.name a character string providing the name of a server-side numeric vector, the y-variable.
1414
#' @param k the number of the nearest neighbours for which their centroid is calculated if the
1515
#' \code{method.indicator} is equal to 1 (i.e. deterministic method).
1616
#' @param noise the percentage of the initial variance that is used as the variance of the embedded
1717
#' noise if the \code{method.indicator} is equal to 2 (i.e. probabilistic method).
1818
#' @param method.indicator a number equal to either 1 or 2. If the value is equal to 1 then the
1919
#' 'deterministic' method is used. If the value is set to 2 the 'probabilistic' method is used.
2020
#' @return a list with the x and y coordinates of the centroids if the deterministic method is used
21-
#' or the x and y coordinated of the noisy data if the probabilistic method is used.
21+
#' or the x and y coordinated of the noisy data if the probabilistic method is used, along with the
22+
#' classes of the x and y inputs (\code{class.x} and \code{class.y})
2223
#' @author Demetris Avraam for DataSHIELD Development Team
24+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
2325
#' @export
24-
#'
25-
heatmapPlotDS <- function(x, y, k, noise, method.indicator){
26+
#'
27+
heatmapPlotDS <- function(x.name, y.name, k, noise, method.indicator){
28+
29+
x <- .loadServersideObject(x.name)
30+
y <- .loadServersideObject(y.name)
31+
.checkClass(obj = x, obj_name = x.name, permitted_classes = c("numeric", "integer"))
32+
.checkClass(obj = y, obj_name = y.name, permitted_classes = c("numeric", "integer"))
2633

2734
###################################################################
2835
# MODULE 1: CAPTURE THE nfilter SETTINGS #
@@ -125,8 +132,8 @@ heatmapPlotDS <- function(x, y, k, noise, method.indicator){
125132
}
126133

127134
# Return a list with the x and y coordinates of the centroids
128-
return(list(x.new, y.new))
129-
135+
return(list(x.new, y.new, class.x=class(x), class.y=class(y)))
136+
130137
}
131138
# AGGREGATE FUNCTION
132139
# heatmapPlotDS

0 commit comments

Comments
 (0)