Here’s an R function that you can use to download clinical trial data

Sometimes you need to look at a lot of sets of clinical trial data, and you don’t want to go to clinicaltrials.gov and do searches manually, then save the files manually, then load them into R or Excel manually to get your work done.

library(readr)
library(utils)

get_ct_dot_gov_data_for_drugname <- function (drugname) {

   temp <- tempfile()

   download.file(paste0("https://clinicaltrials.gov/ct2/results/download_fields?down_count=10000&down_flds=all&down_fmt=tsv&intr=", URLencode(drugname, reserved = TRUE), "&flds=a&flds=b&flds=y"), temp)

   trial_data <- read_delim(
     temp,
     "\t",
     escape_double = FALSE,
     trim_ws = TRUE
   )

   unlink(temp)

   return (trial_data)

 }

So here’s a function that you can use to download all the trials for a given drug name, and it returns a data frame with the trial metadata.

Enjoy!

Published by

The Grey Literature

This is the personal blog of Benjamin Gregory Carlisle PhD. Queer; Academic; Queer academic. "I'm the research fairy, here to make your academic problems disappear!"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.