Information submitted through the support site is private but is not hosted within your secure CDD Vault. Please do not include sensitive intellectual property in your support requests.

R Scripting Language

 

If you require the use of the scripting language R for your API programming, you will require the following three packages:

  • jsonlite
  • RCurl
  • httr


A simple example of an API call with R would look like this:

install.packages("jsonlite")
install.packages("RCurl")
install.packages("httr")
library(RCurl)
library(jsonlite)
library(httr)
data<-getURI("https://app.collaborativedrug.com/api/v1/vaults", httpheader = paste("X-CDD-Token:", TOKEN), .mapUnicode=FALSE)
fromJSON(data) 

Including .mapUnicode=FALSE is essential if any new lines are returned by the API (ex. molfiles) or you will receive an error.

 

Another example using R, a POST request, can be written like this:

install.packages("httr")
library(httr)
response<-POST("https://app.collaborativedrug.com/api/v1/vaults/1234/molecules", body='{"name": "empty", "projects": [938429932]}', add_headers(.headers = c("X-CDD-Token"=TOKEN)))
stop_for_status(response)
content(response) 


Another example using R, a POST request for Bulk Import, can be written like this:

install.packages("jsonlite")
install.packages("RCurl")
install.packages("httr")
library(RCurl)
library(jsonlite)
library(httr)

# To run Bulk Import POST command
response<-POST("https://app.collaborativedrug.com/api/v1/vaults/1234/slurps", body = list(file = upload_file("C:/path/to/file/using/only/forward/slashes/filename.txt"), json = '{"project":"PROJECT-NAME"}'), add_headers(.headers = c("X-CDD-Token"="TOKEN-IN-DOUBLE-QUOTES")) ,verbose() ,.mapUnicode=FALSE)

# To view the SLURP-ID
content(response)

# To Check Status of the Bulk Import POST command
checkresponse <-getURI("https://app.collaborativedrug.com/api/v1/vaults/1234/slurps/SLURP-ID",httpheader = "X-CDD-Token:TOKEN-STARTING-WITH-COLON-ENDING-IN-DOUBLE-QUOTES",.mapUnicode=FALSE)

# To view JSON output of the Bulk Import POST command
fromJSON(checkresponse)