Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Contact Us
  • Home
  • CDMS
  • Castor CDMS Manual
  • Link Castor to another application

Using the Castor API R package for data analysis

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • CDMS
    Castor CDMS Manual Castor CDMS Calculations Manual Frequently Asked Questions Articles for Data Managers Castor CDMS Compliance Release Documents
  • eConsent
    Castor eConsent Manual Castor eConsent Compliance Release Documents
  • SMS
    Castor SMS Manual Castor SMS Compliance Release Documents
  • Castor Connect
    Castor Connect Compliance Release Documents Castor Connect Manual Castor Connect - Participant Quick Start Guide
  • Helpdesk
    News Other Resources Castor products knowledge resources
  • Status page
  • Completing a Study
+ More

Table of Contents

Package Structure Installation Usage Troubleshooting I cannot authenticate

You can use the Castor API R package to access study data in Castor via R. Please note that the 'castoRedc' project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms. For a simple data export and/or study and report data merge, see: How can I export and merge data in R?

To get started with R, RStudio and RShiny, see also: Introduction to R, RStudio and RShiny - Create your own dashboards 

Package Structure

There are three ways to access data through the API:

  1. Access to individual items (getStudyDataPoint, getStudy, getRecord, etc.)
  2. Access to pages of items in a list (getStudies, getRecords, etc.)
  3. Processed into a data frame for straightforward analysis (getStudyData)

Installation

# install.packages("remotes")
remotes::install_github("castoredc/castoRedc")

Usage

  1. Generate your Castor credentials, see: Application Programming Interface (API). Please note that the Client ID and Secret grant the same access to your data as your own username and password. Please treat them as such and do not hand them out to others (including us at Castor). We recommend reading about securely managing your credentials.
  2. Authenticate using your Castor credentials. In the code below we store the credentials in environment variables. If you share your code with collaborators, you won't have to worry about removing your credentials before sharing the code. Check here how you can use environment variables.
    library(castoRedc)
    castor_api <- CastorData$new(key = Sys.getenv("CASTOR_KEY"),
     secret = Sys.getenv("CASTOR_SECRET"),
     base_url = "https://data.castoredc.com")
    If you're not planning to share your code, you could simply use:
    library(castoRedc)
    castor_api <- CastorData$new(key = "YOUR_CLIENTID_HERE",
     secret = "YOUR_SECRET_HERE",
     base_url = "https://data.castoredc.com")
    Please bear in mind that this code will contain your client ID and secret, so do not share them with anyone. Anyone that has your client ID and secret will be able to access your data via your account!
  3. Get a list of the studies you have access to with:
    studies <- castor_api$getStudies()
  4. Subsequently, get a study ID, for example:
    (example_study_id <- studies[["study_id"]][1])
    #> [1] "012A3A45-6ABB-7890-1234-567A8AB90A12"
  5. You can use the study ID to get the study's participants, data, forms, visits, etc.

For example:

  1. Get a list of participants with:
    participants <- castor_api$getParticipants("YOUR_STUDY_ID")
  2. Get the study data with:
    studydata <- castor_api$getStudyData("YOUR_STUDY_ID")


A complete list of functions, and parameters, can be retrieved with:

str(castor_api)


Troubleshooting

I cannot authenticate

Upon authenticating you might have received the error:

Error in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params, :
Bad Request (HTTP 400). Failed to get an access token

The error indicates that the authentication did not go well. Please check your user credentials - make sure that you use the most recent secret. You can check if your credentials are alright with:

castor_api <- CastorData$new(key = "YOUR_KEY_HERE",
secret = "YOUR_SECRET_HERE",
base_url = "https://data.castoredc.com")

In our R package documentation, we generally recommend to use system variables to store your credentials. This is safer than the example above, because the credentials are not directly pasted in the code. If you share your code with collaborators, you won't have to worry about removing your credentials before sharing the code. Please also view this article (bullet point 5) to learn more about what a system environment is.

data analysis castor api

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Enable importing EHR data for your study in Castor EDC/CDMS
  • Import data from electronic health records (EHR) in EDC/CDMS
  • Castor EDC/CDMS Application Programming Interface (API)
  • Configure fields for importing of EHR data in EDC/CDMS
ISO 27001
FDA - 21 CFR part 11
ICH GCP compliant
HIPAA compliant
CDISC
ISO 9001
gdpr compliant

Products & Industries

  • Electronic Data Capture (EDC)
  • ePRO
  • eConsent
  • Decentralized Clinical Trials (DCT)
  • Clinical Data Management
  • Medical Device & Diagnostics
  • Biotech & Pharma
  • CROs
  • Academic Research

Resources

  • Thought Leadership
  • Blog
  • Castor Academy
  • Knowledge Base

 

Company

  • About Us
  • Careers
  • News
  • Contact Support
  • Contact Us

Legal & Compliance

  • Terms of Use
  • Privacy & Cookie Statement
  • Responsible Disclosure Policy
  • Good Clinical Practice (GCP)
  • ISO Compliance Certificates
  • GDPR & HIPAA Compliance
  • Security Statement

© 2022, Castor. All Rights Reserved.

Follow us on social media


Knowledge Base Software powered by Helpjuice

Definition by Author

0
0
Expand