ds.rNorm<-function(samp.size=1,mean=0,sd=1, newobj="newObject", datasources=NULL){ toAssign<-paste0("rNormDS(",samp.size,",",mean, ",", sd, ")") # if no opal login details are provided look for 'opal' objects in the environment if(is.null(datasources)){ datasources <- findLoginObjects() } if(is.null(toAssign)){ stop("Please give the name of object to assign or an expression to evaluate and assign.!\n", call.=FALSE) } # now do the business # Because this is DataSHIELD, the simulated values in two different # studies could be the same because when no seed is set, "one is created # from the current time and the process ID". As the time in each # server may be very similar, you rely on process ID to make different # servers different. Certainly working on local VMs this often leads # to the same set of random numbers being generated. So, the ds.rNorm # function generates n=samp.size random vectors for n=samp.size studies # and the second call to ds.assign (below) picks the kth vector for the # for the kth study. #Randomly simulate n=samp.size vectors for(j in 1:length(datasources)) { newobj.s<-paste0(newobj,j) datashield.assign(datasources, newobj.s, as.symbol(toAssign)) } #Select the values in the kth random vector for the kth study for(k in 1:length(datasources)) { newobj.s<-paste0(newobj,k) datashield.assign(datasources[k], newobj, as.symbol(newobj.s)) } # check that the new object has been created and display a message accordingly finalcheck <- isAssigned(datasources, newobj) }