diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index ccbe25e..ffced6b 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -4,34 +4,41 @@ on: [push, pull_request] jobs: R-CMD-check: - runs-on: ubuntu-latest - container: - image: rocker/tidyverse:latest - + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'release'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + steps: - name: Checkout repository - uses: actions/checkout@v2 - - - name: Set up R + uses: actions/checkout@v4 + + - name: Setup Pandoc + uses: r-lib/actions/setup-pandoc@v2 + + - name: Setup R uses: r-lib/actions/setup-r@v2 - - - name: Set environment variables - run: | - echo "R_LIBS_USER=/__w/_temp/Library" >> $GITHUB_ENV - echo "TZ=UTC" >> $GITHUB_ENV - echo "_R_CHECK_SYSTEM_CLOCK_=FALSE" >> $GITHUB_ENV - echo "NOT_CRAN=true" >> $GITHUB_ENV - - - name: Restore R package dependencies - run: R -e 'renv::restore()' - - - name: Install devtools - run: | - renv::install('devtools') - shell: Rscript {0} - - - name: Install the package - run: R CMD INSTALL . - - - name: Run tests - run: R -e 'devtools::test()' + with: + r-version: ${{ matrix.config.r }} + use-public-rspm: true + + - name: Setup R dependencies + uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck, any::devtools + needs: check + + - name: Check R package + uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true diff --git a/.github/workflows/riskassessr.yaml b/.github/workflows/riskassessr.yaml new file mode 100644 index 0000000..b1285f8 --- /dev/null +++ b/.github/workflows/riskassessr.yaml @@ -0,0 +1,317 @@ +name: Package Risk Assessment + +on: + push: + +jobs: + risk-assessment: + runs-on: ubuntu-latest + name: Risk Assessment + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup R + uses: r-lib/actions/setup-r@v2 + with: + r-version: 'release' + use-public-rspm: true + + - name: Setup Pandoc + uses: r-lib/actions/setup-pandoc@v2 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y libcurl4-openssl-dev libssl-dev libxml2-dev + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Cache R packages + uses: actions/cache@v3 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install package dependencies + run: | + remotes::install_deps(dependencies = TRUE) + shell: Rscript {0} + + - name: Install risk.assessr and additional dependencies + run: | + install.packages(c("risk.assessr", "crayon", "knitr")) + shell: Rscript {0} + + - name: Build package + run: | + devtools::build(path = ".", vignettes = FALSE) + shell: Rscript {0} + + - name: Run Risk Assessment + run: | + # Load required libraries + library(risk.assessr) + library(crayon) + + # Set up CRAN repository + r <- getOption("repos") + r["CRAN"] <- "https://cloud.r-project.org" + options(repos = r) + + cat("=== Starting Package Risk Assessment ===\n") + cat("Repository:", Sys.getenv("GITHUB_REPOSITORY"), "\n") + cat("Branch:", Sys.getenv("GITHUB_REF_NAME"), "\n") + cat("Workflow run:", Sys.getenv("GITHUB_RUN_ID"), "\n") + cat("Timestamp:", format(Sys.time(), "%Y-%m-%d %H:%M:%S UTC"), "\n\n") + + # Pretty print function for GitHub Actions logs + pretty_print_assessment <- function(assessment_results) { + + if (is.null(assessment_results) || length(assessment_results) == 0) { + cat("āŒ No assessment results to display.\n") + return() + } + + # Helper functions for colored output in GitHub Actions + print_header <- function(title) { + cat("\n") + cat("šŸ” ===", title, "===\n") + cat(paste(rep("=", nchar(title) + 10), collapse = ""), "\n") + } + + print_subheader <- function(title) { + cat("\nšŸ“Š", title, "\n") + cat(paste(rep("-", nchar(title) + 3), collapse = ""), "\n") + } + + # Extract package name + pkg_name <- "Unknown Package" + if ("package" %in% names(assessment_results)) { + pkg_name <- assessment_results$package + } else if ("pkg_name" %in% names(assessment_results)) { + pkg_name <- assessment_results$pkg_name + } + + print_header("PACKAGE ASSESSMENT RESULTS") + cat("šŸ“¦ Package:", pkg_name, "\n") + cat("ā° Generated:", format(Sys.time(), "%Y-%m-%d %H:%M:%S"), "\n") + + # Print R CMD Check Results + if ("rcmdcheck" %in% names(assessment_results)) { + print_header("R CMD CHECK RESULTS") + rcmd <- assessment_results$rcmdcheck + + if (is.list(rcmd)) { + # Errors + if ("errors" %in% names(rcmd) && length(rcmd$errors) > 0) { + print_subheader("🚨 ERRORS") + for (error in rcmd$errors) { + cat("āŒ", error, "\n") + } + cat("::error::R CMD check found", length(rcmd$errors), "error(s)\n") + } else { + cat("āœ… No errors found\n") + } + + # Warnings + if ("warnings" %in% names(rcmd) && length(rcmd$warnings) > 0) { + print_subheader("āš ļø WARNINGS") + for (warning in rcmd$warnings) { + cat("āš ļø", warning, "\n") + } + cat("::warning::R CMD check found", length(rcmd$warnings), "warning(s)\n") + } else { + cat("āœ… No warnings found\n") + } + + # Notes + if ("notes" %in% names(rcmd) && length(rcmd$notes) > 0) { + print_subheader("šŸ“ NOTES") + for (note in rcmd$notes) { + cat("ā„¹ļø", note, "\n") + } + cat("::notice::R CMD check found", length(rcmd$notes), "note(s)\n") + } else { + cat("āœ… No notes\n") + } + } else { + cat(as.character(rcmd), "\n") + } + } + + # Print Coverage Results + if ("covr" %in% names(assessment_results)) { + print_header("CODE COVERAGE") + covr <- assessment_results$covr + + if (is.numeric(covr)) { + coverage_pct <- round(covr, 2) + if (coverage_pct >= 80) { + cat("āœ… Coverage:", coverage_pct, "%\n") + } else if (coverage_pct >= 60) { + cat("āš ļø Coverage:", coverage_pct, "%\n") + cat("::warning::Code coverage is below 80%\n") + } else { + cat("āŒ Coverage:", coverage_pct, "%\n") + cat("::error::Code coverage is below 60%\n") + } + } else if (is.data.frame(covr)) { + cat("Coverage details:\n") + print(covr) + } else { + cat(as.character(covr), "\n") + } + } + + # Print Dependencies + if ("dependencies" %in% names(assessment_results)) { + print_header("DEPENDENCIES") + deps <- assessment_results$dependencies + + if (is.data.frame(deps)) { + if (nrow(deps) > 0) { + cat("šŸ“‹ Found", nrow(deps), "dependencies:\n") + print(deps) + } else { + cat("āœ… No dependencies found\n") + } + } else if (is.list(deps)) { + if (length(deps) > 0) { + for (name in names(deps)) { + cat("•", name, ":", as.character(deps[[name]]), "\n") + } + } else { + cat("āœ… No dependencies found\n") + } + } else { + cat(as.character(deps), "\n") + } + } + + # Print Metrics + if ("metrics" %in% names(assessment_results)) { + print_header("PACKAGE METRICS") + metrics <- assessment_results$metrics + + if (is.data.frame(metrics)) { + if (nrow(metrics) > 0) { + print(metrics) + } else { + cat("No metrics data available\n") + } + } else if (is.list(metrics)) { + if (length(metrics) > 0) { + for (name in names(metrics)) { + cat("•", name, ":", as.character(metrics[[name]]), "\n") + } + } else { + cat("No metrics data available\n") + } + } else { + cat(as.character(metrics), "\n") + } + } + + # Print other components + other_components <- names(assessment_results)[!names(assessment_results) %in% + c("rcmdcheck", "covr", "dependencies", "metrics", "package", "pkg_name")] + + if (length(other_components) > 0) { + print_header("OTHER ASSESSMENT DATA") + + for (component in other_components) { + data <- assessment_results[[component]] + cat("\nšŸ“‹", toupper(component), "\n") + + if (is.data.frame(data) && nrow(data) > 0) { + print(data) + } else if (is.list(data) && length(data) > 0) { + str(data, max.level = 2) + } else if (!is.null(data) && length(data) > 0) { + cat(as.character(data), "\n") + } else { + cat("No data available\n") + } + } + } + + # Summary + print_header("ASSESSMENT SUMMARY") + cat("šŸ“Š Total components assessed:", length(assessment_results), "\n") + + # Create GitHub Actions summary + error_count <- if("rcmdcheck" %in% names(assessment_results) && + "errors" %in% names(assessment_results$rcmdcheck)) + length(assessment_results$rcmdcheck$errors) else 0 + warning_count <- if("rcmdcheck" %in% names(assessment_results) && + "warnings" %in% names(assessment_results$rcmdcheck)) + length(assessment_results$rcmdcheck$warnings) else 0 + note_count <- if("rcmdcheck" %in% names(assessment_results) && + "notes" %in% names(assessment_results$rcmdcheck)) + length(assessment_results$rcmdcheck$notes) else 0 + + if (error_count > 0) { + cat("::error::Assessment completed with", error_count, "errors\n") + } else if (warning_count > 0) { + cat("::warning::Assessment completed with", warning_count, "warnings\n") + } else { + cat("::notice::Assessment completed successfully\n") + } + + cat("\nšŸŽ‰ Assessment display completed!\n") + } + + # Run the assessment + tryCatch({ + cat("šŸš€ Starting risk assessment...\n") + + # Build the package in a temp directory + built_pkg <- devtools::build(".", quiet = FALSE, path = tempdir()) + cat("šŸ“¦ Package built:", built_pkg, "\n") + + # Run risk assessment on the built tarball + comprehensive_assessment <- risk_assess_pkg(built_pkg) + + # Print the results + pretty_print_assessment(comprehensive_assessment) + + }, error = function(e) { + cat("::error::Assessment failed with error:", e$message, "\n") + cat("šŸ“‹ Attempting fallback assessment...\n") + + # Fallback: try assessment in current directory + tryCatch({ + comprehensive_assessment <- risk_assess_pkg(".") + pretty_print_assessment(comprehensive_assessment) + + }, error = function(e2) { + cat("::error::Fallback assessment also failed:", e2$message, "\n") + cat("šŸ” Package structure:\n") + cat(paste(list.files(".", recursive = TRUE, include.dirs = TRUE), collapse = "\n"), "\n") + }) + }) + + cat("\n=== Risk Assessment Complete ===\n") + shell: Rscript {0} + + - name: Upload assessment artifacts + uses: actions/upload-artifact@v4 + if: always() + with: + name: risk-assessment-logs + path: | + *.log + *.Rcheck/ + retention-days: 30 diff --git a/README.Rmd b/README.Rmd deleted file mode 100644 index 12ce7ae..0000000 --- a/README.Rmd +++ /dev/null @@ -1,220 +0,0 @@ ---- -output: github_document -editor_options: - markdown: - wrap: 72 ---- - - - -```{r include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - fig.path = "man/figures/README-", - out.width = "100%" -) -``` - -# `ClinTrialX` - - -[![R-CMD-check](https://github.com/ineelhere/clintrialx/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ineelhere/clintrialx/actions/workflows/R-CMD-check.yaml) -[![License: -Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://opensource.org/license/apache-2-0) -[![pkgdown](https://img.shields.io/badge/pkgdown-docs-blue.svg)](https://www.indraneelchakraborty.com/clintrialx/) -[![Visitors](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2Fineelhere%2Fclintrialx&label=Visitors&labelColor=%23f47373&countColor=%2337d67a&style=flat&labelStyle=upper)](https://github.com/ineelhere/clintrialx) -[![CRAN -status](https://www.r-pkg.org/badges/version/clintrialx)](https://CRAN.R-project.org/package=clintrialx) -[![CRAN -downloads](https://cranlogs.r-pkg.org/badges/clintrialx)](https://CRAN.R-project.org/package=clintrialx) - -[![Data Sources: -ClinicalTrials.gov](https://img.shields.io/badge/Data_Sources-ClinicalTrials.gov-blue)](https://clinicaltrials.gov/data-api/api) -[![Data Sources: CTTI -AACT](https://img.shields.io/badge/Data_Sources-CTTI%20AACT%20-purple)](https://aact.ctti-clinicaltrials.org/) - - - -The goal of `{clintrialx}` is to fetch clinical trials data from freely -available registries. Currently, it supports querying the - -- [ClinicalTrials.gov](https://clinicaltrials.gov/) registry using its - [V2 API](https://clinicaltrials.gov/data-api/api) and - -- [CTTI AACT](https://aact.ctti-clinicaltrials.org/) (Public Access to - Aggregate Content of ClinicalTrials.gov). - -## Installation - -Install the package from [CRAN](https://CRAN.R-project.org/package=clintrialx) with: -```r -install.packages("clintrialx") -``` -You can install this package from -[GitHub](https://github.com/ineelhere/clintrialx) with: - -*you'll need the `devtools` package for this* - -``` r -# install.packages("devtools") -devtools::install_github("ineelhere/clintrialx") -``` - -### Check installation - -``` r -library(clintrialx) -``` - -## Setup AACT account - -#### `Only if you wish to use AACT as a source for the data` - -- Visit - -- Sign up and create an account. It's free. - -- The `username` and `password` will be needed to fetch data using - this package. - -- Save it in a `.Renviron` file, for example- - - ``` r - user = "random_name" - password = "random_password" - ``` - -- Now that the file is created, load the variable with the command - `readRenviron("path/to/.Renviron)` - -- You're all set! - -## Query the [ClinicalTrials.gov](https://clinicaltrials.gov/) Registry - -#### Based on NCT IDs - -Fetch one or multiple trial records based on NCT IDs. You can opt to -fetch some specific fields or all fields available at source (default). - -```{r example1, eval = FALSE} -library(clintrialx) -ctg_get_nct(c("NCT02967965", "NCT04000165", "NCT01007279", "NCT02376244", "NCT01179776"), - fields = c("NCT Number", "Study Title", "Study Status", "Sponsor")) - - -``` - -#### Based on fileds - -Supports filtering by condition, location, title keywords, intervention, -and overall status. - -```{r example2, eval = FALSE} -ctg_get_fields( - condition = "Cancer", - location = "Kolkata", - title = NULL, - intervention = "Drug", - status = c("ACTIVE_NOT_RECRUITING", "RECRUITING"), - page_size = 10 -) - -``` - -#### Based on fields - Bulk download - -Download all available data for your query. No limits! - -*Supports filtering by condition, location, title keywords, -intervention, and overall status.* - -```{r example5, eval = FALSE} -df <- ctg_bulk_fetch(location="india") -``` - -## Query the [CTTI AACT](https://aact.ctti-clinicaltrials.org/) - -#### Run Custom Queries - -``` -# Set environment variables for database credentials in .Renviron and load it -# readRenviron(".Renviron") - -# Connect to the database -con <- aact_connection(Sys.getenv('user'), Sys.getenv('password')) - -# Run a custom query -query <- "SELECT nct_id, source, enrollment, overall_status FROM studies LIMIT 5;" -results <- aact_custom_query(con, query) - -# Print the results -print(results) -``` - -## Trial Data HTML Reports - -*Currently works for data from ClinicalTrials.Gov* - -Visit here for an exqample report - - - -```{r example6, eval = FALSE} -#first get the data in a R dataframe -my_clinical_trial_data <- ctg_bulk_fetch(condition="cancer") -#now pass it to the reports function -ctg_data_report( - ctg_data = my_clinical_trial_data, - title = "Clinical Trials Analysis", - author = "Indra", - output_file = "reports/clinical_trials.html", - theme = "flatly", - color_palette = c("#4E79A7", "#F28E2B", "#E15759", "#76B7B2", "#59A14F", "#EDC948"), - include_data_quality = TRUE, - include_interactive_plots = TRUE, - custom_footer = "Proprietary report generated by SomeGreatOrg Inc." -) - -# Generate a report with static plots and no data quality assessment -ctg_data_report( - ctg_data = my_clinical_trial_data, - title = "Quick Clinical Trial Overview", - include_data_quality = FALSE, - include_interactive_plots = FALSE -) - -``` - -Check the path `reports/clinical_trials.html` on your local. It will -have the html report file. - -Cool stuff - It also has the codes to the plots! - -## Data Sources - -You can fetch version information directly from the package: - -```{r example3, eval = FALSE} -version_info(source = "clinicaltrials.gov") - - -``` - -## Get Involved - -šŸš€ Ready to contribute? Let's make clintrialx even better! - -- Fork the [GitHub](https://github.com/ineelhere/clintrialx) repo. -- Check out your development branch from the dev branch. -- Do your work on a feature (ftr) branch. -- Raise a PR against the dev branch of the [clintrialx](https://github.com/ineelhere/clintrialx) repo. -- Sit back and [relax](https://www.youtube.com/watch?v=Uffjii1hXzU) while I review it! - -šŸ’¬ **Questions or Feedback?** Feel free to open an issue on [GitHub -Issues page](https://github.com/ineelhere/clintrialx/issues). - -🌟 **Enjoying `clintrialx`?** Please consider giving it a star on -[GitHub](https://github.com/ineelhere/clintrialx)! Your support helps -this project grow and improve. - -More updates to come. Happy coding! šŸŽ‰ diff --git a/README.md b/README.md index 5bc4af5..0ca3f82 100644 --- a/README.md +++ b/README.md @@ -5,20 +5,17 @@ +[![CRAN status](https://www.r-pkg.org/badges/version/clintrialx)](https://CRAN.R-project.org/package=clintrialx) +[![CRAN downloads](https://cranlogs.r-pkg.org/badges/clintrialx)](https://CRAN.R-project.org/package=clintrialx) [![R-CMD-check](https://github.com/ineelhere/clintrialx/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ineelhere/clintrialx/actions/workflows/R-CMD-check.yaml) -[![License: -Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://opensource.org/license/apache-2-0) +[![Security Status](https://img.shields.io/badge/security-verified-green?label=OSS%20Index)](https://ossindex.sonatype.org/component/pkg:cran/clintrialx) +[![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://opensource.org/license/apache-2-0) [![pkgdown](https://img.shields.io/badge/pkgdown-docs-blue.svg)](https://www.indraneelchakraborty.com/clintrialx/) +[![Data Sources: ClinicalTrials.gov](https://img.shields.io/badge/Data_Sources-ClinicalTrials.gov-blue)](https://clinicaltrials.gov/data-api/api) +[![Data Sources: CTTI AACT](https://img.shields.io/badge/Data_Sources-CTTI%20AACT%20-purple)](https://aact.ctti-clinicaltrials.org/) [![Visitors](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2Fineelhere%2Fclintrialx&label=Visitors&labelColor=%23f47373&countColor=%2337d67a&style=flat&labelStyle=upper)](https://github.com/ineelhere/clintrialx) -[![CRAN -status](https://www.r-pkg.org/badges/version/clintrialx)](https://CRAN.R-project.org/package=clintrialx) -[![CRAN -downloads](https://cranlogs.r-pkg.org/badges/clintrialx)](https://CRAN.R-project.org/package=clintrialx) - -[![Data Sources: -ClinicalTrials.gov](https://img.shields.io/badge/Data_Sources-ClinicalTrials.gov-blue)](https://clinicaltrials.gov/data-api/api) -[![Data Sources: CTTI -AACT](https://img.shields.io/badge/Data_Sources-CTTI%20AACT%20-purple)](https://aact.ctti-clinicaltrials.org/) + + diff --git a/renv.lock b/renv.lock index 8b4cd81..4081470 100644 --- a/renv.lock +++ b/renv.lock @@ -739,4 +739,4 @@ "Hash": "9cb28d11799d93c953f852083d55ee9e" } } -} +} \ No newline at end of file diff --git a/vignettes/usecase-doc.R b/vignettes/usecase-doc.R index 9a3468a..c2869c7 100644 --- a/vignettes/usecase-doc.R +++ b/vignettes/usecase-doc.R @@ -1,74 +1,74 @@ ## ----eval=FALSE--------------------------------------------------------------- -# # Load required libraries -# invisible(suppressPackageStartupMessages({ -# library(clintrialx) # For fetching clinical trial data -# library(ggplot2) # For data visualization -# library(plotly) # For interactive plots -# library(dplyr) # For data manipulation -# library(lubridate) # For date handling -# })) +# # Load required libraries +# invisible(suppressPackageStartupMessages({ +# library(clintrialx) # For fetching clinical trial data +# library(ggplot2) # For data visualization +# library(plotly) # For interactive plots +# library(dplyr) # For data manipulation +# library(lubridate) # For date handling +# })) ## ----eval=FALSE--------------------------------------------------------------- -# # Fetch cancer study data in India -# df <- ctg_bulk_fetch(condition = "cancer", location = "India") +# # Fetch cancer study data in India +# df <- ctg_bulk_fetch(condition = "cancer", location = "India") ## ----eval=FALSE--------------------------------------------------------------- -# # Create a table of study statuses -# status_counts <- table(df$`Study Status`) -# -# # Convert the table to a data frame -# status_df <- data.frame(status = names(status_counts), count = as.numeric(status_counts)) -# -# # Generate the bar plot -# ggplotly(ggplot(status_df, aes(x = reorder(status, -count), y = count)) + -# geom_bar(stat = "identity", fill = "orange") + -# theme_minimal() + -# labs(title = "Distribution of Study Statuses", -# x = "Study Status", -# y = "Count") + -# theme(axis.text.x = element_text(angle = 45, hjust = 1)) + -# geom_text(aes(label = count), vjust = -0.5)) +# # Create a table of study statuses +# status_counts <- table(df$`Study Status`) +# +# # Convert the table to a data frame +# status_df <- data.frame(status = names(status_counts), count = as.numeric(status_counts)) +# +# # Generate the bar plot +# ggplotly(ggplot(status_df, aes(x = reorder(status, -count), y = count)) + +# geom_bar(stat = "identity", fill = "orange") + +# theme_minimal() + +# labs(title = "Distribution of Study Statuses", +# x = "Study Status", +# y = "Count") + +# theme(axis.text.x = element_text(angle = 45, hjust = 1)) + +# geom_text(aes(label = count), vjust = -0.5)) ## ----eval=FALSE--------------------------------------------------------------- -# # Create an interactive box plot of enrollment by study phase -# ggplotly(ggplot(df, aes(x = Phases, y = Enrollment)) + -# geom_boxplot(fill = "lightblue", outlier.colour = "red", outlier.shape = 1) + -# geom_jitter(color = "darkblue", size = 0.5, alpha = 0.5, width = 0.2) + -# theme_minimal(base_size = 14) + -# labs(title = "Enrollment by Study Phase", -# x = "Study Phase", -# y = "Enrollment") + -# theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 12), -# plot.title = element_text(hjust = 0.5))) +# # Create an interactive box plot of enrollment by study phase +# ggplotly(ggplot(df, aes(x = Phases, y = Enrollment)) + +# geom_boxplot(fill = "lightblue", outlier.colour = "red", outlier.shape = 1) + +# geom_jitter(color = "darkblue", size = 0.5, alpha = 0.5, width = 0.2) + +# theme_minimal(base_size = 14) + +# labs(title = "Enrollment by Study Phase", +# x = "Study Phase", +# y = "Enrollment") + +# theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 12), +# plot.title = element_text(hjust = 0.5))) ## ----eval=FALSE--------------------------------------------------------------- -# # Convert date strings to Date objects -# df$start_date <- as.Date(df$`Start Date`, format = "%Y-%m-%d") -# df$completion_date <- as.Date(df$`Completion Date`, format = "%Y-%m-%d") -# -# # Create a scatter plot with a horizontal line at 2024 -# ggplot(df, aes(x = start_date, y = completion_date, color = `Study Status`)) + -# geom_point(alpha = 0.6) + -# geom_hline(yintercept = as.Date("2024-01-01"), linetype = "dashed", color = "blue") + -# theme_minimal() + -# labs(title = "Study Duration Timeline", -# x = "Start Date", -# y = "Completion Date") + -# scale_color_brewer(palette = "Set1") +# # Convert date strings to Date objects +# df$start_date <- as.Date(df$`Start Date`, format = "%Y-%m-%d") +# df$completion_date <- as.Date(df$`Completion Date`, format = "%Y-%m-%d") +# +# # Create a scatter plot with a horizontal line at 2024 +# ggplot(df, aes(x = start_date, y = completion_date, color = `Study Status`)) + +# geom_point(alpha = 0.6) + +# geom_hline(yintercept = as.Date("2024-01-01"), linetype = "dashed", color = "blue") + +# theme_minimal() + +# labs(title = "Study Duration Timeline", +# x = "Start Date", +# y = "Completion Date") + +# scale_color_brewer(palette = "Set1") ## ----eval=FALSE--------------------------------------------------------------- -# # Summarize and plot funding sources by study type -# df_summary <- df %>% -# count(`Funder Type`, `Study Type`) %>% -# group_by(`Funder Type`) %>% -# mutate(prop = n / sum(n)) -# -# ggplotly(ggplot(df_summary, aes(x = `Funder Type`, y = prop, fill = `Study Type`)) + -# geom_bar(stat = "identity", position = "dodge") + -# theme_minimal() + -# labs(title = "Funding Sources and Study Types", -# x = "Funder Type", -# y = "Proportion") + -# scale_fill_brewer(palette = "Set2") + -# theme(axis.text.x = element_text(angle = 45, hjust = 1))) +# # Summarize and plot funding sources by study type +# df_summary <- df %>% +# count(`Funder Type`, `Study Type`) %>% +# group_by(`Funder Type`) %>% +# mutate(prop = n / sum(n)) +# +# ggplotly(ggplot(df_summary, aes(x = `Funder Type`, y = prop, fill = `Study Type`)) + +# geom_bar(stat = "identity", position = "dodge") + +# theme_minimal() + +# labs(title = "Funding Sources and Study Types", +# x = "Funder Type", +# y = "Proportion") + +# scale_fill_brewer(palette = "Set2") + +# theme(axis.text.x = element_text(angle = 45, hjust = 1)))