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!
