diff --git a/DESCRIPTION b/DESCRIPTION index d733e042..81cc2e1c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -63,7 +63,7 @@ Depends: Imports: RANN, stringr, - lme4, + lme4 (>= 2.1-0), dplyr, tibble, purrr, @@ -82,4 +82,4 @@ Suggests: Encoding: UTF-8 Language: en-GB Config/testthat/edition: 3 -Config/roxygen2/version: 8.1.0 +Config/roxygen2/version: 8.1.1 diff --git a/NAMESPACE b/NAMESPACE index 4bf3dc67..4efc223c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,8 +13,6 @@ export(asLogicalDS) export(asMatrixDS) export(asNumericDS) export(aucDS) -export(blackBoxDS) -export(blackBoxRanksDS) export(boxPlotGGDS) export(boxPlotGG_data_TreatmentDS) export(boxPlotGG_data_Treatment_numericDS) @@ -31,7 +29,6 @@ export(corDS) export(corTestDS) export(covDS) export(dataFrameDS) -export(dataFrameFillDS) export(dataFrameSortDS) export(dataFrameSubsetDS1) export(dataFrameSubsetDS2) @@ -40,8 +37,6 @@ export(dimDS) export(dmtC2SDS) export(elsplineDS) export(expDS) -export(extractQuantilesDS1) -export(extractQuantilesDS2) export(fixClassDS) export(fixColsDS) export(fixLevelsDS) @@ -93,10 +88,8 @@ export(mdPatternDS) export(meanDS) export(meanSdGpDS) export(mergeDS) -export(messageDS) export(metadataDS) export(miceDS) -export(minMaxRandDS) export(namesDS) export(nsDS) export(numNaDS) @@ -107,14 +100,8 @@ export(rNormDS) export(rPoisDS) export(rUnifDS) export(rangeDS) -export(ranksSecureDS1) -export(ranksSecureDS2) -export(ranksSecureDS3) -export(ranksSecureDS4) -export(ranksSecureDS5) export(rbindDS) export(reShapeDS) -export(recodeLevelsDS) export(recodeValuesDS) export(repDS) export(replaceNaDS) @@ -127,16 +114,12 @@ export(setSeedDS) export(skewnessDS1) export(skewnessDS2) export(sqrtDS) -export(subsetByClassDS) -export(subsetDS) export(table1DDS) -export(table2DDS) export(tableDS) export(tableDS.assign) export(tableDS2) export(tapplyDS) export(tapplyDS.assign) -export(testObjExistsDS) export(unListDS) export(uniqueDS) export(varDS) diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1cbc8c4a..00000000 --- a/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,20 +0,0 @@ -## Instructions & checklist for PR author - -### Description of changes -[Add descriptions of changes made] - -### Refactor instructions -- [ ] Replaced `x <- eval(parse(text = x.name), envir = parent.frame())` with `x <- .loadServersideObject(x)` -- [ ] If necessary, check the class of the object using `.checkClass()` - -### Testing instructions -- [ ] Writen server-side unit tests for unhappy flow -- [ ] Run `devtools::test(filter = "smk-|disc|arg")` and check it passes -- [ ] Run `devtools::check(args = '--no-tests')` and check it passes (we run tests separately to skip performance checks) -- [ ] Run `devtools::build()` and check it builds without errors - -## Instructions & checklist for PR reviewers -- [ ] Run `devtools::test(filter = "smk-|disc|arg")` and check it passes -- [ ] Run `devtools::check(args = '--no-tests')` and check it passes (we run tests separately to skip performance checks) -- [ ] Run `devtools::build()` and check it builds without errors - diff --git a/R/blackBoxDS.R b/R/blackBoxDS.R deleted file mode 100644 index 40c882a0..00000000 --- a/R/blackBoxDS.R +++ /dev/null @@ -1,385 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description The first key serverside function that sets up the V2BR for -#' ranking in the client. -#' @details Severside assign function called by ds.ranksSecure. -#' Creates pseudo-data by using the real distribution of values in V2BR -#' to create a large number of synthetic data with a similar distribution to -#' the values in V2BR but with a slightly broader distribution at both ends -#' to ensure that any extreme values in the "combined real+pseudo data vector" -#' are all pseudo-data. Also ensures that the number of decimal places of -#' the values in the V2BR is reflected by the number of decimal places in -#' the pseudodata. Finally, takes the "combined real+pseudo data vector" through -#' seven rounds of rank consistent encryption that involves algorithms -#' themselves generated by a pseudorandom process that selects which -#' transformation to apply and with what parameters. The encryption algorithms -#' are the same in each study ensuring that ranks also remain consistent between -#' studies. After encryption the encrypted "combined real+pseudo data vector" is -#' written to the serverside as a dataframe also including other key component -#' vectors from the first stage of the ranking procedure. -#' For more details about the cluster of functions that -#' collectively enable secure global ranking and estimation of global quantiles -#' see the associated document entitled "secure.global.ranking.docx". Also -#' see the header file for ds.ranksSecure -#' @param input.var.name a character string specifying the name of V2BR. This -#' argument is set by the argument with the same name in the clientside function -#' ds.ranksSecure -#' @param shared.seedval a pseudorandom number seed that ensures that the -#' processes generating the order and parameterisation of the encryption -#' algorithms are the same in each study. This argument is set by the argument -#' in the clientside function ds.ranksSecure. For more -#' details, including future plans to share this starting seed in a more secure -#' way, please see the associated document entitled "secure.global.ranking.docx" -#' and the header file for ds.ranksSecure. -#' @param synth.real.ratio an integer value representing -#' the ratio of synthetic (pseudo-data) values to the real number of -#' values in V2BR. This argument is set by the argument with the same name -#' in the clientside function ds.ranksSecure. For more details, please see the -#' associated document entitled "secure.global.ranking.docx" and the header file -#' for ds.ranksSecure. -#' @param NA.manage character string indicating how missing values (NAs) in -#' V2BR should be managed. It takes three possible values: "NA.delete", -#' "NA.low","NA.hi". This argument is set by the argument with the same name -#' in the clientside function ds.ranksSecure. For more details, please see the -#' associated document entitled "secure.global.ranking.docx" and the header file -#' for ds.ranksSecure. -#' @return writes a data frame object entitled blackbox.output.df to the -#' serverside. In each study this contains the encrypted -#' "combined real+pseudo data vector" and a range of other key components -#' from the first stage of the ranking procedure. For more details see the -#' associated document entitled "secure.global.ranking.docx" -#' @author Paul Burton 9th November, 2021 -#' @export -#' -blackBoxDS <- function(input.var.name=NULL, - shared.seedval, synth.real.ratio, NA.manage){ #START FUNC - - ####################################################### - #MODULE 1: CAPTURE THE nfilter SETTINGS - #thr<-dsBase::listDisclosureSettingsDS() - #nfilter.tab <- as.numeric(thr$nfilter.tab) - #nfilter.glm <- as.numeric(thr$nfilter.glm) - #nfilter.subset <- as.numeric(thr$nfilter.subset) - #nfilter.string <- as.numeric(thr$nfilter.string) - #nfilter.stringShort <- as.numeric(thr$nfilter.stringShort) - #nfilter.kNN <- as.numeric(thr$nfilter.kNN) - #nfilter.noise <- as.numeric(thr$nfilter.noise) - #nfilter.levels <- as.numeric(thr$nfilter.levels) - ######################################################## - - # back-up current .Random.seed and revert on.exit - if (exists(x = ".Random.seed", envir = globalenv())) { - assign(x = ".old_seed", value = .Random.seed, envir = parent.frame()); - on.exit({ assign(x = ".Random.seed", value = parent.frame()$.old_seed, envir = globalenv()); remove(".old_seed", envir = parent.frame()) }, add = TRUE) - } else - on.exit(if (exists(x = ".Random.seed", envir = globalenv())) remove(".Random.seed", envir = globalenv()), add = TRUE) - - input.var <- eval(parse(text=input.var.name), envir = parent.frame()) - - input.var.orig<-input.var - -#manage NAs - -if(NA.manage=="NA.delete"){ - input.var <- input.var[stats::complete.cases(input.var)] - input.var.orig<-input.var - } - - if(NA.manage=="NA.low"){ - input.var[is.na(input.var)]<-min.max.df[,1] - input.var.orig<-input.var - } - - if(NA.manage=="NA.hi"){ - input.var[is.na(input.var)]<-min.max.df[,2] - input.var.orig<-input.var - } - -#ESTIMATED OVERALL MEAN AND SD FROM meanQuantileDS -#SAVED IN input.mean.sd.df BY ds.dmtC2S -max.sd.input.var<-input.mean.sd.df$max.sd.input.var -mean.input.var<-input.mean.sd.df$mean.input.var - -numsubs.real<-length(input.var.orig) -numsubs.synth<-length(input.var.orig)*synth.real.ratio -numsubs<-numsubs.real+numsubs.synth - -#Create indicators for original original sequence order and real/synthetic -ID.seq.real.synth.orig<-1:numsubs -is.real.synth.orig<-c(rep(1,numsubs.real),rep(0,numsubs.synth)) - -#Allow individual implementations of blackBoxDS for groups of projects to have a -#unique but shared starting seed (given specified starting seed) but only -#the person setting up the function can know how that seed is perturbed relative -#to the specified seed - -restart.seed.transformation.control.n<-37169 -restart.seed.other.seed.actions<-67881 - -#Now set up for repeated transformations -set.seed(shared.seedval) - -#Create long fixed sequence of calls to seed to keep resetting seed at start -null.vector<-stats::runif(restart.seed.transformation.control.n,0,1) - -#Create transformation control vectors/values first so all studies -#have the same transformation controls given input random seed -#even if the lengths of later vectors (eg synthetic concealing data) are -#different between studies so would lead to inconsistent control -#vectors/values - - -control.vector<-sample(c(1,1,2,2,3,3),replace=FALSE) -#control.vector<-c(1,control.vector) -control.vector - - -control.value<-stats::runif(6,0.0001,1) -control.value - -#Reset seed for other purposes -#Include study-specific component so seeds different in each study - -#This code ensures you end up with a valid seed - -study.specific.seed<-tryCatch(sum(abs(input.var.orig),na.rm=TRUE)/abs(stats::quantile(input.var.orig,0.25,na.rm=TRUE))+abs(stats::median(input.var.orig,na.rm=TRUE))+abs(stats::quantile(input.var.orig,0.75,na.rm=TRUE))) - -if(is.na(study.specific.seed)||is.infinite(study.specific.seed)) -{ - #specific seed to ensure reproducibility if tryCatch fails - set.seed(671628) - study.specific.seed<-stats::runif(1,1000,1000000) -} - -if(study.specific.seed<1000){ - study.specific.seed<-study.specific.seed*1234 - if(study.specific.seed<1||study.specific.seed>5.0E08){ - study.specific.seed<-shared.seedval - } -} - -study.specific.seed<-round(study.specific.seed,0) - - -set.seed(shared.seedval+restart.seed.other.seed.actions+study.specific.seed) - - -#Check that no attempt has been made to enter a fake value for max.sd.input.var -#via the clientside that is close to zero so that the random component of the -#sythetic data is always effectively zero - -if(max.sd.input.var<(sqrt(stats::var(input.var, na.rm=TRUE)))/2){ - error.message<- - paste0("FAILED: the estimated standard deviation being used to generate part of the random component of the synthetic pseudodata is considerably smaller than the actual standard deviation of the input variable (V2BR) suggesting that information may have been fed in from the clientside to create a modified value that is too small. As this increases disclosure risk the whole ranking analysis has been halted") - stop(error.message, call. = FALSE) -} - -#create synthetic data vector -input.var.synth.fixed<-sample(input.var.orig,numsubs.synth,replace=TRUE) -input.var.synth.random<-stats::rnorm(numsubs.synth,0,max.sd.input.var) -input.var.synth.random.rounded<-input.var.synth.random - -input.var.synth<-input.var.synth.fixed+input.var.synth.random - -#ARE THERE MULTIPLE TIES SUGGESTING LIMITED DECIMAL PLACES OR POWERS OF 10 -#IF SO MODIFY input.var.synth ACCORDINGLY - - - num.3dp<-sum(round(input.var.orig%%0.001,2)==0) - prop.3dp<-num.3dp/length(input.var.orig) - if(prop.3dp>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,3) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - num.2dp<-sum(round(input.var.orig%%0.01,2)==0) - prop.2dp<-num.2dp/length(input.var.orig) - if(prop.2dp>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,2) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - - num.1dp<-sum(round(input.var.orig%%0.1,2)==0) - prop.1dp<-num.1dp/length(input.var.orig) - if(prop.1dp>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,1) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - num.integers<-sum(round(input.var.orig%%1,2)==0) - prop.integers<-num.integers/length(input.var.orig) - if(prop.integers>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,0) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - num.tens<-sum(round(input.var.orig%%10,2)==0) - prop.tens<-num.tens/length(input.var.orig) - if(prop.tens>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,-1) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - num.hundreds<-sum(round(input.var.orig%%100,2)==0) - prop.hundreds<-num.hundreds/length(input.var.orig) - if(prop.hundreds>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,-2) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - num.thousands<-sum(round(input.var.orig%%1000,2)==0) - prop.thousands<-num.thousands/length(input.var.orig) - if(prop.thousands>=0.25){ - input.var.synth.random.rounded<-round(input.var.synth.random,-3) - input.var.synth<-input.var.synth.fixed+input.var.synth.random.rounded - } - - -#Initialise input.var for analysis. Start by converting to values 0 to 1 -#in same order as original input.var. Going to use probit function (pnorm) for this. -#This can take any values -inf to +inf but to avoid extreme value rounding errors -#scale input.var to normal 0 1 - -input.var.real.orig<-input.var.orig - -#have to round this because otherwise eg 0.3 -> 0.2999999999999999999 -input.var.real.synth.orig<-round(c(input.var.real.orig,input.var.synth),5) - - -#input.var.probit.temp<-((input.var.real.synth.orig-mean.input.var)/max.sd.input.var) -input.var.probit.temp<-(input.var.real.synth.orig-mean.input.var)/(max.sd.input.var) -input.var.probit<-stats::pnorm(input.var.probit.temp) - - - -if(min(input.var.probit)<=0 | max(input.var.probit)>=1){ - error.message<- - paste0("FAILED: initialised values should strictly be >0 and <1 this rule has been violated - there is possiblyly an NA, inf or other error in the input.var.orig") - stop(error.message, call. = FALSE) -} - - -if(min(rank(input.var.real.synth.orig)-rank(input.var.probit))<0 | max(rank(input.var.real.synth.orig)-rank(input.var.probit))>0) { - error.message<- - paste0("FAILED: probit initialised values are not in an identical order to the original input variable please check") - stop(error.message, call. = FALSE) -} - - - -intermediate.value.matrix<-matrix(NA,ncol=8,nrow=numsubs) - -intermediate.value.matrix[,1]<-input.var.real.synth.orig -intermediate.value.matrix[,2]<-input.var.probit - -utils::head(intermediate.value.matrix) - -for(cv in 3:(length(control.vector)+2)){ - - if(control.vector[cv-2]==1){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]^(control.value[cv-2]) - } - if(control.vector[cv-2]==2){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]+(control.value[cv-2]) - } - if(control.vector[cv-2]==3){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]*(control.value[cv-2]) - } -} - -intermediate.value.matrix<-cbind(intermediate.value.matrix,ID.seq.real.synth.orig,is.real.synth.orig) -colnames(intermediate.value.matrix)<-c("input.var.real.synth.orig","input.var.probit", - 1:6,"ID.seq.real.synth.orig","is.real.synth.orig") - - - -dim(intermediate.value.matrix) -utils::head(intermediate.value.matrix) -utils::tail(intermediate.value.matrix) - - -rank.intermediate.value.matrix<-matrix(NA,ncol=8,nrow=numsubs) - - - -for(k in 1:8) -{ - rank.intermediate.value.matrix[,k]<-rank(intermediate.value.matrix[,k]) -} - -rank.intermediate.value.matrix<-cbind(rank.intermediate.value.matrix,ID.seq.real.synth.orig,is.real.synth.orig) - -colnames(rank.intermediate.value.matrix)<-c("input.var.real.synth.orig","input.var.probit", - 1:6,"ID.seq.real.synth.orig","is.real.synth.orig") - -utils::head(rank.intermediate.value.matrix) -utils::tail(rank.intermediate.value.matrix) - - -message("\nRANKS IN ALL COLUMNS ABOVE SHOULD BE THE SAME\n") - -control.vector -control.value - - -#CREATE blackBox OUTPUT DF - -intermediate.value.df<-data.frame(intermediate.value.matrix) - - -encrypted.var<-intermediate.value.df$"X6" - -ranks.input.var.real.synth.orig<-rank(intermediate.value.df$input.var.real.synth.orig) -ranks.encrypted.var<-rank(intermediate.value.df$"X6") - - -output.df<-data.frame(cbind(input.var.real.synth.orig,encrypted.var,ranks.input.var.real.synth.orig,ranks.encrypted.var,ID.seq.real.synth.orig,is.real.synth.orig)) - -utils::head(output.df) -utils::tail(output.df) - - - -#Sort df by magnitude of key variable -ord.by.val<-order(input.var.real.synth.orig) - -output.temp.sort.by.val<-output.df[ord.by.val,] - - -ID.by.val<-1:nrow(output.temp.sort.by.val) - -output.df.sort.by.val<-data.frame(cbind(output.temp.sort.by.val,ID.by.val)) - - -utils::head(output.df.sort.by.val) -utils::tail(output.df.sort.by.val) -dim(output.df.sort.by.val) - - - -blackbox.output.df <- output.df.sort.by.val - - -if(sum(round(rank(blackbox.output.df[,3])-rank(blackbox.output.df[,4]),2)==0)!=numsubs) -{ - error.message<- - paste0("FAILED: inconsistent values across different transformations in black box, - try a different seed. Altenatively this could reflect modification of the - clientside code which is not recommended. Finally, it can also occur - if the R session on one or more of the Armadillo/Opal data servers runs out - of memory") - stop(error.message, call. = FALSE) -}else{ - message("\nPROCESSING SUCCESSFUL, ALL RANKS AGREE FOR ALL TRANSFORMATIONS\n\n") -} - - -return(blackbox.output.df) - -} #END FUNCTION - -#ASSIGN -# blackBoxDS - - diff --git a/R/blackBoxRanksDS.R b/R/blackBoxRanksDS.R deleted file mode 100644 index c2380242..00000000 --- a/R/blackBoxRanksDS.R +++ /dev/null @@ -1,275 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description The second key serverside function that prepares the global -#' ranks of the the real data only generated in the first stage of the -#' ranking procedure and encrypts them in preparation for generating global -#' ranks that correspond 1 to 1 with only the real data in V2BR. -#' @details Severside assign function called by ds.ranksSecure. It takes the -#' global ranks currently held in sR5.df which reflect the global ranks based on -#' the "combined real+pseudo data vector" as encrypted by blackBoxDS -#' but with all pseudo-data stripped out. It then uses these global ranks (of -#' the real data) as if they were a new variable to be ranked. This is then -#' equivalent to blackBoxDS with the primary difference that no -#' pseudo-data are needed. This is because the global ranks are fundamentally -#' non-disclosive and so can be transferred to the clientside with no risk of -#' disclosure. However, in order to ensure that the client cannot compare -#' the list of global.ranks in sR4.df (after initial global ranking based on -#' ranking of real and pseudo-data combined) with the global.ranks to be -#' generated by blackBoxRanksDS (based solely on the real data they are -#' processed through seven more rounds of encryption as before in blackBoxDS. -#' In consequence the client remains unable to determine which of the original -#' global ranks corresponded to real data and which to pseudo-data. In -#' addition, blackBoxRanksDS does not need to determine the number of decimal -#' places in the data because it is only applied to ranks which are assumed to -#' be integers. For more details about the cluster of functions that -#' collectively enable secure global ranking and estimation of global quantiles -#' see the associated document entitled "secure.global.ranking.docx". Also -#' see the header file for ds.ranksSecure and the header file for blackBoxDS -#' @param input.var.name a character string specifying the name of the -#' vector holding the global ranks. This argument is set automatically by -#' the clientside function ds.ranksSecure -#' @param shared.seedval a pseudorandom number seed that ensures that the -#' processes generating the order and parameterisation of the encryption -#' algorithms are the same in each study. This argument is set by the argument -#' in the clientside function ds.ranksSecure. The -#' seed value shared by all studies in setting up the encryption procedures -#' in blackBoxRanksDS is arbitrarily changed from that used to set up the -#' encryption procedures in blackBoxDS, so the the set of 7 encryption -#' algorithms is deliberately different. For more -#' details, including future plans to share this starting seed in a more secure -#' way, please see the associated document entitled "secure.global.ranking.docx" -#' and the header file for ds.ranksSecure. -#' @return writes a data frame object entitled blackbox.ranks.df to the -#' serverside. In each study this contains the encrypted global ranks -#' and a range of other key components from the second stage (ranking of global -#' ranks for real observations only) of the ranking procedure. For more details -#' see the associated document entitled "secure.global.ranking.docx" -#' @author Paul Burton 9th November, 2021 -#' @export -#' -blackBoxRanksDS <- function(input.var.name=NULL, shared.seedval){ #START FUNC - - ####################################################### - #MODULE 1: CAPTURE THE nfilter SETTINGS - #thr<-dsBase::listDisclosureSettingsDS() - #nfilter.tab <- as.numeric(thr$nfilter.tab) - #nfilter.glm <- as.numeric(thr$nfilter.glm) - #nfilter.subset <- as.numeric(thr$nfilter.subset) - #nfilter.string <- as.numeric(thr$nfilter.string) - #nfilter.stringShort <- as.numeric(thr$nfilter.stringShort) - #nfilter.kNN <- as.numeric(thr$nfilter.kNN) - #nfilter.noise <- as.numeric(thr$nfilter.noise) - #nfilter.levels <- as.numeric(thr$nfilter.levels) - ######################################################## - - # back-up current .Random.seed and revert on.exit - if (exists(x = ".Random.seed", envir = globalenv())) { - assign(x = ".old_seed", value = .Random.seed, envir = parent.frame()); - on.exit({ assign(x = ".Random.seed", value = parent.frame()$.old_seed, envir = globalenv()); remove(".old_seed", envir = parent.frame()) }, add = TRUE) - } else - on.exit(if (exists(x = ".Random.seed", envir = globalenv())) remove(".Random.seed", envir = globalenv()), add = TRUE) - -input.var <- eval(parse(text=input.var.name), envir = parent.frame()) -input.global.ranks<-input.var - -#ESTIMATED OVERALL MEAN AND SD FROM meanQuantileDS -#SAVED IN input.mean.sd.df BY ds.dmtC2S -max.sd.input.ranks<-input.ranks.sd.df$max.sd.input.ranks -mean.input.ranks<-input.ranks.sd.df$mean.input.ranks - -numsubs.real<-length(input.global.ranks) - -numsubs<-numsubs.real - -#Create indicators for original original sequence order and real/synthetic -ID.seq.real.orig<-1:numsubs - -#Allow individual implementations of blackBoxDS for groups of projects to have a -#unique but shared starting seed (given specified starting seed) but only -#the person setting up the function can know how that seed is perturbed relative -#to the specified seed - -restart.seed.transformation.control.n<-78615 -restart.seed.other.seed.actions<-43 - -#Now set up for repeated transformations -shared.seedval<-(shared.seedval+19)*7 -set.seed(shared.seedval) - -#Create long fixed sequence of calls to seed to keep resetting seed at start -null.vector<-stats::runif(restart.seed.transformation.control.n,0,1) - -#Create transformation control vectors/values first so all studies -#have the same transformation controls given input random seed -#even if the lengths of later vectors (eg synthetic concealing data) are -#different between studies so would lead to inconsistent control -#vectors/values - - -control.vector<-sample(c(1,1,2,2,3,3),replace=FALSE) -#control.vector<-c(1,control.vector) -control.vector - - -control.value<-stats::runif(6,0.0001,1) -control.value - -#Reset seed for other purposes -set.seed(shared.seedval+restart.seed.other.seed.actions) - - -#Initialise input.var for analysis. Start by converting to values 0 to 1 -#in same order as original input.var. Going to use probit function (stats::pnorm) for this. -#This can take any values -inf to +inf but to avoid extreme value rounding errors -#scale input.var to normal 0 1 - -#Unlike blackBoxDS no need to check that no attempt has been made to enter a -#fake value for max.sd.input.var. That is because in blackBoxRanksDS no -#synthetic data are generated so the only impact of changing the value of -#max.sd.input.var is to change the first probit transformation. This will either -#cause the whole analysis to fail if the value of max.sd.input.var is too small -#or large or will have no effect at all. So there is no enhanced disclosure risk -#and no need for the equivalent disclosure trap. - -input.var.probit.temp<-((input.global.ranks-mean.input.ranks)/max.sd.input.ranks) -input.var.probit<-stats::pnorm(input.var.probit.temp) - - -if(min(input.var.probit)<=0 | max(input.var.probit)>=1){ - error.message<- - paste0("FAILED: initialised values should strictly be >0 and <1 this rule has been violated - there is possiblyly an NA, inf or other error in the input.global.ranks") - stop(error.message, call. = FALSE) -} - - -if(min(rank(input.global.ranks)-rank(input.var.probit))<0 | max(rank(input.global.ranks)-rank(input.var.probit))>0) { - error.message<- - paste0("FAILED: probit initialised values are not in an identical order to the original input variable please check") - stop(error.message, call. = FALSE) -} - - - -intermediate.value.matrix<-matrix(NA,ncol=8,nrow=numsubs) - -intermediate.value.matrix[,1]<-input.global.ranks -intermediate.value.matrix[,2]<-input.var.probit - - -for(cv in 3:(length(control.vector)+2)){ - - if(control.vector[cv-2]==1){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]^(control.value[cv-2]) - } - if(control.vector[cv-2]==2){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]+(control.value[cv-2]) - } - if(control.vector[cv-2]==3){ - intermediate.value.matrix[,cv]<-intermediate.value.matrix[,(cv-1)]*(control.value[cv-2]) - } -} - -intermediate.value.matrix<-cbind(intermediate.value.matrix,ID.seq.real.orig) -colnames(intermediate.value.matrix)<-c("input.global.ranks.orig","input.var.probit", - 1:6,"ID.seq.real.orig") - - - -dim(intermediate.value.matrix) -utils::head(intermediate.value.matrix) -utils::tail(intermediate.value.matrix) - - -rank.intermediate.value.matrix<-matrix(NA,ncol=8,nrow=numsubs) - - - -for(k in 1:8) -{ - rank.intermediate.value.matrix[,k]<-rank(intermediate.value.matrix[,k]) -} - -rank.intermediate.value.matrix<-cbind(rank.intermediate.value.matrix,ID.seq.real.orig) - -colnames(rank.intermediate.value.matrix)<-c("input.global.ranks.orig","input.var.probit", - 1:6,"ID.seq.real.orig") - - -message("\nRANKS IN ALL COLUMNS ABOVE SHOULD BE THE SAME\n") - -control.vector -control.value - - -#CREATE blackBox OUTPUT DF - -intermediate.value.df<-data.frame(intermediate.value.matrix) - -names(intermediate.value.df) -encrypted.global.ranks<-intermediate.value.df$"X6" - -ranks.input.global.ranks.orig<-rank(intermediate.value.df$input.global.ranks.orig) -ranks.encrypted.global.ranks<-rank(intermediate.value.df$"X6") - - -output.df<-data.frame(cbind(input.global.ranks,encrypted.global.ranks,ranks.input.global.ranks.orig,ranks.encrypted.global.ranks,ID.seq.real.orig)) - -utils::head(output.df) -utils::tail(output.df) - - - -#Sort df by magnitude of key variable -ord.by.val<-order(input.global.ranks) - -output.temp.sort.by.val<-output.df[ord.by.val,] - -utils::head(output.temp.sort.by.val) - - -ID.by.val<-1:nrow(output.temp.sort.by.val) - -output.df.sort.by.val<-data.frame(cbind(output.temp.sort.by.val,ID.by.val)) - - -utils::head(output.df.sort.by.val) -utils::tail(output.df.sort.by.val) -dim(output.df.sort.by.val) - - - -blackbox.ranks.df <- cbind(sR5.df[,c(5,1,2,3,9,6,10)],output.df.sort.by.val[,1:2]) - -colnames(blackbox.ranks.df)[3]<-"encrypted.input.var" -colnames(blackbox.ranks.df)[5]<-"global.ranks.input.from.sR5" -colnames(blackbox.ranks.df)[6]<-"is.real" -colnames(blackbox.ranks.df)[8]<-"global.ranks.after.blackbox" -colnames(blackbox.ranks.df)[9]<-"encrypted.global.ranks" - - - -utils::head(blackbox.ranks.df) - - -if(sum(round(rank(blackbox.ranks.df[,5])-rank(blackbox.ranks.df[,8]),2)==0)!=numsubs) -{ - error.message<- - paste0("FAILED: inconsistent ranking across different transformations in black box, - try a different seed. Altenatively this could reflect modification of the - clientside code which is not recommended. Finally, it can also occur - if the R session on one or more of the Armadillo/Opal data servers runs out - of memory") - stop(error.message, call. = FALSE) -}else{ - message("\nPROCESSING SUCCESSFUL, ALL RANKS AGREE FOR ALL TRANSFORMATIONS\n\n") -} - - -return(blackbox.ranks.df) - -} #END FUNCTION - -#ASSIGN -# blackBoxRanksDS - - diff --git a/R/corDS.R b/R/corDS.R index 9653900a..aba34ece 100644 --- a/R/corDS.R +++ b/R/corDS.R @@ -30,17 +30,17 @@ corDS <- function(x=NULL, y=NULL){ ############################################################# x.val <- .loadServersideObject(x) - .checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) + .checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "factor", "matrix", "data.frame")) if (!is.null(y) && !any(class(x.val) %in% c("matrix", "data.frame"))){ y.val <- .loadServersideObject(y) - .checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) + .checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "factor", "matrix", "data.frame")) } else{ y.val <- NULL } - if (is.null(y.val) && any(class(x.val) %in% c("numeric", "integer"))) { + if (is.null(y.val) && any(class(x.val) %in% c("numeric", "integer", "factor"))) { stop("If x is a numeric vector, y must also be a numeric vector.", call. = FALSE) } diff --git a/R/covDS.R b/R/covDS.R index 84f8f66b..d31858dd 100644 --- a/R/covDS.R +++ b/R/covDS.R @@ -39,17 +39,17 @@ covDS <- function(x=NULL, y=NULL, use=NULL){ ############################################################# x.val <- .loadServersideObject(x) - .checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) + .checkClass(obj = x.val, obj_name = x, permitted_classes = c("numeric", "integer", "factor", "matrix", "data.frame")) if (!is.null(y) && !any(class(x.val) %in% c("matrix", "data.frame"))){ y.val <- .loadServersideObject(y) - .checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "matrix", "data.frame")) + .checkClass(obj = y.val, obj_name = y, permitted_classes = c("numeric", "integer", "factor", "matrix", "data.frame")) } else{ y.val <- NULL } - if (is.null(y.val) && any(class(x.val) %in% c("numeric", "integer"))) { + if (is.null(y.val) && any(class(x.val) %in% c("numeric", "integer", "factor"))) { stop("If x is a numeric vector, y must also be a numeric vector.", call. = FALSE) } diff --git a/R/dataFrameFillDS.R b/R/dataFrameFillDS.R deleted file mode 100644 index 7de8d805..00000000 --- a/R/dataFrameFillDS.R +++ /dev/null @@ -1,105 +0,0 @@ -#' -#' @title dataFrameFillDS -#' @description An assign function called by the clientside ds.dataFrameFill function. -#' @details This function checks if each study has all the variables compared to the other studies -#' in the analysis. If a study does not have some of the variables, the function generates those -#' variables as vectors of missing values and combines them as columns to the input data frame. -#' Then, the "complete" in terms of the columns dataframe is saved in each server with a name -#' specified by the argument \code{newobj} on the clientside. -#' @param df.name a character string representing the name of the input data frame that will be -#' filled with extra columns with missing values if a number of variables is missing from it -#' compared to the data frames of the other studies used in the analysis. -#' @param allNames.transmit unique names of all the variables that are included in the input -#' data frames from all the used datasources. -#' @param class.vect.transmit the classes of all the variables that are included in the vector -#' \code{allNames.transmit}. -#' @param levels.vec.transmit the levels of all factor variables. -#' The classes supported are 'numeric', 'integer', 'character', 'factor' and 'logical'. -#' @return Nothing is returned to the client. The generated object is written to the serverside. -#' @author Demetris Avraam for DataSHIELD Development Team -#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands -#' @export -#' -dataFrameFillDS <- function(df.name, allNames.transmit, class.vect.transmit, levels.vec.transmit){ - - data <- .loadServersideObject(df.name) - - if(!is.null(allNames.transmit)){ - allNames <- unlist(strsplit(allNames.transmit, split=",")) - }else{ - allNames <- NULL - } - - if(!is.null(class.vect.transmit)){ - class.vect <- unlist(strsplit(class.vect.transmit, split=",")) - }else{ - class.vect <- NULL - } - - if(!is.null(levels.vec.transmit)){ - levels.vec <- strsplit(levels.vec.transmit, split=" ") - levels.vec <- lapply(levels.vec, function(x){as.numeric(unlist(strsplit(x, split=",")))}) - }else{ - levels.vec <- NULL - } - - for (class.vect.index in 1:length(class.vect)){ - if (! class.vect[class.vect.index] %in% c('numeric', 'integer', 'character', 'factor' , 'logical')){ - stop(paste0("Unexpected missing class specified: '", class.vect[class.vect.index], "'"), call.=FALSE) - } - } - - study.colnames <- colnames(data) - missingIndex <- which(!(allNames %in% study.colnames)) - - missingFactorsIndex <- which(class.vect=='factor') - if(!is.null(levels.vec)){ - missingFactorsIndex.vec <- rep(NA,length(allNames)) - for (i in 1:length(missingFactorsIndex.vec)){ - if(class.vect[[i]]=='factor'){ - missingFactorsIndex.vec[i] <- i - }else{ - missingFactorsIndex.vec[i] <- NA - } - } - nonNA.missingFactorsIndex <- length(missingFactorsIndex) - - Factorslevels <- as.list(rep(NA, length(allNames))) - for (i in 1:nonNA.missingFactorsIndex){ - Factorslevels[[missingFactorsIndex[i]]] <- levels.vec[[i]] - } - } - - if (length(missingIndex) > 0){ - missingVars <- allNames[missingIndex] - missingClass <- class.vect[missingIndex] - numRows <- nrow(data) - numCols <- length(missingVars) - - mat.new <- matrix(NA, ncol=numCols, nrow=numRows) - - df.new <- data.frame(x=mat.new, row.names=NULL) - colnames(df.new) <- missingVars - - funs <- sapply(paste0("as.", missingClass), match.fun) - df.new[] <- Map(function(dd, f) f(as.character(dd)), df.new, funs) - - if(length(which(missingClass=='factor')) > 0){ - missingLevels <- Factorslevels[missingIndex] - factor.index <- which(missingClass=='factor') - for(i in 1:length(factor.index)){ - levels(df.new[,factor.index[i]]) <- missingLevels[[factor.index[i]]] - } - } - - df.out <- cbind(data, df.new) - }else{ - df.out <- data - } - - return(df.out) - -} -# ASSIGN FUNCTION -# dataFrameFillDS - diff --git a/R/extractQuantilesDS1.R b/R/extractQuantilesDS1.R deleted file mode 100644 index d7aeef49..00000000 --- a/R/extractQuantilesDS1.R +++ /dev/null @@ -1,134 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' and use of these ranks to estimate global quantiles across all studies -#' @description identify the global values of V2BR (i.e. the values across all -#' studies) that relate to a set of quantiles to be evaluated. -#' @details Severside aggregate function called by ds.extractQuantiles via -#' ds.ranksSecure. As well as estimating the key values of V2BR that correspond -#' to the selected quantiles, this function also implements a disclosure control -#' trap. If the ratio of the total number of all observations across all studies -#' divided by the number of quantile values to be estimated is less than or -#' equal to nfilter.subset (which specifies the minimum size of a subset) the -#' process stops and an error message is returned suggesting that you might -#' try selecting a narrower range of quantiles with less quantile values to be -#' estimated as specified by the argument of the -#' function ds.ranksSecure. For more details about the cluster of functions that -#' collectively enable secure global ranking and estimation of global quantiles -#' see the associated document entitled "secure.global.ranking.docx" -#' @param extract.quantiles one of a restricted set of character strings that -#' fix the set of quantile values for which the corresponding values across -#' all studies are to be estimated. For more details -#' see the associated document entitled "secure.global.ranking.docx", the -#' header for ds.ranksSecure and ds.extractQuantiles functions. -#' The value of this argument is set in choosing the value of the argument -#' in ds.ranksSecure. -#' @param extract.summary.output.ranks.df character string specifying optional -#' name for the data.frame written to the serverside on each data source that -#' contains 5 of the key output variables from the ranking procedure pertaining -#' to that particular data source. This data frame represents the key source of -#' information - including global ranks - that determines the values of V2BR -#' that are identified as corresponding to the particular set of quantiles to -#' be estimated as specified by the argument of -#' function ds.ranksSecure (and the argument of -#' ds.extractQuantiles). -#' @return as a first step in creating the vector of values of values of V2BR -#' that correspond to each quantile value, extractQuantilesDS1 identifies the -#' two closest quantile values across all studies that span each key quantile -#' value. These are saved as the data frame "closest.bounds.df" on the -#' clientside and then saved on the serverside by ds.dmtC2S into the data frame -#' "global.bounds.df". Also if the number of observations across all studies is -#' too small, and a disclosure risk exists if the final.quantile.vector is made -#' available via the client, this function stops the processing and returns a -#' warning/error message. -#' @author Paul Burton 11th November, 2021 -#' @export -extractQuantilesDS1 <- function(extract.quantiles,extract.summary.output.ranks.df){ #START FUNC - - - ############################################################# - #MODULE 1: CAPTURE THE nfilter SETTINGS # - thr<-dsBase::listDisclosureSettingsDS() # - nfilter.tab <- as.numeric(thr$nfilter.tab) # - #nfilter.glm <- as.numeric(thr$nfilter.glm) # - nfilter.subset <- as.numeric(thr$nfilter.subset) # - #nfilter.string <- as.numeric(thr$nfilter.string) # - #nfilter.stringShort <- as.numeric(thr$nfilter.stringShort) # - #nfilter.kNN <- as.numeric(thr$nfilter.kNN) # - #nfilter.noise <- as.numeric(thr$nfilter.noise) # - #nfilter.levels <- as.numeric(thr$nfilter.levels) # - ############################################################# - - ############################################# - - extract.summary.ranks.df <- eval(parse(text=extract.summary.output.ranks.df), envir = parent.frame()) - - #Specify quantiles to evaluate - if(extract.quantiles=="0.025-0.975"){ - evaluation.quantiles<-c(0.025,0.05,0.10,0.20,0.25,0.30,0.3333,0.40,0.50,0.60,0.6667,0.70,0.75,0.80,0.90,0.95,0.975) - } - if(extract.quantiles=="0.05-0.95"){ - evaluation.quantiles<-c(0.05,0.10,0.20,0.25,0.30,0.3333,0.40,0.50,0.60,0.6667,0.70,0.75,0.80,0.90,0.95) - } - if(extract.quantiles=="0.10-0.90"){ - evaluation.quantiles<-c(0.10,0.20,0.25,0.30,0.3333,0.40,0.50,0.60,0.6667,0.70,0.75,0.80,0.90) - } - if(extract.quantiles=="0.20-0.80"){ - evaluation.quantiles<-c(0.20,0.25,0.30,0.3333,0.40,0.50,0.60,0.6667,0.70,0.75,0.80) - } - if(extract.quantiles=="quartiles"){ - evaluation.quantiles<-c(0.25,0.50,0.75) - } - if(extract.quantiles=="median"){ - evaluation.quantiles<-c(0.50) - } - - - numvals<-length(evaluation.quantiles) - numsubs.in.study<-nrow(extract.summary.ranks.df) - - #calculate total number of real data observations in variable to be ranked - #across all studies to prime disclosure control - - #Identify specific observations defining chosen evaluation quantiles - quants<-extract.summary.ranks.df$final.quantiles.global - ranks<-extract.summary.ranks.df$final.ranks.global - numsubs.real<-max(ranks/quants) - - if((numsubs.real/numvals)<=nfilter.tab){ - error.message<- - paste0("FAILED: the total number of observations across all studies is so small that there is a disclosure risk in releasing the list of quantiles requested. You could change the quantiles.for.estimation argument to request a narrower range of quantiles to be be estimated.") - stop(error.message, call. = FALSE) - } - - - lower.bound<-rep(NA,numvals) - upper.bound<-rep(NA,numvals) - - num.real.all.studies<-max() - for(qq in 1:numvals){ - disclosure.risk<-FALSE - if(length(quants<=evaluation.quantiles[qq])=evaluation.quantiles[qq])=evaluation.quantiles[qq]]) - - } - -bounds.df<-data.frame(evaluation.quantiles,lower.bound,upper.bound) - -colnames(bounds.df)<-c("evaluation.quantiles","lower.bound","upper.bound") - -return(bounds.df) -} - -#AGGREGATE -# extractQuantilesDS1 - - - - diff --git a/R/extractQuantilesDS2.R b/R/extractQuantilesDS2.R deleted file mode 100644 index 7b8ee593..00000000 --- a/R/extractQuantilesDS2.R +++ /dev/null @@ -1,95 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' and use of these ranks to estimate global quantiles across all studies -#' @description identify the global values of V2BR (i.e. the values across all -#' studies) that relate to a set of quantiles to be evaluated. -#' @details Severside aggregate function called by ds.extractQuantiles via -#' ds.ranksSecure. This takes the "global.bounds.df" data frame saved on the -#' serverside following construction by extractQuantilesDS1. This -#' data frame includes the two quantile values that most closely span each -#' quartile value to be estimated. If either of the values had been the correct -#' value for a given quantile, both the bounding values would have taken that -#' value in global.bounds.df. This is because the upper bound was defined as -#' the lowest value that was equal to or greater than the true value for that -#' quantile while the lower bound was defined as the highest value that was -#' equal to or lower than the true value. Next, the function extractQuantileDS2 -#' goes round study by study to identify the values of V2BR that actually -#' correspond to each of the spanning values around each quantile. Then the -#' function goes quantile by quantile and estimates the mean of the -#' two values of V2BR that correspond to the the spanning quantiles. If these -#' two values are the same it means that that value of V2BR is the -#' "true" value and the mean of two (or potentially several) instances of that -#' value is inevitably also equal to that true value. If the upper and lower -#' bounding values of V2BR differ, neither can be the precisely correct single -#' value of V2BR for that quantile (see above for explanation) and so the mean -#' of the two is a reasonable interpolated summary. -#' @param extract.summary.output.ranks.df character string specifies an optional -#' name for the data.frame written to the serverside on each data source that -#' contains 5 of the key output variables from the ranking procedure pertaining -#' to that particular data source. This data frame represents the key source of -#' information - including global ranks - that determines the values of V2BR -#' that are identified as corresponding to the particular set of quantiles to -#' be estimated as specified by the argument of -#' function ds.ranksSecure (and the argument of -#' ds.extractQuantiles). -#' @return the single value of V2BR which best corresponds to each key quantile -#' value to be estimated as specified by the argument -#' A data frame (final.quantile.df)summarising the results of this analysis -#' is written to the clientside. This data frame consists of two vectors. The -#' first is named "evaluation.quantiles". It lists the full set of quantiles -#' you have requested for evaluation as specified by the argument -#' "quantiles.for.estimation" The second vector which is called -#' "final.quantile.vector" details the values of V2BR that correspond to the -#' the key quantiles listed in vector 1. -#' @author Paul Burton 11th November, 2021 -#' @export -extractQuantilesDS2 <- function(extract.summary.output.ranks.df){ #START FUNC - - - ############################################################# - #MODULE 1: CAPTURE THE nfilter SETTINGS # - thr<-dsBase::listDisclosureSettingsDS() # - #nfilter.tab <- as.numeric(thr$nfilter.tab) # - #nfilter.glm <- as.numeric(thr$nfilter.glm) # - nfilter.subset <- as.numeric(thr$nfilter.subset) # - #nfilter.string <- as.numeric(thr$nfilter.string) # - #nfilter.stringShort <- as.numeric(thr$nfilter.stringShort) # - #nfilter.kNN <- as.numeric(thr$nfilter.kNN) # - #nfilter.noise <- as.numeric(thr$nfilter.noise) # - #nfilter.levels <- as.numeric(thr$nfilter.levels) # - ############################################################# - -extract.summary.ranks.df2 <- eval(parse(text=extract.summary.output.ranks.df), envir = parent.frame()) -numsubs<-nrow(extract.summary.ranks.df2) -numvals<-length(global.bounds.df$evaluation.quantiles) - - -relevant.study.specific.input.values.lower<-rep(NA,numvals) -relevant.study.specific.input.values.upper<-rep(NA,numvals) - -for(ww in 1:numvals){ - if(sum(extract.summary.ranks.df2$final.quantiles.global==global.bounds.df$lower.bound.vector[ww])>0) - { - relevant.study.specific.input.values.lower[ww]<- - mean(extract.summary.ranks.df2$input.var.real.orig[extract.summary.ranks.df2$final.quantiles.global - ==global.bounds.df$lower.bound.vector[ww]]) - } - - if(sum(extract.summary.ranks.df2$final.quantiles.global==global.bounds.df$upper.bound.vector[ww])>0) - { - relevant.study.specific.input.values.upper[ww]<- - mean(extract.summary.ranks.df2$input.var.real.orig[extract.summary.ranks.df2$final.quantiles.global - ==global.bounds.df$upper.bound.vector[ww]]) - } -} - - - return(list(relevant.study.specific.input.values.lower=relevant.study.specific.input.values.lower, - relevant.study.specific.input.values.upper=relevant.study.specific.input.values.upper)) -} - -#AGGREGATE -# extractQuantilesDS2 - - - - diff --git a/R/glmSLMADS.assign.R b/R/glmSLMADS.assign.R index 68fe6929..3448aed3 100644 --- a/R/glmSLMADS.assign.R +++ b/R/glmSLMADS.assign.R @@ -27,10 +27,10 @@ glmSLMADS.assign <- function(formula, family, offsetName, weightsName, dataName) # Correctly name offset, weights and data objects in function call # (to allow glmPredict to work correctly later) - calltext <- paste0("mg<-glm(formula,family=",family,",offset=", + calltext <- paste0("glm(formula,family=",family,",offset=", offsetName,",weights=",weightsName,",data=", dataName,",x=TRUE)") - eval(parse(text=calltext)) + mg <- eval(parse(text=calltext), envir = list(formula = formula), enclos = parent.frame()) # update the call object to include the actual formula mg$call$formula <- formula diff --git a/R/lsDS.R b/R/lsDS.R index 7558b8e0..e75b4141 100644 --- a/R/lsDS.R +++ b/R/lsDS.R @@ -37,11 +37,9 @@ nfilter.string<-as.numeric(thr$nfilter.string) # #datashield.privacyLevel<-as.numeric(thr$datashield.privacyLevel) # ######################################################################### -envir.text<-".GlobalEnv" - if(env.to.search==1L) { -envir.2.search<-eval(parse(text=envir.text)) +envir.2.search<-parent.frame() }else{ envir.2.search<-as.environment(env.to.search) } @@ -51,7 +49,7 @@ j<-0 if(is.null(search.filter)) { -outobj<-ls(pos=env.to.search) +outobj<-ls(envir=envir.2.search) outlist<-list(environment.searched=environmentName(envir.2.search),objects.found=outobj) @@ -92,10 +90,10 @@ return(outlist) search.filter.final<-paste(search.filter.temp1,collapse="") - outobj<-ls(pos=env.to.search,pattern=utils::glob2rx(search.filter.final)) + outobj<-ls(envir=envir.2.search,pattern=utils::glob2rx(search.filter.final)) }else{ - outobj<-ls(pos=env.to.search,pattern=utils::glob2rx(search.filter)) + outobj<-ls(envir=envir.2.search,pattern=utils::glob2rx(search.filter)) search.filter.final<-search.filter } diff --git a/R/messageDS.R b/R/messageDS.R deleted file mode 100644 index a148ea10..00000000 --- a/R/messageDS.R +++ /dev/null @@ -1,99 +0,0 @@ -#' -#' @title messageDS -#' @description This function allows for error messages arising from the -#' running of a server-side assign function to be returned to the client-side -#' @details Errors arising from aggregate server-side functions can be returned -#' directly to the client-side. But this is not possible for server-side assign -#' functions because they are designed specifically to write objects to the -#' server-side and to return no meaningful information to the client-side. -#' Otherwise, users may be able to use assign functions to return disclosive -#' output to the client-side. ds.message calls messageDS which looks -#' specifically for an object called $serversideMessage in a designated list on -#' the server-side. Server-side functions from which error messages are to be made -#' available, are designed to be able to write the designated error message to -#' the $serversideMessage object into the list that is saved on the server-side -#' as the primary output of that function. So only valid server-side functions of -#' DataSHIELD can write a $studysideMessage, and as additional protection against -#' unexpected ways that someone may try to get round this limitation, a -#' $studysideMessage is a string that cannot exceed a length of nfilter.string -#' a default of 80 characters. -#' @param message.object.name is a character string, containing the name of the list containing the -#' message. See the header of the client-side function ds.message for more details. -#' @return a list object from each study, containing whatever message has been written by -#' DataSHIELD into $studysideMessage. -#' @author Burton PR -#' @export -#' -messageDS <- function(message.object.name){ - -############################################################# -#MODULE 1: CAPTURE THE nfilter SETTINGS # -thr<-dsBase::listDisclosureSettingsDS() # -#nfilter.tab<-as.numeric(thr$nfilter.tab) # -#nfilter.glm<-as.numeric(thr$nfilter.glm) # -nfilter.subset<-as.numeric(thr$nfilter.subset) # -nfilter.string<-as.numeric(thr$nfilter.string) # -nfilter.stringShort<-as.numeric(thr$nfilter.stringShort) # -nfilter.kNN<-as.numeric(thr$nfilter.kNN) # -############################################################# - -#TEST IF message.object.name EXISTS AS AN OBJECT ON SERVERSIDE -#exists() must have message.object.name explicitly specified in inverted commas. -#NOT just the name of a character class object representing the name without -#inverted comma - -A1.exists.text<-paste0("exists('",message.object.name,"')") - -boole.A1.exists<-eval(parse(text=A1.exists.text), envir = parent.frame()) - - - - -if(!boole.A1.exists) { -out.obj<-"Error: the object does not exist in this datasource" -return(out.obj) -} - - - -#IF message.object.name EXISTS, CHECK WHETHER IT CURRENTLY CONTAINS A studysideMessage - -if(boole.A1.exists){ -message.object.name.active<-eval(parse(text=message.object.name), envir = parent.frame()) - - - -#CASE WHERE PRIMARY OUTPUT OBJECT IS A LIST -if("list" %in% class(message.object.name.active)){ - -#A LIST WITH NAMES - could be a studysideMessage - if(!is.null(names(message.object.name.active))) { - s.message.available<-FALSE - for(j in 1:length(names(message.object.name.active))){ - if(names(message.object.name.active)[j]=="studysideMessage"){ - s.message.available<-TRUE - out.obj<-"NOT ALL OK: there are studysideMessage(s) on this datasource" - } - } - if(!s.message.available){ - out.obj<-"ALL OK: there are no studysideMessage(s) on this datasource" - } - } - -#A LIST WITHOUT NAMES - if(is.null(names(message.object.name.active))) { - out.obj<-"Outcome object is a list without names. So a studysideMessage may be hidden. Please check output is OK" - } - -}else{ -#CASE WHERE PRIMARY OUTPUT IS AN OBJECT OF A CLASS OTHER THAN LIST - output object created OK and so no studysideMessage - out.obj<-"ALL OK: there are no studysideMessage(s) on this datasource" - } - - } - - return(MESSAGE=out.obj) - -} -#AGGREGATE FUNCTION -# messageDS diff --git a/R/minMaxRandDS.R b/R/minMaxRandDS.R deleted file mode 100644 index 64caf7ae..00000000 --- a/R/minMaxRandDS.R +++ /dev/null @@ -1,76 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description Creates a minimum value that is more negative, and less positive -#' than any real value in V2BR and a maximum value that is more positive and -#' less negative than any value of V2BR. -#' @details Severside aggregate function called by ds.ranksSecure. The minimum -#' and maximum values it creates are used to replace missing values -#' (NAs) in V2BR if the argument e is set to "NA.low" or "NA.hi" -#' respectively. For more details about the cluster of functions that -#' collectively enable secure global ranking and estimation of global quantiles -#' see the associated document entitled "secure.global.ranking.docx". Also -#' see the header file for ds.ranksSecure -#' @param input.var.name a character string specifying the name of V2BR. This -#' argument is set by the argument with the same name in the clientside function -#' ds.ranksSecure -#' @return the data frame objects containing the global ranks and quantiles. -#' For more details see the associated document entitled -#' "secure.global.ranking.docx" -#' @author Paul Burton 9th November, 2021 -#' @export -#' -minMaxRandDS <- function(input.var.name){ #START FUNC - - # back-up current .Random.seed and revert on.exit - if (exists(x = ".Random.seed", envir = globalenv())) { - assign(x = ".old_seed", value = .Random.seed, envir = parent.frame()); - on.exit({ assign(x = ".Random.seed", value = parent.frame()$.old_seed, envir = globalenv()); remove(".old_seed", envir = parent.frame()) }, add = TRUE) - } else - on.exit(if (exists(x = ".Random.seed", envir = globalenv())) remove(".Random.seed", envir = globalenv()), add = TRUE) - - input.var <- eval(parse(text=input.var.name), envir = parent.frame()) - - #create seed that is unknown and cannot be repeated - set.seed(NULL) - - mult.created<-0 - while(mult.created==0){ - rand.mult.temp<-stats::rnorm(1,1.5,0.5) - if(rand.mult.temp>1.2){ - rand.mult<-rand.mult.temp - mult.created<-1 - } - } - rand.max<-max(input.var,na.rm=TRUE) - rand.min<-min(input.var,na.rm=TRUE) - - if(rand.max<0){ - rand.max<-(-rand.max)+1 - } - - if(rand.max==0){ - rand.max<-1 - } - - rand.max<-rand.max*rand.mult - - if(rand.min>0){ - rand.min<-(-rand.min)-1 - } - - if(rand.min==0){ - rand.min<-(-1) - } - - rand.min<-rand.min*rand.mult - -rand.min.max<-c(rand.min,rand.max) - -return(rand.min.max) - -} -#AGGREGATE -# minMaxRandDS - - - - diff --git a/R/ranksSecureDS1.R b/R/ranksSecureDS1.R deleted file mode 100644 index f24a4318..00000000 --- a/R/ranksSecureDS1.R +++ /dev/null @@ -1,34 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description takes key non-disclosive components of the serverside data frame -#' blackbox.output.df over to the clientside to enable global ranking. -#' @details Severside aggregate function called by ds.ranksSecure. The -#' non-disclosive components of blackbox.output.df that are transmitted to the -#' clientside are: (1) final values of the "combined real+pseudo data vector" -#' after all seven rounds of encryption have been completed; (2) a set of -#' sequential IDs allocated after sorting the "combined real+pseudo data vector" -#' by value (in ascending order). This allows later re-linkage of values back on -#' the serverside and confirmation that that linkage is correct. For more -#' details about the cluster of functions that collectively enable secure global -#' ranking and estimation of global quantiles see the associated document -#' entitled "secure.global.ranking.docx". Also see the header file -#' for ds.ranksSecure -#' @return the non-disclosive elements of blackbox.output.df (see details) -#' on the serverside as a data frame object (called blackbox.output) -#' on the clientside. After processing to create the global ranks across all -#' studies, this is returned to the serverside as the data frame sR4.df using -#' the clientside function ds.dmtC2S -#' @author Paul Burton 9th November, 2021 -#' @export -ranksSecureDS1 <- function(){ #START FUNC - -sR2.df<-blackbox.output.df[,c(2,7)] - -return(sR2.df) -} - -#AGGREGATE -# ranksSecureDS1 - - - - diff --git a/R/ranksSecureDS2.R b/R/ranksSecureDS2.R deleted file mode 100644 index 5a4acc5e..00000000 --- a/R/ranksSecureDS2.R +++ /dev/null @@ -1,111 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description Checks that the data frame produced in creating the initial -#' global ranks (ranks based on real and pseudo-data after the running of -#' blackBoxDS)has the correct dimensions and order as the serverside data frames -#' to which it will now be appended. If either the number of rows or the order -#' of the rows are inconsistent with the pre-existing data frames on the -#' serverside an error message is returned and the processing stops. Then -#' strips out the pseudo-data leaving solely the global ranks based just on -#' the real data -#' @details Severside assign function called by ds.ranksSecure. -#' It works on the on the output created by serverside function ranksSecureDS1 -#' and saved on the serverside in data frame sR4.df by ds.dmtC2S. Having -#' checked QA it strips out all rows corresponding to pseudo-data. The resultant -#' data frame contains the following vectors: (1) the fully encrypted V2BR -#' (after application of blackBoxDS);(2) "ID.by.val" the sequential -#' ID associated with the "combined real+pseudo data vector" sorted by -#' value (ascending); (3) "studyid", a vector consisting solely of value n in -#' the nth study; (4) "global.rank" the vector containing global ranks created by -#' the clientside code in ds.ranksSecure after ranksSecureDS1 is called and up -#' to the point where ds.dmtC2S sends sR4.df to the serverside. For more -#' details about the cluster of functions that collectively enable secure global -#' ranking and estimation of global quantiles see the associated document -#' entitled "secure.global.ranking.docx". Also see the header file -#' for ds.ranksSecure -#' @return creates a new data frame sR5.df on the serverside containing -#' solely the real data and including key elements needed for next stage of the -#' ranking process. Most crucially these include "global.rank" and "ID.by.val" -#' sorted in ascending order of the magnitude of V2BR -#' @author Paul Burton 9th November, 2021 -#' @export -ranksSecureDS2 <- function(){ #START FUNC - -########################################################################## -########################################################################## -##LOCAL CODE SET UP TO CHECK ERROR TRAPS DURING DEVELOPMENT -##THIS CODE TESTED AND PASSED 11/10/21 -# -##FIRST RUN QA.ranksSecure -# -##THEN RUN THIS FUNCTION WITH NEITHER TRAP TRIGGERED (ie FROM #generic ..) -##SHOULD BE NO ERROR MESSAGES -# -##THEN RUN WITH JUST TRAP 2 TRIGGERED (i.e. FROM #trap 2) -##SHOULD JUST BE TRAP 2 ERROR MESSAGE -# -##THEN RUN QA.ranksSecure AGAIN -# -##THEN RUN WITH JUST TRAP 1 TRIGGERED (i.e. FROM #trap 1 BUT NOT #trap 2) -##SHOULD JUST BE TRAP 2 ERROR MESSAGE -# -##trap 1 -## bodf.1<-bodf.1[2:nrow(bodf.1),] -# -##trap 2 -## ord10<-order(bodf.1[,5]) -## bodf.1<-bodf.1[ord10,] -# -##generic set up no traps triggered -# -#sR4.df<-R.sR4.df.2 -#blackbox.output.df<-bodf.2 -########################################################################## -########################################################################## - -#check key data frames have the same number of rows and are in the same order -df.equivalent<-1 - -if(nrow(blackbox.output.df)!=nrow(sR4.df)){ - df.equivalent<-0 - } -if(df.equivalent==0){ -error.message<- - paste0("FAILED: in at least one study, data frame before global ranking has - a different number of rows to data.frame after global ranking. Please explore - and correct whatever may have caused this") -stop(error.message, call. = FALSE) -} - -if(sum(round(abs(blackbox.output.df$encrypted.var-sR4.df$encrypted.var),2))>0){ - df.equivalent<-0 -} - -if(df.equivalent==0){ - error.message<- - paste0("FAILED: in at least one study, data frame before global ranking is - in a different order to the data.frame after global ranking. Please explore - and correct whatever may have caused this") - stop(error.message, call. = FALSE) -} - - -sR5.df.temp<-data.frame(cbind(blackbox.output.df,sR4.df[,c(1,4,3)])) - -sR5.df.real<-sR5.df.temp[blackbox.output.df$is.real==1,] - -colnames(sR5.df.real)<-colnames(sR5.df.temp) - -colnames(sR5.df.real)[1]<-"input.var.real.orig" -colnames(sR5.df.real)[3]<-"ranks.input.var.real.orig" -colnames(sR5.df.real)[5]<-"ID.seq.real.orig" - - -return(sR5.df.real) -} - -#ASSIGN -# ranksSecureDS2 - - - - diff --git a/R/ranksSecureDS3.R b/R/ranksSecureDS3.R deleted file mode 100644 index 2d20d7fe..00000000 --- a/R/ranksSecureDS3.R +++ /dev/null @@ -1,46 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description takes key non-disclosive components of the serverside data frame -#' blackbox.ranks.df over to the clientside to enable global re-ranking of the -#' global ranks just applying to the real data (not the pseudo-data). -#' @details Severside aggregate function called by ds.ranksSecure. The -#' non-disclosive components of blackbox.ranks.df that are transmitted to the -#' clientside are: (1) final values of the encrypted global ranks vector -#' after all seven rounds of encryption have been completed; (2) a set of -#' sequential IDs allocated to the global ranks vector in each study in their -#' current order based on increasing value of V2BR. This allows later re-linkage -#' of values back on the serverside and confirmation that that linkage is -#' correct. (3) a studyid vector with all values n in the nth study. This -#' facilitates data management on the serverside during the global ranking -#' of global ranks. For more details about the cluster of functions that -#' collectively enable secure global ranking and estimation of global quantiles -#' see the associated document entitled "secure.global.ranking.docx". Also see -#' the header file for ds.ranksSecure -#' @return the non-disclosive elements of blackbox.output.df (see details) -#' on the serverside as a data frame object (called sR6.df) -#' on the clientside. After processing within ds.ranksSecure to create the -#' global ranks and global quantiles (of real data only) across all studies, -#' this is returned to the serverside as data frame "global.ranks.quantiles.df" -#' using the clientside function ds.dmtC2S. To illustrate the difference between -#' ranks and quantiles, if there are a total of 1000 original real observations -#' across all studies and one particular observation has the rank 250, it will -#' have quantile value 0.25 (i.e. 25%th value in the overall data ordered by -#' increasing value). Both ranks and quantiles can have ties. For more details -#' about the cluster of functions that collectively enable secure global ranking -#' and estimation of global quantiles see the associated document entitled -#' "secure.global.ranking.docx". Also see the header file for ds.ranksSecure -#' @author Paul Burton 9th November, 2021 -#' @export -ranksSecureDS3 <- function(){ #START FUNC - -sR6.df<-data.frame(cbind(blackbox.ranks.df[,9],1:nrow(blackbox.ranks.df),blackbox.ranks.df[,7])) -colnames(sR6.df)<-c("encrypted.ranks","ID.real.by.val","studyid") - -return(sR6.df) -} - -#AGGREGATE -# ranksSecureDS3 - - - - diff --git a/R/ranksSecureDS4.R b/R/ranksSecureDS4.R deleted file mode 100644 index 1bf3159d..00000000 --- a/R/ranksSecureDS4.R +++ /dev/null @@ -1,108 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description Creates a data frame "sR8.df" by cbinding the data frame -#' "blackBox.ranks.df" with the global ranks and global quantiles vectors in -#' "global.ranks.quantiles.df". Performs QA on this matrix and orders the -#' sR8.df data frame according to the argument in ds.ranksSecure -#' @details Severside assign function called by ds.ranksSecure. -#' Creates a data frame "sR8.df" by cbinding the data frame "blackBox.ranks.df" -#' with the global ranks and global quantiles vectors in -#' "global.ranks.quantiles.df". Checks that all components of sR8.df have the -#' correct dimensions and are consistent in their ordering. If either the -#' number of rows or the order of the rows are inconsistent with those in -#' "blackBox.ranks.df" an error message is returned and the processing stops. -#' If sR8.df passes all QA tests it is written to the serverside as a data -#' frame with its name identified by the argument in -#' ds.ranksSecure. If that argument is NULL or unspecified the data frame -#' is called "main.ranks.df". The ranksSecureDS4 function also orders the -#' combined data frame () in one of two ways: if -#' the argument in ds.ranksSecure is set to "ID.orig" the -#' combined data frame is ordered in the same way as the original V2BR vector; -#' if the argument is set to vals.orig" the combined data frame -#' is ordered by the magnitude of the values of V2BR (ascending). Having -#' created the data frame () in this manner it can now be -#' directly cbinded to either the V2BR vector itself or to a data frame, tibble -#' or matrix containing V2BR (assuming they are also in the order corresponding -#' to the argument ) and this combined object can be used as the -#' basis of analysis based on the global ranks or quantiles including a range -#' of types of non-parametric analysis. -#' @param ranks.sort.by a character string taking two possible values. These -#' are "ID.orig" and "vals.orig". These define the order in which the -#' output.ranks.df and summary.output.ranks.df data frames are presented. This -#' argument is set by the argument with the same name in ds.ranksSecure. -#' Default value is "ID.orig". -#' @return Creates the data frame identified by the name given by the argument -#' () of the ds.ranksSecure function and writes it to the -#' serverside. If the argument is NULL or unspecified the -#' output data frame is called "main.ranks.df". The data frame is ordered -#' according to the argument in ds.ranksSecure. -#' @author Paul Burton 9th November, 2021 -#' @export -ranksSecureDS4 <- function(ranks.sort.by){ #START FUNC - -sR8.df<-cbind(blackbox.ranks.df,global.ranks.quantiles.df$real.ranks.global,global.ranks.quantiles.df$real.quantiles.global) -colnames(sR8.df)[ncol(sR8.df)-1]<-"final.ranks.global" -colnames(sR8.df)[ncol(sR8.df)]<-"final.quantiles.global" - -ord.by.ID.orig<-order(sR8.df$ID.seq.real.orig) - -if(ranks.sort.by!="ID.orig" && ranks.sort.by!="vals.orig"){ - error.message<- - paste0("FAILED: ranks.sort.by must be specified as either 'ID.orig' or 'vals.orig'") - stop(error.message, call. = FALSE) -} - -if(ranks.sort.by=="ID.orig") -{ -sR8.df<-sR8.df[ord.by.ID.orig,] -} - -if(ranks.sort.by=="vals.orig") -{ - sR8.df<-sR8.df -} - -lenx<-length(sR8.df$encrypted.input.var) - -if((length(sR8.df$global.ranks.input.from.sR5)!=lenx)|| - (length(sR8.df$global.ranks.after.blackbox)!=lenx)|| - (length(sR8.df$final.ranks.global)!=lenx)|| - (length(sR8.df$final.quantiles.global)!=lenx)) -{ - error.message<- - paste0("FAILED: ranking components of different lengths. This could reflect - modification of the clientside code which is not recommended. It can - also occur if the R session on one or more of the Armadillo/Opal data servers - runs out of memory") - stop(error.message, call. = FALSE) -} - -ranks.consistent<-1 - -if(sum(round(rank(sR8.df$global.ranks.input.from.sR5)-rank(sR8.df$global.ranks.after.blackbox),2)==0)!=lenx){ - ranks.consistent<-0 -} - -if(sum(round(rank(sR8.df$global.ranks.input.from.sR5)-rank(sR8.df$final.ranks.global),2)==0)!=lenx){ -ranks.consistent<-0 -} - -if(sum(round(rank(sR8.df$global.ranks.input.from.sR5)-rank(sR8.df$final.quantiles.global),2)==0)!=lenx){ - ranks.consistent<-0 -} - -if(ranks.consistent==0) -{ - error.message<- - paste0("FAILED: inconsistent ranking across different components of ranking matrix, - try a different seed. Altenatively this could reflect modification of the - clientside code which is not recommended. Finally, it can also occur - if the R session on one or more of the Armadillo/Opal data servers runs out - of memory") - stop(error.message, call. = FALSE) -} - -return(sR8.df) -} - -#ASSIGN -# ranksSecureDS4 diff --git a/R/ranksSecureDS5.R b/R/ranksSecureDS5.R deleted file mode 100644 index eafc6681..00000000 --- a/R/ranksSecureDS5.R +++ /dev/null @@ -1,53 +0,0 @@ -#' @title Secure ranking of "V2BR" (vector to be ranked) across all sources -#' @description Summarises the serverside data frame written by ranksSecureDS4 -#' which is identified by the name given by the argument () of -#' the ds.ranksSecure function to produce a new output data frame containing -#' only 5 key variables. -#' @details Serverside assign function called by clientside function -#' ds.ranksSecure. Takes the serverside data frame written by ranksSecureDS4 -#' which is identified by the name given by the argument () of -#' the ds.ranksSecure function. This holds 11 vectors including the final -#' global ranks across all studies and final global quantiles. The data frame -#' is ordered according to the argument in ds.ranksSecure. The -#' ranksSecureDS5 function then extracts 5 key vectors from the larger data -#' frame to produce a summary data frame that is given a name specified by -#' the argument () the ds.ranksSecure function. -#' This data frame includes the following components: (1) The values of a -#' sequential ID variable (ID.seq.real.orig) created to lie alongside the -#' original V2BR vector in the same order as that vector was itself ordered. -#' These ID values therefore reflect which row in the original data corresponds -#' to a given row in the output. If the argument in -#' ds.ranksSecure is set to "ID.orig" the values of the ID.seq.real.orig vector -#' in the output data frame simply run sequentially from 1 to N where N is the -#' number of individuals in the corresponding study. If is -#' set to "vals.orig" the values of the ID.seq.real.orig vector will be -#' determined by the magnitude of the corresponding V2BR value and will -#' appear to be ordered in a haphazard manner; (2) the original values of V2BR; -#' (3) the global ranks corresponding to the original values in V2BR, with ties -#' reflected appropriately; (4) the global quantiles corresponding to the -#' original values in V2BR, with ties reflected appropriately; (5) a studyid -#' vector in which all elements take the value n in the nth study. -#' @param output.ranks.df a character string which specifies an optional name -#' for the data.frame written to the serverside on each data source that -#' contains 11 of the key output variables from the ranking procedure pertaining -#' to that particular data source. This argument is set by the argument with -#' the same name in ds.ranksSecure. -#' @return extracts 5 key vectors from the larger data frame created by -#' ranksSecureDS4 to produce a summary data frame that is written to the -#' serverside. It is given a name specified by the argument. -#' @author Paul Burton 9th November, 2021 -#' @export -ranksSecureDS5 <- function(output.ranks.df){ #START FUNC -final.summary.df <- eval(parse(text=output.ranks.df), envir = parent.frame()) - - -final.summary.df<-final.summary.df[,c(1,2,10,11,7)] - -return(final.summary.df) -} - -#ASSIGN -# ranksSecureDS5 - - - diff --git a/R/recodeLevelsDS.R b/R/recodeLevelsDS.R deleted file mode 100644 index b4c47998..00000000 --- a/R/recodeLevelsDS.R +++ /dev/null @@ -1,29 +0,0 @@ -#' -#' @title Recodes the levels of a categorical variables -#' @description The functions uses the input factor and generates a new factor -#' with new levels. -#' @param x a factor vector -#' @param classes a character vector the levels of the newt factor vector -#' @return a factor vector with the new levels -#' @author Gaye, A. -#' @export -#' -recodeLevelsDS <- function (x=NULL, classes=NULL){ - - # Check Permissive Privacy Control Level. - dsBase::checkPermissivePrivacyControlLevel(c('permissive', 'banana', 'carrot')) - - # check if the input vector is valid (i.e. meets DataSHIELD criteria) - check <- .checkDisclosureSize(x) - - if(check){ - # generate the new variable with the specified levels - levels(x) <- classes - }else{ - # generate the new variable with the specified levels but with missing values - x[1:length(x)] <- NA - } - - return(x) - -} diff --git a/R/subsetByClassDS.R b/R/subsetByClassDS.R deleted file mode 100644 index e4063482..00000000 --- a/R/subsetByClassDS.R +++ /dev/null @@ -1,79 +0,0 @@ -#' -#' @title Breaks down a dataframe or a factor into its sub-classes -#' @description The function takes a categorical vector or dataframe as input and generates subset(s) -#' vectors or dataframes for each category. Subsets are considered invalid if they hold between 1 and -#' 4 observations. -#' @details If the input data object is a dataframe it is possible to specify the variables -#' to subset on. If a subset is not 'valid' all its the values are reported as missing (i.e. NA), -#' the name of the subsets is labelled as '_INVALID'. If no variables are specified to subset on, -#' the dataframe will be subset on each of its factor variables. -#' And if none of the columns holds a factor variable a message is issued as output. A message is also -#' issued as output if the input vector is not of type factor. -#' @param data a string character, the name of the dataframe or the factor vector -#' @param variables a vector of string characters, the names of the the variables to subset on. -#' @return a list which contains the subsetted datasets -#' @author Gaye, A. -#' @export -#' -subsetByClassDS <- function(data=NULL, variables=NULL){ - - # Check Permissive Privacy Control Level. - dsBase::checkPermissivePrivacyControlLevel(c('permissive', 'banana', 'carrot')) - - # this filter sets the minimum number of observations that are allowed - - ############################################################# - # MODULE 1: CAPTURE THE nfilter SETTINGS - thr <- dsBase::listDisclosureSettingsDS() - #nfilter.tab <- as.numeric(thr$nfilter.tab) - #nfilter.glm <- as.numeric(thr$nfilter.glm) - nfilter.subset <- as.numeric(thr$nfilter.subset) - #nfilter.string <- as.numeric(thr$nfilter.string) - ############################################################# - - # evaluate the string passed on to the function as an object - input <- eval(parse(text=data), envir = parent.frame()) - - # subsetting is carried out only of the input is of type factor or data.frame - if(is.factor(input)){ - # call the internal function that generates subsets if the input is a factor variable - Dname <- extract(data)[[2]] - output <- subsetByClassHelper1(input, Dname, nfilter.subset) - }else{ - # get the names of the variables on the dataset - varnames <- colnames(input) - - # set the number of loops depending on the number of variables specified - # if no variable was specified then loop through all the variables - if(is.null(variables)){ - loop <- c(1:dim(input)[2]) - }else{ - # if the user specified variables to subset on check if those are in the dataset to subset from, - # if none of the variables is on the dataset record a message to inform the user - indx <- which(varnames %in% variables) - - if(length(indx) > 1){ - loop <- indx - }else{ - loop <- 1 - } - } - - # loop through the variables and make a subset dataframe for each level - # of each factor variable and keep the generated subset dataframes in a list - if(length(loop) > 1){ - # call the function that gets the subsets if the user specified non or more than 1 variable - out.temp <- subsetByClassHelper2(input,loop,nfilter.subset) - subsets <- out.temp[[1]] - nonfactorvars <- out.temp[[2]] - }else{ - # call the function that gets the subsets if the user specified only one variable to subset by - out.temp <- subsetByClassHelper3(input,indx,nfilter.subset) - subsets <- out.temp[[1]] - nonfactorvars <- out.temp[[2]] - } - output <- subsets - } - - return(output) -} diff --git a/R/subsetByClassHelper1.R b/R/subsetByClassHelper1.R deleted file mode 100644 index 7c288da3..00000000 --- a/R/subsetByClassHelper1.R +++ /dev/null @@ -1,41 +0,0 @@ -#' -#' @title generates subsets vectors from a factor vector -#' @description This is an internal function called by the function 'subsetByClassDS'. -#' @details The function generates subsets if the input of 'subsetByClassDS' is a factor vector. -#' @param xvect a vector of type factor. -#' @param xname the name of the vector. -#' @param filter the minimum number observation (i.e. rows) that are allowed. -#' @return a list which contains the subsets. -#' @keywords internal -#' @noRd -#' @author Gaye, A. -#' -subsetByClassHelper1 <- function(xvect=NULL, xname=NULL, filter=NULL){ - vectname <- xname - subsets <- list() - names.of.subsets <- c() - categories <- levels(xvect) - for(i in 1:length(categories)){ - indices <- which(xvect == as.numeric(categories[i])) - if(!(length(indices) < filter)){ - subsets[[i]] <- xvect[indices] - name.of.subD <- paste(vectname,".level_", categories[i], sep="") - names.of.subsets <- append(names.of.subsets, name.of.subD) - }else{ - # if any one category has between 0 and 'filter' observation turn subset content into missing values - if(length(indices) == 0){ - subsets[[i]] <- xvect[-c(1:length(xvect))] - name.of.subD <- paste(vectname,".level_", categories[i], "_EMPTY", sep="") - }else{ - temp1 <- xvect[indices] - temp1[1:length(temp1)] <- NA - subsets[[i]] <- temp1 - name.of.subD <- paste(vectname,".level_", categories[i], "_INVALID", sep="") - } - names.of.subsets <- append(names.of.subsets, name.of.subD) - } - names(subsets) <- names.of.subsets - output <- subsets - } - return(output) -} diff --git a/R/subsetByClassHelper2.R b/R/subsetByClassHelper2.R deleted file mode 100644 index f59cc907..00000000 --- a/R/subsetByClassHelper2.R +++ /dev/null @@ -1,64 +0,0 @@ -#' -#' @title generates subset tables from a data frame -#' @description This is an internal function called by the function 'subsetByClassDS' -#' @details The function generates subsets if the input of 'subsetByClassDS' is a data frame -#' and if the number variables(columns) to subset by are greater than 1; i.e. this -#' function is called if the user specified more than one variable or no variable to subset by -#' (if no variables are specified the function 'subsetByClassDS' produces a subset for each category -#' in each variable). -#' @param df a data frame. -#' @param iter the indices of columns to loop trough. -#' @param filter the minimum number of observations (i.e. rows) that are allowed. -#' @return a list which contains the subsets, their names and an integer that indicates how many columns were -#' not factors. -#' @keywords internal -#' @noRd -#' @author Gaye, A. -#' -subsetByClassHelper2 <- function(df=NULL, iter=NULL, filter=NULL){ - # various counters and temporary variables to hold info - subsets <- list() - names.of.subsets <- c() - count <- 0 - nonfactorvars <- 0 - ncols <- length(colnames(df)) - for(i in iter){ - var <- df[,i] - varname <- colnames(df)[i] - if(is.factor(var)){ - # get the levels - categories <- levels(var) - # loop through the levels and generate a dataset for each level - # if the number of observations for that level > 0 and < 'filter' - for(j in 1:length(categories)){ - indices <- which(var == as.numeric(categories[j])) - if(!(length(indices) < filter)){ - count <- count+1 - subD <- df[indices,] - subsets[[count]] <- subD - name.of.subD <- paste(varname,".level_", categories[j], sep="") - names.of.subsets <- append(names.of.subsets, name.of.subD) - }else{ - # if any one category has between 1 and 'filter' number of observation turn subset content into missing values - count <- count+1 - if(length(indices) == 0){ - subsets[[count]] <- df[-c(1:dim(df)[1]),] - name.of.subD <- paste(varname,".level_", categories[j], "_EMPTY",sep="") - }else{ - subD <- df[indices,] - subD[] <- NA - subsets[[count]] <- subD - name.of.subD <- paste(varname,".level_", categories[j], "_INVALID",sep="") - } - colnames(subsets[[count]]) <- colnames(df) - names.of.subsets <- append(names.of.subsets, name.of.subD) - } - } - names(subsets) <- names.of.subsets - }else{ - # if a variable is not a factor increment the below counter - nonfactorvars <- nonfactorvars + 1 - } - } - return(list(subsets, nonfactorvars)) -} \ No newline at end of file diff --git a/R/subsetByClassHelper3.R b/R/subsetByClassHelper3.R deleted file mode 100644 index de401f62..00000000 --- a/R/subsetByClassHelper3.R +++ /dev/null @@ -1,59 +0,0 @@ -#' -#' @title generates subset tables from a data frame -#' @description This is an internal function called by the function 'subsetByClassDS' -#' @details The function generates subsets if the input of 'subsetByClassDS' is a data frame -#' and if the number of variables (columns) to subset by is 1; i.e. this -#' function is called if the user specified one variable to subset by. -#' @param df a data frame. -#' @param indx1 the column index of the variable specified by the user. -#' @param filter the minimum number of observations (i.e. rows) that are allowed. -#' @return a list which contains the subsets, their names and an integer that indicates if -#' the variable specified by user is a factor. -#' @keywords internal -#' @noRd -#' @author Gaye, A. -#' -subsetByClassHelper3 <- function(df=NULL, indx1=NULL, filter=NULL){ - # various counters and temporary variables to hold info - subsets <- list() - names.of.subsets <- c() - count <- 0 - nonfactorvars <- 0 - ncols <- length(colnames(df)) - var <- df[,indx1] - varname <- colnames(df)[indx1] - if(is.factor(var)){ - # get the levels - categories <- levels(var) - # loop through the levels and generate a dataset for each level - # if the number of observations for that level > 0 and < 'filter' - for(j in 1:length(categories)){ - indices <- which(var == as.numeric(categories[j])) - if(!(length(indices) < filter)){ - count <- count+1 - subD <- df[indices,] - subsets[[count]] <- subD - name.of.subD <- paste(varname,".level_", categories[j], sep="") - names.of.subsets <- append(names.of.subsets, name.of.subD) - }else{ - # if any one category has between 1 and 'filter' number of observations turn subset content into missing values - count <- count+1 - if(length(indices) == 0){ - subsets[[count]] <- df[-c(1:dim(df)[1]),] - name.of.subD <- paste(varname,".level_", categories[j], "_EMPTY",sep="") - }else{ - subD <- df[indices,] - subD[] <- NA - subsets[[count]] <- subD - name.of.subD <- paste(varname,".level_", categories[j], "_INVALID",sep="") - } - colnames(subsets[[count]]) <- colnames(df) - names.of.subsets <- append(names.of.subsets, name.of.subD) - } - } - names(subsets) <- names.of.subsets - }else{ - nonfactorvars <- 1 - } - return(list(subsets, nonfactorvars)) -} \ No newline at end of file diff --git a/R/subsetDS.R b/R/subsetDS.R deleted file mode 100644 index 2ab0a14c..00000000 --- a/R/subsetDS.R +++ /dev/null @@ -1,134 +0,0 @@ -#' -#' @title Generates a valid subset of a table or a vector -#' @description The function uses the R classical subsetting with squared brackets '[]' and allows also to -#' subset using a logical operator and a threshold. The object to subset from must be a vector (factor, numeric -#' or character) or a table (data.frame or matrix). -#' @details If the input data is a table: The user specifies the rows and/or columns to include in the subset if the input -#' object is a table; the columns can be referred to by their names. The name of a vector (i.e. a variable) can also be provided -#' with a logical operator and a threshold (see example 3). -#' If the input data is a vector: when the parameters 'rows', 'logical' and 'threshold' are all provided the last two are ignored ( -#' 'rows' has precedence over the other two parameters then). -#' If the requested subset is not valid (i.e. contains less than the allowed -#' number of observations), the subset is not generated, rather a table or a vector of missing values is generated to allow -#' for any subsequent process using the output of the function to proceed after informing the user via a message. -#' @param dt a string character, the name of the dataframe or the factor vector and the range of the subset. -#' @param complt a boolean that tells if the subset to subset should include only complete cases -#' @param rs a vector of two integers that give the range of rows de extract. -#' @param cs a vector of two integers or one or more characters; the indices of the columns to extract or the names of the columns (i.e. -#' names of the variables to extract). -#' @param lg a character, the logical parameter to use if the user wishes to subset a vector using a logical -#' operator. This parameter is ignored if the input data is not a vector. -#' @param th a numeric, the threshold to use in conjunction with the logical parameter. This parameter is ignored -#' if the input data is not a vector. -#' @param varname a character, if the input data is a table, if this parameter is provided along with the 'logical' and 'threshold' -#' parameters, a subtable is based the threshold applied to the specified variable. This parameter is however ignored if the parameter -#' 'rows' and/or 'cols' are provided. -#' @return a subset of the vector, matrix or dataframe as specified is stored on the server side -#' @author Gaye, A. -#' @export -#' -subsetDS <- function(dt=NULL, complt=NULL, rs=NULL, cs=NULL, lg=NULL, th=NULL, varname=NULL){ - - # Check Permissive Privacy Control Level. - dsBase::checkPermissivePrivacyControlLevel(c('permissive', 'banana', 'carrot')) - - # this filter sets the minimum number of observations that are allowed - - ############################################################# - # MODULE 1: CAPTURE THE nfilter SETTINGS - thr <- dsBase::listDisclosureSettingsDS() - nfilter.tab <- as.numeric(thr$nfilter.tab) - #nfilter.glm <- as.numeric(thr$nfilter.glm) - #nfilter.subset <- as.numeric(thr$nfilter.subset) - #nfilter.string <- as.numeric(thr$nfilter.string) - ############################################################# - - # the logical operators are given as integers change them into characters - if(!(is.null(lg))){ - if(lg == 1){lg <- ">"} - if(lg == 2){lg <- ">="} - if(lg == 3){lg <- "<"} - if(lg == 4){lg <- "<="} - if(lg == 5){lg <- "=="} - if(lg == 6){lg <- "!="} - } - - # evaluate the input data object - D <- eval(parse(text=dt), envir = parent.frame()) - - # if 'complt' is set to TRUE, get continue with a dataset with complete cases only - if(complt){ - cc <- stats::complete.cases(D) - xx <- which(cc == TRUE) - Dtemp <- D - if(is.vector(D) | is.factor(D)){ - D <- Dtemp[xx] - }else{ - D <- Dtemp[xx,] - } - } - - # carry out the subsetting - if(is.vector(D) | is.factor(D)){ # if the input data is a vector - - if(is.null(rs)){ - if(is.null(lg) | is.null(th)){ - subvect <- D - }else{ - exprs1 <- paste0("D[which(D", lg, th, ")]") - subvect <- eval(parse(text=exprs1)) - } - }else{ - subvect <- D[rs] - } - - if(length(subvect) < nfilter.tab){ - if(length(subvect) == 0){ - output <- D[-c(1:length(D))] - }else{ - temp1 <- subvect - temp1[1:length(temp1)] <- NA - output <- temp1 - } - }else{ - output <- subvect - } - }else{ # if the input data is a table - - if(!(is.null(rs)) | !(is.null(cs))){ - if(!(is.null(rs)) & !(is.null(cs))){ - subtable <- D[rs, cs] - }else{ - if(is.null(cs)){ - cs <- c(1:dim(D)[2]) - } - if(is.null(rs)){ - rs <- c(1:dim(D)[1]) - } - subtable <- D[rs,cs] - } - }else{ - if(is.null(varname)){ - subtable <- D - }else{ - idx <- which(colnames(D) == varname) - exprs2 <- paste0('D[which(D[,',idx,']', lg, th, '),]') - subtable <- eval(parse(text=exprs2)) - } - } - - if((dim(subtable)[1]) < nfilter.tab){ - if((dim(subtable)[1]) == 0){ - output <- D[-c(1:dim(D)[1]),] - }else{ - subD <- subtable - subD[] <- NA - output <- subD - } - }else{ - output <- subtable - } - } - - return(output) -} diff --git a/R/table2DDS.R b/R/table2DDS.R deleted file mode 100644 index 5b4f5dd1..00000000 --- a/R/table2DDS.R +++ /dev/null @@ -1,61 +0,0 @@ -#' -#' @title table2DDS (aggregate function) called by ds.table2D -#' @description This function generates a 2-dimensional contingency table where potentially disclosive cells -#' (based on a set threshold) are replaced by a missing value ('NA'). -#' @details It generates 2-dimensional contingency tables where valid (non-disclosive) tables are defined -#' as those where none of their cells have counts between 1 and the set threshold "nfilter.tab". When the output table -#' is invalid all cells except the total counts are replaced by missing values. Only the total counts are visible -#' on the table returned to the client side. A message is also returned with the 2-dimensional table; the message -#' says "invalid table - invalid counts present" if the table is invalid and 'valid table' otherwise. -#' @param xvect a numerical vector with discrete values - usually a factor. -#' @param yvect a numerical vector with discrete values - usually a factor. -#' @return a list which contains two elements: 'table', the 2-dimensional table and 'message' a message which -#' informs about the validity of the table. -#' @author Amadou Gaye, Paul Burton, Demetris Avraam for DataSHIELD Development Team -#' @export -#' -table2DDS <- function(xvect,yvect){ - - ############################################################# - #MODULE 1: CAPTURE THE nfilter SETTINGS - thr <- dsBase::listDisclosureSettingsDS() - nfilter.tab <- as.numeric(thr$nfilter.tab) - #nfilter.glm<-as.numeric(thr$nfilter.glm) - #nfilter.subset<-as.numeric(thr$nfilter.subset) - #nfilter.string<-as.numeric(thr$nfilter.string) - #nfilter.stringShort<-as.numeric(thr$nfilter.stringShort) - #nfilter.kNN<-as.numeric(thr$nfilter.kNN) - ############################################################# - - # tabulate the input vector and output the result in a data frame format - aa <- table(xvect, yvect) - bb <- matrix(NA, nrow=dim(aa)[1], ncol=dim(aa)[2]) - for(i in 1:dim(aa)[1]){ - bb[i,] <- aa[i,] - } - bb <- rbind(bb, colSums(bb)) - bb <- cbind(bb, rowSums(bb)) - cc <- as.data.frame(bb) - colnames(cc) <- c(levels(as.factor(yvect)), "Total") - rownames(cc) <- c(levels(as.factor(xvect)), "Total") - - # the minimum non-zero number of observations that is allowed in a single cell - nfilter <- nfilter.tab - - # check for invalid cells if any found change them to 'NA' and set the validity message accordingly - validity <- "valid Table" - for(i in 1: dim(cc)[2]){ - indx <- which(cc[1:(dim(cc)[1] - 1),i] > 0 & cc[1:(dim(cc)[1] - 1),i] < nfilter) - if(length(indx) > 0){ - cc[1:(dim(cc)[1] - 1), 1:(dim(cc)[2] - 1)] <- NA - validity <- "invalid table - invalid counts present" - break - } - } - - # return output table and message - return(list(table=cc, message=validity)) - -} -#AGGREGATE FUNCTION -# table2DDS diff --git a/R/testObjExistsDS.R b/R/testObjExistsDS.R deleted file mode 100644 index 9c3a26e7..00000000 --- a/R/testObjExistsDS.R +++ /dev/null @@ -1,33 +0,0 @@ -#' -#' @title testObjExistsDS -#' @description The server-side function called by ds.testObjExists -#' @details Tests whether a given object exists in -#' all sources. It is called at the end of all -#' recently written assign functions to check the new (assigned) object has been -#' created in all sources -#' @param test.obj.name a client-side provided character string specifying the variable -#' whose presence is to be tested in each data source -#' -#' @author Burton PR -#' -#' @return List with `test.obj.exists` and `test.obj.class` -#' @export -#' -testObjExistsDS <- function(test.obj.name=NULL){ - - test.obj.exists <- FALSE - test.obj.class <- NULL - - #Restrict tests to settings where name does exist to avoid error termination - - if(exists(test.obj.name, envir = parent.frame())){ - test.obj.exists <- TRUE - test.obj <- get(test.obj.name, envir = parent.frame()) - test.obj.class <- class(test.obj) - } - - return(list(test.obj.exists=test.obj.exists,test.obj.class=test.obj.class)) - -} -#AGGREGATE FUNCTION -# testObjExistsDS diff --git a/inst/DATASHIELD b/inst/DATASHIELD index e69da687..3e08f68e 100644 --- a/inst/DATASHIELD +++ b/inst/DATASHIELD @@ -1,6 +1,5 @@ AggregateMethods: asFactorDS1, - asListDS, aucDS, boxPlotGGDS, checkNegValueDS, @@ -11,8 +10,6 @@ AggregateMethods: covDS, dataFrameSubsetDS1, densityGridDS, - extractQuantilesDS1, - extractQuantilesDS2, dimDS, gamlssDS, glmDS1, @@ -40,16 +37,12 @@ AggregateMethods: mdPatternDS, meanDS, meanSdGpDS, - messageDS, metadataDS, miceDS, - minMaxRandDS, namesDS, numNaDS, quantileMeanDS, rangeDS, - ranksSecureDS1, - ranksSecureDS3, rmDS, scatterPlotDS, scoreVectDS, @@ -57,11 +50,9 @@ AggregateMethods: skewnessDS1, skewnessDS2, table1DDS, - table2DDS, tableDS, tableDS2, tapplyDS, - testObjExistsDS, varDS, exists=base::exists, is.character=base::is.character, @@ -84,8 +75,6 @@ AssignMethods: asLogicalDS, asMatrixDS, asNumericDS, - blackBoxDS, - blackBoxRanksDS, BooleDS, boxPlotGG_data_TreatmentDS, boxPlotGG_data_Treatment_numericDS, @@ -95,7 +84,6 @@ AssignMethods: changeRefGroupDS, completeCasesDS, dataFrameDS, - dataFrameFillDS, dataFrameSortDS, dataFrameSubsetDS2, dmtC2SDS, @@ -121,12 +109,8 @@ AssignMethods: mergeDS, nsDS, qlsplineDS, - ranksSecureDS2, - ranksSecureDS4, - ranksSecureDS5, rbindDS, rBinomDS, - recodeLevelsDS, recodeValuesDS, repDS, replaceNaDS, @@ -138,8 +122,6 @@ AssignMethods: sampleDS, seqDS, sqrtDS, - subsetByClassDS, - subsetDS, tableDS.assign, tapplyDS.assign, uniqueDS, diff --git a/inst/WORDLIST b/inst/WORDLIST index 23ca495f..351aee80 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -92,8 +92,6 @@ auc aucDS bfa blackBox -blackBoxDS -blackBoxRanksDS blackbox booleans bp @@ -119,7 +117,6 @@ cyc dataFrame dataFrameDS dataFrameFill -dataFrameFillDS dataFrameShort dataFrameSort dataFrameSortDS @@ -208,7 +205,6 @@ maxit mdata meanSdGp mergeDS -messageDS messageobj metafor mfa @@ -302,7 +298,6 @@ tableDS tapply tapplyDS testObjExists -testObjExistsDS th tibble timevar diff --git a/man/blackBoxDS.Rd b/man/blackBoxDS.Rd deleted file mode 100644 index 3621284b..00000000 --- a/man/blackBoxDS.Rd +++ /dev/null @@ -1,70 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/blackBoxDS.R -\name{blackBoxDS} -\alias{blackBoxDS} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -blackBoxDS(input.var.name = NULL, shared.seedval, synth.real.ratio, NA.manage) -} -\arguments{ -\item{input.var.name}{a character string specifying the name of V2BR. This -argument is set by the argument with the same name in the clientside function -ds.ranksSecure} - -\item{shared.seedval}{a pseudorandom number seed that ensures that the -processes generating the order and parameterisation of the encryption -algorithms are the same in each study. This argument is set by the argument - in the clientside function ds.ranksSecure. For more -details, including future plans to share this starting seed in a more secure -way, please see the associated document entitled "secure.global.ranking.docx" -and the header file for ds.ranksSecure.} - -\item{synth.real.ratio}{an integer value representing -the ratio of synthetic (pseudo-data) values to the real number of -values in V2BR. This argument is set by the argument with the same name -in the clientside function ds.ranksSecure. For more details, please see the -associated document entitled "secure.global.ranking.docx" and the header file -for ds.ranksSecure.} - -\item{NA.manage}{character string indicating how missing values (NAs) in -V2BR should be managed. It takes three possible values: "NA.delete", -"NA.low","NA.hi". This argument is set by the argument with the same name -in the clientside function ds.ranksSecure. For more details, please see the -associated document entitled "secure.global.ranking.docx" and the header file -for ds.ranksSecure.} -} -\value{ -writes a data frame object entitled blackbox.output.df to the -serverside. In each study this contains the encrypted -"combined real+pseudo data vector" and a range of other key components -from the first stage of the ranking procedure. For more details see the -associated document entitled "secure.global.ranking.docx" -} -\description{ -The first key serverside function that sets up the V2BR for -ranking in the client. -} -\details{ -Severside assign function called by ds.ranksSecure. -Creates pseudo-data by using the real distribution of values in V2BR -to create a large number of synthetic data with a similar distribution to -the values in V2BR but with a slightly broader distribution at both ends -to ensure that any extreme values in the "combined real+pseudo data vector" -are all pseudo-data. Also ensures that the number of decimal places of -the values in the V2BR is reflected by the number of decimal places in -the pseudodata. Finally, takes the "combined real+pseudo data vector" through -seven rounds of rank consistent encryption that involves algorithms -themselves generated by a pseudorandom process that selects which -transformation to apply and with what parameters. The encryption algorithms -are the same in each study ensuring that ranks also remain consistent between -studies. After encryption the encrypted "combined real+pseudo data vector" is -written to the serverside as a dataframe also including other key component -vectors from the first stage of the ranking procedure. -For more details about the cluster of functions that -collectively enable secure global ranking and estimation of global quantiles -see the associated document entitled "secure.global.ranking.docx". Also -see the header file for ds.ranksSecure -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/blackBoxRanksDS.Rd b/man/blackBoxRanksDS.Rd deleted file mode 100644 index f5446a31..00000000 --- a/man/blackBoxRanksDS.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/blackBoxRanksDS.R -\name{blackBoxRanksDS} -\alias{blackBoxRanksDS} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -blackBoxRanksDS(input.var.name = NULL, shared.seedval) -} -\arguments{ -\item{input.var.name}{a character string specifying the name of the -vector holding the global ranks. This argument is set automatically by -the clientside function ds.ranksSecure} - -\item{shared.seedval}{a pseudorandom number seed that ensures that the -processes generating the order and parameterisation of the encryption -algorithms are the same in each study. This argument is set by the argument - in the clientside function ds.ranksSecure. The -seed value shared by all studies in setting up the encryption procedures -in blackBoxRanksDS is arbitrarily changed from that used to set up the -encryption procedures in blackBoxDS, so the the set of 7 encryption -algorithms is deliberately different. For more -details, including future plans to share this starting seed in a more secure -way, please see the associated document entitled "secure.global.ranking.docx" -and the header file for ds.ranksSecure.} -} -\value{ -writes a data frame object entitled blackbox.ranks.df to the -serverside. In each study this contains the encrypted global ranks -and a range of other key components from the second stage (ranking of global -ranks for real observations only) of the ranking procedure. For more details -see the associated document entitled "secure.global.ranking.docx" -} -\description{ -The second key serverside function that prepares the global -ranks of the the real data only generated in the first stage of the -ranking procedure and encrypts them in preparation for generating global -ranks that correspond 1 to 1 with only the real data in V2BR. -} -\details{ -Severside assign function called by ds.ranksSecure. It takes the -global ranks currently held in sR5.df which reflect the global ranks based on -the "combined real+pseudo data vector" as encrypted by blackBoxDS -but with all pseudo-data stripped out. It then uses these global ranks (of -the real data) as if they were a new variable to be ranked. This is then -equivalent to blackBoxDS with the primary difference that no -pseudo-data are needed. This is because the global ranks are fundamentally -non-disclosive and so can be transferred to the clientside with no risk of -disclosure. However, in order to ensure that the client cannot compare -the list of global.ranks in sR4.df (after initial global ranking based on -ranking of real and pseudo-data combined) with the global.ranks to be -generated by blackBoxRanksDS (based solely on the real data they are -processed through seven more rounds of encryption as before in blackBoxDS. -In consequence the client remains unable to determine which of the original -global ranks corresponded to real data and which to pseudo-data. In -addition, blackBoxRanksDS does not need to determine the number of decimal -places in the data because it is only applied to ranks which are assumed to -be integers. For more details about the cluster of functions that -collectively enable secure global ranking and estimation of global quantiles -see the associated document entitled "secure.global.ranking.docx". Also -see the header file for ds.ranksSecure and the header file for blackBoxDS -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/dataFrameFillDS.Rd b/man/dataFrameFillDS.Rd deleted file mode 100644 index 65899c34..00000000 --- a/man/dataFrameFillDS.Rd +++ /dev/null @@ -1,45 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dataFrameFillDS.R -\name{dataFrameFillDS} -\alias{dataFrameFillDS} -\title{dataFrameFillDS} -\usage{ -dataFrameFillDS( - df.name, - allNames.transmit, - class.vect.transmit, - levels.vec.transmit -) -} -\arguments{ -\item{df.name}{a character string representing the name of the input data frame that will be -filled with extra columns with missing values if a number of variables is missing from it -compared to the data frames of the other studies used in the analysis.} - -\item{allNames.transmit}{unique names of all the variables that are included in the input -data frames from all the used datasources.} - -\item{class.vect.transmit}{the classes of all the variables that are included in the vector -\code{allNames.transmit}.} - -\item{levels.vec.transmit}{the levels of all factor variables. -The classes supported are 'numeric', 'integer', 'character', 'factor' and 'logical'.} -} -\value{ -Nothing is returned to the client. The generated object is written to the serverside. -} -\description{ -An assign function called by the clientside ds.dataFrameFill function. -} -\details{ -This function checks if each study has all the variables compared to the other studies -in the analysis. If a study does not have some of the variables, the function generates those -variables as vectors of missing values and combines them as columns to the input data frame. -Then, the "complete" in terms of the columns dataframe is saved in each server with a name -specified by the argument \code{newobj} on the clientside. -} -\author{ -Demetris Avraam for DataSHIELD Development Team - -Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands -} diff --git a/man/extractQuantilesDS1.Rd b/man/extractQuantilesDS1.Rd deleted file mode 100644 index 4aae2dfc..00000000 --- a/man/extractQuantilesDS1.Rd +++ /dev/null @@ -1,60 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/extractQuantilesDS1.R -\name{extractQuantilesDS1} -\alias{extractQuantilesDS1} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources -and use of these ranks to estimate global quantiles across all studies} -\usage{ -extractQuantilesDS1(extract.quantiles, extract.summary.output.ranks.df) -} -\arguments{ -\item{extract.quantiles}{one of a restricted set of character strings that -fix the set of quantile values for which the corresponding values across -all studies are to be estimated. For more details -see the associated document entitled "secure.global.ranking.docx", the -header for ds.ranksSecure and ds.extractQuantiles functions. -The value of this argument is set in choosing the value of the argument - in ds.ranksSecure.} - -\item{extract.summary.output.ranks.df}{character string specifying optional -name for the data.frame written to the serverside on each data source that -contains 5 of the key output variables from the ranking procedure pertaining -to that particular data source. This data frame represents the key source of -information - including global ranks - that determines the values of V2BR -that are identified as corresponding to the particular set of quantiles to -be estimated as specified by the argument of -function ds.ranksSecure (and the argument of -ds.extractQuantiles).} -} -\value{ -as a first step in creating the vector of values of values of V2BR -that correspond to each quantile value, extractQuantilesDS1 identifies the -two closest quantile values across all studies that span each key quantile -value. These are saved as the data frame "closest.bounds.df" on the -clientside and then saved on the serverside by ds.dmtC2S into the data frame -"global.bounds.df". Also if the number of observations across all studies is -too small, and a disclosure risk exists if the final.quantile.vector is made -available via the client, this function stops the processing and returns a -warning/error message. -} -\description{ -identify the global values of V2BR (i.e. the values across all -studies) that relate to a set of quantiles to be evaluated. -} -\details{ -Severside aggregate function called by ds.extractQuantiles via -ds.ranksSecure. As well as estimating the key values of V2BR that correspond -to the selected quantiles, this function also implements a disclosure control -trap. If the ratio of the total number of all observations across all studies -divided by the number of quantile values to be estimated is less than or -equal to nfilter.subset (which specifies the minimum size of a subset) the -process stops and an error message is returned suggesting that you might -try selecting a narrower range of quantiles with less quantile values to be -estimated as specified by the argument of the -function ds.ranksSecure. For more details about the cluster of functions that -collectively enable secure global ranking and estimation of global quantiles -see the associated document entitled "secure.global.ranking.docx" -} -\author{ -Paul Burton 11th November, 2021 -} diff --git a/man/extractQuantilesDS2.Rd b/man/extractQuantilesDS2.Rd deleted file mode 100644 index c4213f6b..00000000 --- a/man/extractQuantilesDS2.Rd +++ /dev/null @@ -1,60 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/extractQuantilesDS2.R -\name{extractQuantilesDS2} -\alias{extractQuantilesDS2} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources -and use of these ranks to estimate global quantiles across all studies} -\usage{ -extractQuantilesDS2(extract.summary.output.ranks.df) -} -\arguments{ -\item{extract.summary.output.ranks.df}{character string specifies an optional -name for the data.frame written to the serverside on each data source that -contains 5 of the key output variables from the ranking procedure pertaining -to that particular data source. This data frame represents the key source of -information - including global ranks - that determines the values of V2BR -that are identified as corresponding to the particular set of quantiles to -be estimated as specified by the argument of -function ds.ranksSecure (and the argument of -ds.extractQuantiles).} -} -\value{ -the single value of V2BR which best corresponds to each key quantile -value to be estimated as specified by the argument -A data frame (final.quantile.df)summarising the results of this analysis -is written to the clientside. This data frame consists of two vectors. The -first is named "evaluation.quantiles". It lists the full set of quantiles -you have requested for evaluation as specified by the argument -"quantiles.for.estimation" The second vector which is called -"final.quantile.vector" details the values of V2BR that correspond to the -the key quantiles listed in vector 1. -} -\description{ -identify the global values of V2BR (i.e. the values across all -studies) that relate to a set of quantiles to be evaluated. -} -\details{ -Severside aggregate function called by ds.extractQuantiles via -ds.ranksSecure. This takes the "global.bounds.df" data frame saved on the -serverside following construction by extractQuantilesDS1. This -data frame includes the two quantile values that most closely span each -quartile value to be estimated. If either of the values had been the correct -value for a given quantile, both the bounding values would have taken that -value in global.bounds.df. This is because the upper bound was defined as -the lowest value that was equal to or greater than the true value for that -quantile while the lower bound was defined as the highest value that was -equal to or lower than the true value. Next, the function extractQuantileDS2 -goes round study by study to identify the values of V2BR that actually -correspond to each of the spanning values around each quantile. Then the -function goes quantile by quantile and estimates the mean of the -two values of V2BR that correspond to the the spanning quantiles. If these -two values are the same it means that that value of V2BR is the -"true" value and the mean of two (or potentially several) instances of that -value is inevitably also equal to that true value. If the upper and lower -bounding values of V2BR differ, neither can be the precisely correct single -value of V2BR for that quantile (see above for explanation) and so the mean -of the two is a reasonable interpolated summary. -} -\author{ -Paul Burton 11th November, 2021 -} diff --git a/man/messageDS.Rd b/man/messageDS.Rd deleted file mode 100644 index b438a2b9..00000000 --- a/man/messageDS.Rd +++ /dev/null @@ -1,40 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/messageDS.R -\name{messageDS} -\alias{messageDS} -\title{messageDS} -\usage{ -messageDS(message.object.name) -} -\arguments{ -\item{message.object.name}{is a character string, containing the name of the list containing the -message. See the header of the client-side function ds.message for more details.} -} -\value{ -a list object from each study, containing whatever message has been written by -DataSHIELD into $studysideMessage. -} -\description{ -This function allows for error messages arising from the -running of a server-side assign function to be returned to the client-side -} -\details{ -Errors arising from aggregate server-side functions can be returned -directly to the client-side. But this is not possible for server-side assign -functions because they are designed specifically to write objects to the -server-side and to return no meaningful information to the client-side. -Otherwise, users may be able to use assign functions to return disclosive -output to the client-side. ds.message calls messageDS which looks -specifically for an object called $serversideMessage in a designated list on -the server-side. Server-side functions from which error messages are to be made -available, are designed to be able to write the designated error message to -the $serversideMessage object into the list that is saved on the server-side -as the primary output of that function. So only valid server-side functions of -DataSHIELD can write a $studysideMessage, and as additional protection against -unexpected ways that someone may try to get round this limitation, a -$studysideMessage is a string that cannot exceed a length of nfilter.string -a default of 80 characters. -} -\author{ -Burton PR -} diff --git a/man/minMaxRandDS.Rd b/man/minMaxRandDS.Rd deleted file mode 100644 index 82355434..00000000 --- a/man/minMaxRandDS.Rd +++ /dev/null @@ -1,35 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/minMaxRandDS.R -\name{minMaxRandDS} -\alias{minMaxRandDS} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -minMaxRandDS(input.var.name) -} -\arguments{ -\item{input.var.name}{a character string specifying the name of V2BR. This -argument is set by the argument with the same name in the clientside function -ds.ranksSecure} -} -\value{ -the data frame objects containing the global ranks and quantiles. -For more details see the associated document entitled -"secure.global.ranking.docx" -} -\description{ -Creates a minimum value that is more negative, and less positive -than any real value in V2BR and a maximum value that is more positive and -less negative than any value of V2BR. -} -\details{ -Severside aggregate function called by ds.ranksSecure. The minimum -and maximum values it creates are used to replace missing values -(NAs) in V2BR if the argument e is set to "NA.low" or "NA.hi" -respectively. For more details about the cluster of functions that -collectively enable secure global ranking and estimation of global quantiles -see the associated document entitled "secure.global.ranking.docx". Also -see the header file for ds.ranksSecure -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/ranksSecureDS1.Rd b/man/ranksSecureDS1.Rd deleted file mode 100644 index e809cdec..00000000 --- a/man/ranksSecureDS1.Rd +++ /dev/null @@ -1,35 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ranksSecureDS1.R -\name{ranksSecureDS1} -\alias{ranksSecureDS1} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -ranksSecureDS1() -} -\value{ -the non-disclosive elements of blackbox.output.df (see details) -on the serverside as a data frame object (called blackbox.output) -on the clientside. After processing to create the global ranks across all -studies, this is returned to the serverside as the data frame sR4.df using -the clientside function ds.dmtC2S -} -\description{ -takes key non-disclosive components of the serverside data frame -blackbox.output.df over to the clientside to enable global ranking. -} -\details{ -Severside aggregate function called by ds.ranksSecure. The -non-disclosive components of blackbox.output.df that are transmitted to the -clientside are: (1) final values of the "combined real+pseudo data vector" -after all seven rounds of encryption have been completed; (2) a set of -sequential IDs allocated after sorting the "combined real+pseudo data vector" -by value (in ascending order). This allows later re-linkage of values back on -the serverside and confirmation that that linkage is correct. For more -details about the cluster of functions that collectively enable secure global -ranking and estimation of global quantiles see the associated document -entitled "secure.global.ranking.docx". Also see the header file -for ds.ranksSecure -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/ranksSecureDS2.Rd b/man/ranksSecureDS2.Rd deleted file mode 100644 index c742d493..00000000 --- a/man/ranksSecureDS2.Rd +++ /dev/null @@ -1,44 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ranksSecureDS2.R -\name{ranksSecureDS2} -\alias{ranksSecureDS2} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -ranksSecureDS2() -} -\value{ -creates a new data frame sR5.df on the serverside containing -solely the real data and including key elements needed for next stage of the -ranking process. Most crucially these include "global.rank" and "ID.by.val" -sorted in ascending order of the magnitude of V2BR -} -\description{ -Checks that the data frame produced in creating the initial -global ranks (ranks based on real and pseudo-data after the running of -blackBoxDS)has the correct dimensions and order as the serverside data frames -to which it will now be appended. If either the number of rows or the order -of the rows are inconsistent with the pre-existing data frames on the -serverside an error message is returned and the processing stops. Then -strips out the pseudo-data leaving solely the global ranks based just on -the real data -} -\details{ -Severside assign function called by ds.ranksSecure. -It works on the on the output created by serverside function ranksSecureDS1 -and saved on the serverside in data frame sR4.df by ds.dmtC2S. Having -checked QA it strips out all rows corresponding to pseudo-data. The resultant -data frame contains the following vectors: (1) the fully encrypted V2BR -(after application of blackBoxDS);(2) "ID.by.val" the sequential -ID associated with the "combined real+pseudo data vector" sorted by -value (ascending); (3) "studyid", a vector consisting solely of value n in -the nth study; (4) "global.rank" the vector containing global ranks created by -the clientside code in ds.ranksSecure after ranksSecureDS1 is called and up -to the point where ds.dmtC2S sends sR4.df to the serverside. For more -details about the cluster of functions that collectively enable secure global -ranking and estimation of global quantiles see the associated document -entitled "secure.global.ranking.docx". Also see the header file -for ds.ranksSecure -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/ranksSecureDS3.Rd b/man/ranksSecureDS3.Rd deleted file mode 100644 index 286f77ad..00000000 --- a/man/ranksSecureDS3.Rd +++ /dev/null @@ -1,46 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ranksSecureDS3.R -\name{ranksSecureDS3} -\alias{ranksSecureDS3} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -ranksSecureDS3() -} -\value{ -the non-disclosive elements of blackbox.output.df (see details) -on the serverside as a data frame object (called sR6.df) -on the clientside. After processing within ds.ranksSecure to create the -global ranks and global quantiles (of real data only) across all studies, -this is returned to the serverside as data frame "global.ranks.quantiles.df" -using the clientside function ds.dmtC2S. To illustrate the difference between -ranks and quantiles, if there are a total of 1000 original real observations -across all studies and one particular observation has the rank 250, it will -have quantile value 0.25 (i.e. 25%th value in the overall data ordered by -increasing value). Both ranks and quantiles can have ties. For more details -about the cluster of functions that collectively enable secure global ranking -and estimation of global quantiles see the associated document entitled -"secure.global.ranking.docx". Also see the header file for ds.ranksSecure -} -\description{ -takes key non-disclosive components of the serverside data frame -blackbox.ranks.df over to the clientside to enable global re-ranking of the -global ranks just applying to the real data (not the pseudo-data). -} -\details{ -Severside aggregate function called by ds.ranksSecure. The -non-disclosive components of blackbox.ranks.df that are transmitted to the -clientside are: (1) final values of the encrypted global ranks vector -after all seven rounds of encryption have been completed; (2) a set of -sequential IDs allocated to the global ranks vector in each study in their -current order based on increasing value of V2BR. This allows later re-linkage -of values back on the serverside and confirmation that that linkage is -correct. (3) a studyid vector with all values n in the nth study. This -facilitates data management on the serverside during the global ranking -of global ranks. For more details about the cluster of functions that -collectively enable secure global ranking and estimation of global quantiles -see the associated document entitled "secure.global.ranking.docx". Also see -the header file for ds.ranksSecure -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/ranksSecureDS4.Rd b/man/ranksSecureDS4.Rd deleted file mode 100644 index 7835282c..00000000 --- a/man/ranksSecureDS4.Rd +++ /dev/null @@ -1,55 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ranksSecureDS4.R -\name{ranksSecureDS4} -\alias{ranksSecureDS4} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -ranksSecureDS4(ranks.sort.by) -} -\arguments{ -\item{ranks.sort.by}{a character string taking two possible values. These -are "ID.orig" and "vals.orig". These define the order in which the -output.ranks.df and summary.output.ranks.df data frames are presented. This -argument is set by the argument with the same name in ds.ranksSecure. -Default value is "ID.orig".} -} -\value{ -Creates the data frame identified by the name given by the argument -() of the ds.ranksSecure function and writes it to the -serverside. If the argument is NULL or unspecified the -output data frame is called "main.ranks.df". The data frame is ordered -according to the argument in ds.ranksSecure. -} -\description{ -Creates a data frame "sR8.df" by cbinding the data frame -"blackBox.ranks.df" with the global ranks and global quantiles vectors in -"global.ranks.quantiles.df". Performs QA on this matrix and orders the -sR8.df data frame according to the argument in ds.ranksSecure -} -\details{ -Severside assign function called by ds.ranksSecure. -Creates a data frame "sR8.df" by cbinding the data frame "blackBox.ranks.df" -with the global ranks and global quantiles vectors in -"global.ranks.quantiles.df". Checks that all components of sR8.df have the -correct dimensions and are consistent in their ordering. If either the -number of rows or the order of the rows are inconsistent with those in -"blackBox.ranks.df" an error message is returned and the processing stops. -If sR8.df passes all QA tests it is written to the serverside as a data -frame with its name identified by the argument in -ds.ranksSecure. If that argument is NULL or unspecified the data frame -is called "main.ranks.df". The ranksSecureDS4 function also orders the -combined data frame () in one of two ways: if -the argument in ds.ranksSecure is set to "ID.orig" the -combined data frame is ordered in the same way as the original V2BR vector; -if the argument is set to vals.orig" the combined data frame -is ordered by the magnitude of the values of V2BR (ascending). Having -created the data frame () in this manner it can now be -directly cbinded to either the V2BR vector itself or to a data frame, tibble -or matrix containing V2BR (assuming they are also in the order corresponding -to the argument ) and this combined object can be used as the -basis of analysis based on the global ranks or quantiles including a range -of types of non-parametric analysis. -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/ranksSecureDS5.Rd b/man/ranksSecureDS5.Rd deleted file mode 100644 index 6851ff90..00000000 --- a/man/ranksSecureDS5.Rd +++ /dev/null @@ -1,55 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ranksSecureDS5.R -\name{ranksSecureDS5} -\alias{ranksSecureDS5} -\title{Secure ranking of "V2BR" (vector to be ranked) across all sources} -\usage{ -ranksSecureDS5(output.ranks.df) -} -\arguments{ -\item{output.ranks.df}{a character string which specifies an optional name -for the data.frame written to the serverside on each data source that -contains 11 of the key output variables from the ranking procedure pertaining -to that particular data source. This argument is set by the argument with -the same name in ds.ranksSecure.} -} -\value{ -extracts 5 key vectors from the larger data frame created by -ranksSecureDS4 to produce a summary data frame that is written to the -serverside. It is given a name specified by the argument. -} -\description{ -Summarises the serverside data frame written by ranksSecureDS4 -which is identified by the name given by the argument () of -the ds.ranksSecure function to produce a new output data frame containing -only 5 key variables. -} -\details{ -Serverside assign function called by clientside function -ds.ranksSecure. Takes the serverside data frame written by ranksSecureDS4 -which is identified by the name given by the argument () of -the ds.ranksSecure function. This holds 11 vectors including the final -global ranks across all studies and final global quantiles. The data frame -is ordered according to the argument in ds.ranksSecure. The -ranksSecureDS5 function then extracts 5 key vectors from the larger data -frame to produce a summary data frame that is given a name specified by -the argument () the ds.ranksSecure function. -This data frame includes the following components: (1) The values of a -sequential ID variable (ID.seq.real.orig) created to lie alongside the -original V2BR vector in the same order as that vector was itself ordered. -These ID values therefore reflect which row in the original data corresponds -to a given row in the output. If the argument in -ds.ranksSecure is set to "ID.orig" the values of the ID.seq.real.orig vector -in the output data frame simply run sequentially from 1 to N where N is the -number of individuals in the corresponding study. If is -set to "vals.orig" the values of the ID.seq.real.orig vector will be -determined by the magnitude of the corresponding V2BR value and will -appear to be ordered in a haphazard manner; (2) the original values of V2BR; -(3) the global ranks corresponding to the original values in V2BR, with ties -reflected appropriately; (4) the global quantiles corresponding to the -original values in V2BR, with ties reflected appropriately; (5) a studyid -vector in which all elements take the value n in the nth study. -} -\author{ -Paul Burton 9th November, 2021 -} diff --git a/man/recodeLevelsDS.Rd b/man/recodeLevelsDS.Rd deleted file mode 100644 index 9067227a..00000000 --- a/man/recodeLevelsDS.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/recodeLevelsDS.R -\name{recodeLevelsDS} -\alias{recodeLevelsDS} -\title{Recodes the levels of a categorical variables} -\usage{ -recodeLevelsDS(x = NULL, classes = NULL) -} -\arguments{ -\item{x}{a factor vector} - -\item{classes}{a character vector the levels of the newt factor vector} -} -\value{ -a factor vector with the new levels -} -\description{ -The functions uses the input factor and generates a new factor -with new levels. -} -\author{ -Gaye, A. -} diff --git a/man/subsetByClassDS.Rd b/man/subsetByClassDS.Rd deleted file mode 100644 index c56e6537..00000000 --- a/man/subsetByClassDS.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/subsetByClassDS.R -\name{subsetByClassDS} -\alias{subsetByClassDS} -\title{Breaks down a dataframe or a factor into its sub-classes} -\usage{ -subsetByClassDS(data = NULL, variables = NULL) -} -\arguments{ -\item{data}{a string character, the name of the dataframe or the factor vector} - -\item{variables}{a vector of string characters, the names of the the variables to subset on.} -} -\value{ -a list which contains the subsetted datasets -} -\description{ -The function takes a categorical vector or dataframe as input and generates subset(s) -vectors or dataframes for each category. Subsets are considered invalid if they hold between 1 and -4 observations. -} -\details{ -If the input data object is a dataframe it is possible to specify the variables -to subset on. If a subset is not 'valid' all its the values are reported as missing (i.e. NA), -the name of the subsets is labelled as '_INVALID'. If no variables are specified to subset on, -the dataframe will be subset on each of its factor variables. -And if none of the columns holds a factor variable a message is issued as output. A message is also -issued as output if the input vector is not of type factor. -} -\author{ -Gaye, A. -} diff --git a/man/subsetDS.Rd b/man/subsetDS.Rd deleted file mode 100644 index 188d140f..00000000 --- a/man/subsetDS.Rd +++ /dev/null @@ -1,57 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/subsetDS.R -\name{subsetDS} -\alias{subsetDS} -\title{Generates a valid subset of a table or a vector} -\usage{ -subsetDS( - dt = NULL, - complt = NULL, - rs = NULL, - cs = NULL, - lg = NULL, - th = NULL, - varname = NULL -) -} -\arguments{ -\item{dt}{a string character, the name of the dataframe or the factor vector and the range of the subset.} - -\item{complt}{a boolean that tells if the subset to subset should include only complete cases} - -\item{rs}{a vector of two integers that give the range of rows de extract.} - -\item{cs}{a vector of two integers or one or more characters; the indices of the columns to extract or the names of the columns (i.e. -names of the variables to extract).} - -\item{lg}{a character, the logical parameter to use if the user wishes to subset a vector using a logical -operator. This parameter is ignored if the input data is not a vector.} - -\item{th}{a numeric, the threshold to use in conjunction with the logical parameter. This parameter is ignored -if the input data is not a vector.} - -\item{varname}{a character, if the input data is a table, if this parameter is provided along with the 'logical' and 'threshold' -parameters, a subtable is based the threshold applied to the specified variable. This parameter is however ignored if the parameter -'rows' and/or 'cols' are provided.} -} -\value{ -a subset of the vector, matrix or dataframe as specified is stored on the server side -} -\description{ -The function uses the R classical subsetting with squared brackets '[]' and allows also to -subset using a logical operator and a threshold. The object to subset from must be a vector (factor, numeric -or character) or a table (data.frame or matrix). -} -\details{ -If the input data is a table: The user specifies the rows and/or columns to include in the subset if the input -object is a table; the columns can be referred to by their names. The name of a vector (i.e. a variable) can also be provided -with a logical operator and a threshold (see example 3). -If the input data is a vector: when the parameters 'rows', 'logical' and 'threshold' are all provided the last two are ignored ( -'rows' has precedence over the other two parameters then). -If the requested subset is not valid (i.e. contains less than the allowed -number of observations), the subset is not generated, rather a table or a vector of missing values is generated to allow -for any subsequent process using the output of the function to proceed after informing the user via a message. -} -\author{ -Gaye, A. -} diff --git a/man/table2DDS.Rd b/man/table2DDS.Rd deleted file mode 100644 index 2e760e28..00000000 --- a/man/table2DDS.Rd +++ /dev/null @@ -1,31 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/table2DDS.R -\name{table2DDS} -\alias{table2DDS} -\title{table2DDS (aggregate function) called by ds.table2D} -\usage{ -table2DDS(xvect, yvect) -} -\arguments{ -\item{xvect}{a numerical vector with discrete values - usually a factor.} - -\item{yvect}{a numerical vector with discrete values - usually a factor.} -} -\value{ -a list which contains two elements: 'table', the 2-dimensional table and 'message' a message which -informs about the validity of the table. -} -\description{ -This function generates a 2-dimensional contingency table where potentially disclosive cells -(based on a set threshold) are replaced by a missing value ('NA'). -} -\details{ -It generates 2-dimensional contingency tables where valid (non-disclosive) tables are defined -as those where none of their cells have counts between 1 and the set threshold "nfilter.tab". When the output table -is invalid all cells except the total counts are replaced by missing values. Only the total counts are visible -on the table returned to the client side. A message is also returned with the 2-dimensional table; the message -says "invalid table - invalid counts present" if the table is invalid and 'valid table' otherwise. -} -\author{ -Amadou Gaye, Paul Burton, Demetris Avraam for DataSHIELD Development Team -} diff --git a/man/testObjExistsDS.Rd b/man/testObjExistsDS.Rd deleted file mode 100644 index 3c49f15c..00000000 --- a/man/testObjExistsDS.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/testObjExistsDS.R -\name{testObjExistsDS} -\alias{testObjExistsDS} -\title{testObjExistsDS} -\usage{ -testObjExistsDS(test.obj.name = NULL) -} -\arguments{ -\item{test.obj.name}{a client-side provided character string specifying the variable -whose presence is to be tested in each data source} -} -\value{ -List with `test.obj.exists` and `test.obj.class` -} -\description{ -The server-side function called by ds.testObjExists -} -\details{ -Tests whether a given object exists in -all sources. It is called at the end of all -recently written assign functions to check the new (assigned) object has been -created in all sources -} -\author{ -Burton PR -} diff --git a/tests/testthat/test-arg-dataFrameFillDS.R b/tests/testthat/test-arg-dataFrameFillDS.R deleted file mode 100644 index 19c710aa..00000000 --- a/tests/testthat/test-arg-dataFrameFillDS.R +++ /dev/null @@ -1,55 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("dataFrameFillDS::arg::setup") - -# -# Tests -# - -# context("dataFrameFillDS::arg") -test_that("simple dataFrameFillDS, ascending, numeric", { - df <- data.frame(v1 = c(-2.0, -3.0, 4.0, 2.0, 1.0, 0.0, -1.0, 3.0), v2 = c(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)) - allNames.transmit <- "v1,v2,v3,v4,v5,v6,v7" - class.vect.transmit <- "numeric,numeric,numeric,foo,bar,factor,logical" - levels.vec.transmit <- NULL - - expect_error(res <- dataFrameFillDS("df", allNames.transmit, class.vect.transmit, levels.vec.transmit), "Unexpected missing class specified: 'foo'", fixed = TRUE) - - expect_true(! exists("res")) -}) - -test_that("simple dataFrameFillDS, ascending, numeric", { - df <- data.frame(v1 = c(-2.0, -3.0, 4.0, 2.0, 1.0, 0.0, -1.0, 3.0), v2 = c(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)) - allNames.transmit <- "v1,v2,v3,v4,v5,v6,v7" - class.vect.transmit <- "numeric,numeric,numeric,foo,bar,factor,logical" - levels.vec.transmit <- NULL - - expect_error(res <- dataFrameFillDS("df", allNames.transmit, class.vect.transmit, levels.vec.transmit), "Unexpected missing class specified: 'foo'", fixed = TRUE) - - expect_true(! exists("res")) -}) - -# -# Shutdown -# - -# context("dataFrameFillDS::arg::shutdown") - -# -# Done -# - -# context("dataFrameFillDS::arg::done") diff --git a/tests/testthat/test-smk-corDS.R b/tests/testthat/test-smk-corDS.R index ba51e096..059be9ad 100644 --- a/tests/testthat/test-smk-corDS.R +++ b/tests/testthat/test-smk-corDS.R @@ -764,6 +764,16 @@ test_that("corDS gives the same result for a matrix as for a data.frame", { expect_equal(res.matrix[names(res.matrix) != "class"], res.df[names(res.df) != "class"]) }) +test_that("corDS accepts a factor x, correlating on its level codes", { + fvar <- factor(c("m", "f", "m", "f", "m", "f", "m", "f", "m", "f")) + yvar <- c(1.0, 5.0, 2.0, 6.0, 3.0, 7.0, 2.0, 8.0, 1.0, 9.0) + + res <- corDS("fvar", "yvar") + + expect_equal(res$class, "factor") + expect_equal(res$sums[1, 2], sum(as.integer(fvar))) +}) + # # Done # diff --git a/tests/testthat/test-smk-covDS.R b/tests/testthat/test-smk-covDS.R index d44f98bb..9bb4e517 100644 --- a/tests/testthat/test-smk-covDS.R +++ b/tests/testthat/test-smk-covDS.R @@ -278,6 +278,16 @@ test_that("covDS gives the same result for a matrix as for a data.frame", { expect_equal(res.matrix[names(res.matrix) != "class"], res.df[names(res.df) != "class"]) }) +test_that("covDS accepts a factor x, using its level codes", { + fvar <- factor(c("m", "f", "m", "f", "m", "f", "m", "f", "m", "f")) + yvar <- c(1.0, 5.0, 2.0, 6.0, 3.0, 7.0, 2.0, 8.0, 1.0, 9.0) + + res <- covDS("fvar", "yvar", "pairwise.complete") + + expect_equal(res$class, "factor") + expect_equal(res$sums[1, 2], sum(as.integer(fvar))) +}) + # # Done # diff --git a/tests/testthat/test-smk-dataFrameFillDS.R b/tests/testthat/test-smk-dataFrameFillDS.R deleted file mode 100644 index 326c6c85..00000000 --- a/tests/testthat/test-smk-dataFrameFillDS.R +++ /dev/null @@ -1,110 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("dataFrameFillDS::smk::setup") - -# -# Tests -# - -# context("dataFrameFillDS::smk") -test_that("simple dataFrameFillDS, ascending, numeric", { - df <- data.frame(v1 = c(-2.0, -3.0, 4.0, 2.0, 1.0, 0.0, -1.0, 3.0), v2 = c(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)) - allNames.transmit <- "v1,v2,v3,v4,v5,v6,v7" - class.vect.transmit <- "numeric,numeric,numeric,integer,character,factor,logical" - levels.vec.transmit <- "1,2,3" - - res <- dataFrameFillDS("df", allNames.transmit, class.vect.transmit, levels.vec.transmit) - - expect_equal(class(res), "data.frame") - expect_length(res, 7) - - res.colnames <- colnames(res) - expect_length(res.colnames, 7) - expect_equal(res.colnames[1], 'v1') - expect_equal(res.colnames[2], 'v2') - expect_equal(res.colnames[3], 'v3') - expect_equal(res.colnames[4], 'v4') - expect_equal(res.colnames[5], 'v5') - expect_equal(res.colnames[6], 'v6') - expect_equal(res.colnames[7], 'v7') - - expect_length(res$v1, 8) - expect_length(res$v2, 8) - expect_length(res$v3, 8) - expect_length(res$v4, 8) - expect_length(res$v5, 8) - expect_length(res$v6, 8) - expect_length(res$v7, 8) - - expect_equal(class(res$v1), "numeric") - expect_equal(class(res$v2), "numeric") - expect_equal(class(res$v3), "numeric") - expect_equal(class(res$v4), "integer") - expect_equal(class(res$v5), "character") - expect_equal(class(res$v6), "factor") - expect_equal(class(res$v7), "logical") - - expect_equal(res$v1[1], -2.0) - expect_equal(res$v2[1], 0.0) - expect_equal(res$v1[2], -3.0) - expect_equal(res$v2[2], 1.0) - expect_equal(res$v1[3], 4.0) - expect_equal(res$v2[3], 2.0) - expect_equal(res$v1[4], 2.0) - expect_equal(res$v2[4], 3.0) - expect_equal(res$v1[5], 1.0) - expect_equal(res$v2[5], 4.0) - expect_equal(res$v1[6], 0.0) - expect_equal(res$v2[6], 5.0) - expect_equal(res$v1[7], -1.0) - expect_equal(res$v2[7], 6.0) - expect_equal(res$v1[8], 3.0) - expect_equal(res$v2[8], 7.0) - - for (index in 1:8) - { - expect_true(is.na(res$v3[index]), info = paste0('index=', index, ', column=v3')) - expect_true(is.na(res$v4[index]), info = paste0('index=', index, ', column=v4')) - expect_true(is.na(res$v5[index]), info = paste0('index=', index, ', column=v5')) - expect_true(is.na(res$v6[index]), info = paste0('index=', index, ', column=v6')) - expect_true(is.na(res$v7[index]), info = paste0('index=', index, ', column=v7')) - } - - res.v6.levels <- levels(res$v6) - - expect_equal(res.v6.levels[1], "1") - expect_equal(res.v6.levels[2], "2") - expect_equal(res.v6.levels[3], "3") -}) - -test_that("dataFrameFillDS errors when object does not exist", { - expect_error( - dataFrameFillDS("nonexistent_object", "a,b", "numeric,numeric", NULL), - regexp = "does not exist" - ) -}) - -# -# Shutdown -# - -# context("dataFrameFillDS::smk::shutdown") - -# -# Done -# - -# context("dataFrameFillDS::smk::done") diff --git a/tests/testthat/test-smk-glmerSLMADS.assign.R b/tests/testthat/test-smk-glmerSLMADS.assign.R index 9277ffad..e675bb9d 100644 --- a/tests/testthat/test-smk-glmerSLMADS.assign.R +++ b/tests/testthat/test-smk-glmerSLMADS.assign.R @@ -29,10 +29,10 @@ test_that("simple glmerSLMADS.assign, binomial random intercept", { expect_true(methods::is(res, "glmerMod")) expect_equal(nobs(res), 50) - expect_equal(as.numeric(lme4::fixef(res)), c(-1.4299523, 0.2248647), tolerance = 1e-5) + expect_equal(as.numeric(lme4::fixef(res)), c(-1.4340652, 0.2255225), tolerance = 1e-5) vc <- as.data.frame(lme4::VarCorr(res)) - expect_equal(vc$vcov, 2.7451347, tolerance = 1e-5) + expect_equal(vc$vcov, 2.7493590, tolerance = 1e-5) }) test_that("glmerSLMADS.assign throws error when dataName does not exist", { diff --git a/tests/testthat/test-smk-glmerSLMADS2.R b/tests/testthat/test-smk-glmerSLMADS2.R index 94821cea..adb47e47 100644 --- a/tests/testthat/test-smk-glmerSLMADS2.R +++ b/tests/testthat/test-smk-glmerSLMADS2.R @@ -35,7 +35,7 @@ test_that("simple glmerSLMADS2, binomial random intercept", { expect_equal(res$Nmissing, 0) expect_equal(dim(res$coefficients), c(2, 4)) expect_equal(res$coefficients[, "Estimate"], - c(`(Intercept)` = -1.4299523, x = 0.2248647), tolerance = 1e-5) + c(`(Intercept)` = -1.4340652, x = 0.2255225), tolerance = 1e-5) expect_equal(res$family, "binomial") }) diff --git a/tests/testthat/test-smk-lsDS.R b/tests/testthat/test-smk-lsDS.R index b96eb0ec..4427f195 100644 --- a/tests/testthat/test-smk-lsDS.R +++ b/tests/testthat/test-smk-lsDS.R @@ -28,7 +28,7 @@ test_that("simple lsDS", { search.filter <- NULL env.to.search <- 1L - res <- lsDS(search.filter, env.to.search) + res <- eval(call("lsDS", search.filter, env.to.search), envir = .GlobalEnv) expect_equal(class(res), "list") expect_length(res, 2) @@ -44,7 +44,7 @@ test_that("simple lsDS", { search.filter <- "_:A:_" env.to.search <- 1L - res <- lsDS(search.filter, env.to.search) + res <- eval(call("lsDS", search.filter, env.to.search), envir = .GlobalEnv) expect_equal(class(res), "list") expect_length(res, 3) @@ -55,6 +55,15 @@ test_that("simple lsDS", { expect_equal(res$search.filter.final, "*") }) +# context("lsDS::smk::calling environment") +test_that("lsDS lists the environment it is called from", { + local.obj <- "value" + + res <- lsDS(NULL, 1L) + + expect_true("local.obj" %in% res$objects.found) +}) + # # Done # diff --git a/tests/testthat/test-smk-messageDS.R b/tests/testthat/test-smk-messageDS.R deleted file mode 100644 index 91ec685b..00000000 --- a/tests/testthat/test-smk-messageDS.R +++ /dev/null @@ -1,92 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("messageDS::smk::setup") - -set.standard.disclosure.settings() - -# -# Tests -# - -# context("messageDS::smk") -test_that("simple messageDS", { - expect_warning(base::rm("object"), "object 'object' not found", fixed = TRUE) - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "Error: the object does not exist in this datasource") -}) - -test_that("simple messageDS", { - object <- NULL - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "ALL OK: there are no studysideMessage(s) on this datasource") -}) - -test_that("simple messageDS", { - object <- list() - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "Outcome object is a list without names. So a studysideMessage may be hidden. Please check output is OK") -}) - - -test_that("simple messageDS", { - object <- list("a", "b", "c", "d") - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "Outcome object is a list without names. So a studysideMessage may be hidden. Please check output is OK") -}) - -test_that("simple messageDS", { - object <- list(v1 = "a", v2 = "b", v3 = "c", v4 = "d") - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "ALL OK: there are no studysideMessage(s) on this datasource") -}) - -test_that("simple messageDS", { - object <- list(v1 = "a", v2 = "b", studysideMessage = "message", v3 = "c", v4 = "d") - - res <- messageDS("object") - - expect_equal(class(res), "character") - expect_length(res, 1) - expect_equal(res, "NOT ALL OK: there are studysideMessage(s) on this datasource") -}) - -# -# Done -# - -# context("messageDS::smk::shutdown") - -# context("messageDS::smk::done") diff --git a/tests/testthat/test-smk-minMaxRandDS.R b/tests/testthat/test-smk-minMaxRandDS.R deleted file mode 100644 index 0e057e5a..00000000 --- a/tests/testthat/test-smk-minMaxRandDS.R +++ /dev/null @@ -1,38 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("minMaxRandDS::smk::setup") - -# -# Tests -# - -test_that("minMaxRandDS", { - input <- read.csv(file = 'data_files/DASIM/DASIM1.csv') - - res <- minMaxRandDS(input) - - expect_equal(class(res), "numeric") - expect_length(res, 2) - expect_true("numeric" %in% class(res[1])) - expect_true("numeric" %in% class(res[2])) -}) - -# -# Done -# - -# context("minMaxRandDS::smk::shutdown") - -# context("minMaxRandDS::smk::done") diff --git a/tests/testthat/test-smk-recodeLevelsDS.R b/tests/testthat/test-smk-recodeLevelsDS.R deleted file mode 100644 index 9e365836..00000000 --- a/tests/testthat/test-smk-recodeLevelsDS.R +++ /dev/null @@ -1,47 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("recodeLevelsDS::smk::setup") - -# -# Tests -# - -test_that("simple recodeLevelsDS", { - input <- c(1, 2, 3, 4, 1, 3) - classes <- c("one", "two", "three", "four") - - res <- recodeLevelsDS(input, classes) - - expect_equal(class(res), "numeric") - expect_length(res, 6) - - res.levels <- levels(res) - - expect_equal(class(res.levels), "character") - expect_length(res.levels, 4) - expect_equal(res.levels[1], "one") - expect_equal(res.levels[2], "two") - expect_equal(res.levels[3], "three") - expect_equal(res.levels[4], "four") -}) - -# -# Done -# - -# context("recodeLevelsDS::smk::shutdown") - -# context("recodeLevelsDS::smk::done") diff --git a/tests/testthat/test-smk-subsetByClassDS.R b/tests/testthat/test-smk-subsetByClassDS.R deleted file mode 100644 index 82ccab5d..00000000 --- a/tests/testthat/test-smk-subsetByClassDS.R +++ /dev/null @@ -1,88 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("subsetByClassDS::smk::setup") - -set.standard.disclosure.settings() - -# -# Tests -# - -# context("subsetByClassDS::smk") -test_that("simple subsetByClassDS, data.frame, unspecified variables", { - data <- data.frame(v1 = factor(c(0, 0, 0, 1, 1, 1, 2, 1, 2, 2)), v2 = c(4.0, 0.0, 3.0, 1.0, 2.0, 2.0, 1.0, 3.0, 0.0, 4.0), v3 = c(1:10), v4 = c(1:10)) - variables <- NULL - - res <- subsetByClassDS("data", variables) - - expect_equal(class(res), "list") - expect_length(res, 3) - - expect_equal(class(res$v1.level_0), "data.frame") - expect_length(res$v1.level_0, 4) - - expect_equal(class(res$v1.level_1), "data.frame") - expect_length(res$v1.level_1, 4) - - expect_equal(class(res$v1.level_2), "data.frame") - expect_length(res$v1.level_2, 4) -}) - -test_that("simple subsetByClassDS, data.frame, specified variables", { - data <- data.frame(v1 = factor(c(0, 0, 0, 1, 1, 1, 2, 1, 2, 2)), v2 = c(4.0, 0.0, 3.0, 1.0, 2.0, 2.0, 1.0, 3.0, 0.0, 4.0), v3 = c(1:10), v4 = c(1:10)) - variables <- c("v1") - - res <- subsetByClassDS("data", variables) - - expect_equal(class(res), "list") - expect_length(res, 3) - - expect_equal(class(res$v1.level_0), "data.frame") - expect_length(res$v1.level_0, 4) - - expect_equal(class(res$v1.level_1), "data.frame") - expect_length(res$v1.level_1, 4) - - expect_equal(class(res$v1.level_2), "data.frame") - expect_length(res$v1.level_2, 4) -}) - -test_that("simple subsetByClassDS, factor vector, specified variables", { - data <- factor(c(0, 0, 0, 1, 1, 1, 2, 1, 2, 2)) - variables <- NULL - - res <- subsetByClassDS("data", variables) - - expect_equal(class(res), "list") - expect_length(res, 3) - - expect_equal(class(res$data.level_0), "factor") - expect_length(res$data.level_0, 3) - - expect_equal(class(res$data.level_1), "factor") - expect_length(res$data.level_1, 4) - - expect_equal(class(res$data.level_2), "factor") - expect_length(res$data.level_2, 3) -}) - -# -# Done -# - -# context("subsetByClassDS::smk::shutdown") - -# context("subsetByClassDS::smk::done") diff --git a/tests/testthat/test-smk-subsetDS.R b/tests/testthat/test-smk-subsetDS.R deleted file mode 100644 index 53d291c4..00000000 --- a/tests/testthat/test-smk-subsetDS.R +++ /dev/null @@ -1,126 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("subsetDS::smk::setup") - -set.standard.disclosure.settings() - -# -# Tests -# - -# context("subsetDS::smk") -test_that("simple subsetDS, no NAs", { - data <- data.frame(v1 = c(0, 0, 1, 1, 2, 2, 3, 3, 4, 4), v2 = c(4.0, 0.0, 3.0, 1.0, 2.0, 2.0, 1.0, 3.0, 0.0, 4.0)) - complt <- FALSE - rs <- NULL - cs <- NULL - lg <- 2 - th <- 2 - varname <- "v1" - - res <- subsetDS("data", complt, rs, cs, lg, th, varname) - - expect_equal(class(res), "data.frame") - expect_length(res, 2) - - expect_equal(class(res$v1), "numeric") - expect_length(res$v1, 6) - expect_equal(res$v1[1], 2) - expect_equal(res$v1[2], 2) - expect_equal(res$v1[3], 3) - expect_equal(res$v1[4], 3) - expect_equal(res$v1[5], 4) - expect_equal(res$v1[6], 4) - - expect_equal(class(res$v2), "numeric") - expect_length(res$v2, 6) - expect_equal(res$v2[1], 2.0) - expect_equal(res$v2[2], 2.0) - expect_equal(res$v2[3], 1.0) - expect_equal(res$v2[4], 3.0) - expect_equal(res$v2[5], 0.0) - expect_equal(res$v2[6], 4.0) -}) - -test_that("simple subsetDS, NAs, complete.case FALSE", { - data <- data.frame(v1 = c(0, 0, 1, 1, 2, 2, 3, 3, 4, 4), v2 = c(4.0, 0.0, 3.0, 1.0, 2.0, 2.0, 1.0, NA, NA, 4.0)) - complt <- FALSE - rs <- NULL - cs <- NULL - lg <- 2 - th <- 2 - varname <- "v1" - - res <- subsetDS("data", complt, rs, cs, lg, th, varname) - - expect_equal(class(res), "data.frame") - expect_length(res, 2) - - expect_equal(class(res$v1), "numeric") - expect_length(res$v1, 6) - expect_equal(res$v1[1], 2) - expect_equal(res$v1[2], 2) - expect_equal(res$v1[3], 3) - expect_equal(res$v1[4], 3) - expect_equal(res$v1[5], 4) - expect_equal(res$v1[6], 4) - - expect_equal(class(res$v2), "numeric") - expect_length(res$v2, 6) - expect_equal(res$v2[1], 2.0) - expect_equal(res$v2[2], 2.0) - expect_equal(res$v2[3], 1.0) - expect_true(is.na(res$v2[4])) - expect_true(is.na(res$v2[5])) - expect_equal(res$v2[6], 4.0) -}) - -test_that("simple subsetDS, NAs, complete.case TRUE", { - data <- data.frame(v1 = c(0, 0, 1, 1, 2, 2, 3, 3, 4, 4), v2 = c(4.0, 0.0, 3.0, 1.0, 2.0, 2.0, 1.0, NA, NA, 4.0)) - complt <- TRUE - rs <- NULL - cs <- NULL - lg <- 2 - th <- 2 - varname <- "v1" - - res <- subsetDS("data", complt, rs, cs, lg, th, varname) - - expect_equal(class(res), "data.frame") - expect_length(res, 2) - - expect_equal(class(res$v1), "numeric") - expect_length(res$v1, 4) - expect_equal(res$v1[1], 2) - expect_equal(res$v1[2], 2) - expect_equal(res$v1[3], 3) - expect_equal(res$v1[4], 4) - - expect_equal(class(res$v2), "numeric") - expect_length(res$v2, 4) - expect_equal(res$v2[1], 2.0) - expect_equal(res$v2[2], 2.0) - expect_equal(res$v2[3], 1.0) - expect_equal(res$v2[4], 4.0) -}) - -# -# Done -# - -# context("subsetDS::smk::shutdown") - -# context("subsetDS::smk::done") diff --git a/tests/testthat/test-smk-testObjExistsDS.R b/tests/testthat/test-smk-testObjExistsDS.R deleted file mode 100644 index 705948d0..00000000 --- a/tests/testthat/test-smk-testObjExistsDS.R +++ /dev/null @@ -1,270 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved. -# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved. -# -# This program and the accompanying materials -# are made available under the terms of the GNU Public License v3.0. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- - -# -# Set up -# - -# context("testObjExistsDS::smk::setup") - -# -# Tests -# - -# context("testObjExistsDS::smk::character") -test_that("simple testObjExistsDS, character", { - input <- "value" - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "character") -}) - -test_that("simple testObjExistsDS, character vector", { - input <- c("value1", "value2", "value3", "value4") - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "character") -}) - -# context("testObjExistsDS::smk::integer") -test_that("simple testObjExistsDS, integer", { - input <- 1L - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "integer") -}) - -test_that("simple testObjExistsDS, integer vector", { - input <- c(1L, 2L, 3L, 4L) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "integer") -}) - -# context("testObjExistsDS::smk::numeric") -test_that("simple testObjExistsDS, numeric", { - input <- 1.1 - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "numeric") -}) - -test_that("simple testObjExistsDS, numeric vector", { - input <- c(1.1, 2.1, 3.1, 4.1) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "numeric") -}) - -# context("testObjExistsDS::smk::logical") -test_that("simple testObjExistsDS, logical, FALSE", { - input <- FALSE - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "logical") -}) - -test_that("simple testObjExistsDS, logical, TRUE", { - input <- TRUE - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "logical") -}) - -test_that("simple testObjExistsDS, logical vector", { - input <- c(FALSE, TRUE, FALSE, TRUE) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "logical") -}) - -# context("testObjExistsDS::smk::data.frame") -test_that("simple testObjExistsDS, data.frame", { - input <- data.frame(v1 = c(0.0, 1.0, 2.0, 3.0, 4.0), v2 = c(4.0, 3.0, 2.0, 1.0, 0.0)) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "data.frame") -}) - -# context("testObjExistsDS::smk::array") -test_that("simple testObjExistsDS, array", { - input <- array(c(0.0, 1.0, 2.0, 3.0, 4.0)) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "array") -}) - -# context("testObjExistsDS::smk::matrix") -test_that("simple testObjExistsDS, matrix", { - input <- matrix(c(0.0, 1.0, 2.0, 3.0, 4.0)) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - if (base::getRversion() < '4.0.0') - { - expect_length(res$test.obj.class, 1) - expect_true("matrix" %in% res$test.obj.class) - } - else - { - expect_length(res$test.obj.class, 2) - expect_true("matrix" %in% res$test.obj.class) - expect_true("array" %in% res$test.obj.class) - } -}) - -# context("testObjExistsDS::smk::data.matrix") -test_that("simple testObjExistsDS, data.matrix", { - input <- data.matrix(data.frame(v1 = c(0.0, 1.0, 2.0, 3.0, 4.0), v2 = c(4.0, 3.0, 2.0, 1.0, 0.0))) - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - - if (base::getRversion() < '4.0.0') - { - expect_length(res$test.obj.class, 1) - expect_true("matrix" %in% res$test.obj.class) - } - else - { - expect_length(res$test.obj.class, 2) - expect_true("matrix" %in% res$test.obj.class) - expect_true("array" %in% res$test.obj.class) - } -}) - -# context("testObjExistsDS::smk::date") -test_that("simple testObjExistsDS, date", { - input <- Sys.Date() - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "Date") -}) - -# context("testObjExistsDS::smk::formula") -test_that("simple testObjExistsDS, formula", { - input <- X ~ A + B - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "formula") -}) - -# context("testObjExistsDS::smk::environment") -test_that("simple testObjExistsDS, environment", { - input <- environment() - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "environment") -}) - -# context("testObjExistsDS::smk::NA") -test_that("special testObjExistsDS, NA", { - input <- NA - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "logical") -}) - -# context("testObjExistsDS::smk::NULL") -test_that("special testObjExistsDS, NULL", { - input <- NULL - - res <- testObjExistsDS("input") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, TRUE) - expect_equal(res$test.obj.class, "NULL") -}) - -# context("testObjExistsDS::smk::not exists") -test_that("special testObjExistsDS, not exists", { - res <- testObjExistsDS("XXXinputXXX") - - expect_equal(class(res), "list") - expect_length(res, 2) - expect_equal(res$test.obj.exists, FALSE) - expect_equal(res$test.obj.class, NULL) -}) - -# -# Done -# - -# context("testObjExistsDS::smk::shutdown") - -# context("testObjExistsDS::smk::done")