Skip to content

Commit 8a72662

Browse files
committed
add return.coords argument to allow the display of anonymised coordinates on the Console
1 parent b4b6bdc commit 8a72662

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

R/ds.scatterPlot.R

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
#' This can be set as \code{'combine'} or \code{'split'}.
6363
#' Default \code{'split'}.
6464
#' For more information see \strong{Details}.
65+
#' @param return.coords a logical. If TRUE the coordinates of the anonymised data points are return
66+
#' to the Console. Default value is FALSE.
6567
#' @param datasources a list of \code{\link{DSConnection-class}} objects obtained after login.
6668
#' If the \code{datasources} argument is not specified
6769
#' the default set of connections will be used: see \code{\link{datashield.connections_default}}.
@@ -110,7 +112,8 @@
110112
#' datasources = connections)
111113
#'
112114
#' #Example 2: generate a combined scatter plot with the probabilistic method
113-
#' #and noise = 0.5
115+
#' #and noise of variance 0.5% of the variable's variance, and display the coordinates
116+
#' # of the anonymised data points to the Console
114117
#'
115118
#' ds.scatterPlot(x = "D$PM_BMI_CONTINUOUS",
116119
#' y = "D$LAB_GLUC_ADJUSTED",
@@ -124,17 +127,17 @@
124127
#'
125128
#' }
126129
#'
127-
ds.scatterPlot <- function (x=NULL, y=NULL, method='deterministic', k=3, noise=0.25, type="split", datasources=NULL){
130+
ds.scatterPlot <- function (x=NULL, y=NULL, method='deterministic', k=3, noise=0.25, type="split", return.coords=FALSE, datasources=NULL){
128131

129-
# look for DS connections
130132
if(is.null(x)){
131-
stop("Please provide the x-variable", call.=FALSE)
133+
stop("Please provide the name of the x-variable", call.=FALSE)
132134
}
133135

134136
if(is.null(y)){
135-
stop("Please provide the y-variable", call.=FALSE)
137+
stop("Please provide the name of the y-variable", call.=FALSE)
136138
}
137139

140+
# look for DS connections
138141
if(is.null(datasources)){
139142
datasources <- datashield.connections_find()
140143
}
@@ -199,6 +202,7 @@ ds.scatterPlot <- function (x=NULL, y=NULL, method='deterministic', k=3, noise=0
199202
}
200203
pooled.points.x <- unlist(pooled.points.x)
201204
pooled.points.y <- unlist(pooled.points.y)
205+
pooled.coordinates <- cbind(x=pooled.points.x, y=pooled.points.y)
202206

203207
# plot and return the scatter plot depending on the argument "type"
204208
if(type=="combine"){
@@ -207,7 +211,11 @@ ds.scatterPlot <- function (x=NULL, y=NULL, method='deterministic', k=3, noise=0
207211
graphics::par(mfrow=c(numr,numc))
208212
graphics::plot(pooled.points.x, pooled.points.y, xlab=x.lab, ylab=y.lab, main=paste0("Combined scatter plot"))
209213
return.message <- "Combined plot created"
210-
return(return.message)
214+
if(isTRUE(return.coords)){
215+
return(list(pooled.coordinates=pooled.coordinates, message=return.message))
216+
}else{
217+
return(message=return.message)
218+
}
211219
}else{
212220
if(type=="split"){
213221
# set the graph area and plot
@@ -216,15 +224,22 @@ ds.scatterPlot <- function (x=NULL, y=NULL, method='deterministic', k=3, noise=0
216224
numc <- 2
217225
graphics::par(mfrow=c(numr,numc))
218226
scatter <- list()
219-
}
227+
}
228+
split.coordinates <- list()
220229
for(i in 1:num.sources){
221230
title <- paste0("Scatter plot of ", stdnames[i])
222231
x <- output[[i]][[1]]
223232
y <- output[[i]][[2]]
224233
graphics::plot(x, y, xlab=x.lab, ylab=y.lab, main=title)
234+
split.coordinates[[i]] <- cbind(x=output[[i]][[1]], y=output[[i]][[2]])
225235
}
236+
names(split.coordinates) <- stdnames
226237
return.message <- "Split plot created"
227-
return(return.message)
238+
if(isTRUE(return.coords)){
239+
return(list(split.coordinates, message=return.message))
240+
}else{
241+
return(message=return.message)
242+
}
228243
}else{
229244
stop('Function argument "type" has to be either "combine" or "split"')
230245
}

man/ds.scatterPlot.Rd

Lines changed: 6 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)