How to create a new function

  • Pull dsBase package from github to your machine - this is all the server side datashield functions for base package
  • Pull the dsBaseClient from github to your machine - this contains all the client functions
  • Write R script for server function named in the conventional way xxxDS.R
  • Write an R script for the client function named in the conventional way ds.xxxxx.R
  • Place the server function script into the correct folder pulled from github e.g. dsBase/R/ on your own machine
  • Place the client function script into the correct folder pulled from github e.g. dsBaseClient/R/ on your own machine
  • Put the header at the top of the client R script (ds.xxxx.R script)

    Example Header block
    #' 
    #' @title [insert something] 
    #' @description [insert something]
    #' @export 
    #'
    Example 2
    #' 
    #' @title creates random numbers 
    #' @description This function is similar to R function \code{rnorm}.
    #' @export
    #'
  • On each Opal server log into the web interface and click on Administration > DataSHIELD and select either ASSIGN or AGGREGATE (depends on your function and what it does!)
    Click +Method
    Add a name of server side function "xxxxx.DS"
    Select R script
    Paste the server function code from your xxxxx.DS.R script into the empty box
    Click save 
  • Reload the new client library from your local machine. In R:

    library(devtools)
    devtools::load_all("filepath to dsBaseClient you have pulled from github on your machine")
  • Test the new function:

    #load libraries
    library(opal)
    library(dsBaseClient)
    library(dsStatsClient)
    library(dsGraphicsClient)
    library(dsModellingClient)
     
    #log into to the test opals
    data(logindata)
    opals <- datashield.login(logins=logindata,assign=TRUE)
     
    #run the function to test it
    ds.rNorm1(samp.size=25,mean=0,sd=1,newobj="newObject",datasources=NULL)
     

 

DataSHIELD Wiki by DataSHIELD is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Based on a work at http://www.datashield.ac.uk/wiki