Skip to content

Commit

Permalink
[CRAN MOD] optimize example runs and file specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ineelhere committed Aug 28, 2024
1 parent 843c3c8 commit a5bacca
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
^README\.Rmd$
^CODE_OF_CONDUCT\.md$
^logo\.png$
^report.html$
^LICENSE$
^reports$
70 changes: 10 additions & 60 deletions R/ctg_data_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,13 @@
#' \item The generated report is self-contained and can be easily shared or published on the web.
#' }
#'
#' @examples
#' \donttest{
#' # Basic usage with default settings
#' ctg_data_report(my_clinical_trial_data)
#'
#' # Customized report with specific settings
#' 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(
#' my_clinical_trial_data,
#' title = "Quick Clinical Trial Overview",
#' include_data_quality = FALSE,
#' include_interactive_plots = FALSE
#' )
#' }
#'
#' @seealso
#' \url{https://www.indraneelchakraborty.com/clintrialx/} for more information about the ClinTrialX package.
#' @importFrom grDevices colorRampPalette
#' @importFrom utils install.packages installed.packages
#' @importFrom rmarkdown render
#' @export

ctg_data_report <- function(ctg_data,
title = "Clinical Trial Data Report",
author = "Author Name",
Expand All @@ -127,49 +101,25 @@ ctg_data_report <- function(ctg_data,
include_data_quality = TRUE,
include_interactive_plots = TRUE,
custom_footer = NULL) {

# List of required packages
required_packages <- c("rmarkdown", "ggplot2", "plotly", "dplyr", "lubridate", "reactable", "scales", "RColorBrewer", "htmltools")

# Function to check if a package is installed
is_installed <- function(package) {
return(package %in% rownames(installed.packages()))
}

# Check which packages are missing
missing_packages <- required_packages[!sapply(required_packages, is_installed)]
# Check if required packages are available
missing_packages <- required_packages[!sapply(required_packages, requireNamespace, quietly = TRUE)]

# If there are missing packages, print a message and offer to install them
if (length(missing_packages) > 0) {
cat("The following packages are required but not installed:\n")
cat(paste("-", missing_packages, collapse = "\n"), "\n\n")

install_choice <- readline(prompt = "Would you like to install these packages now? (yes/no): ")

if (tolower(install_choice) == "yes") {
install.packages(missing_packages)
cat("\nPackages installed successfully.\n")
} else {
cat("\nPlease install the missing packages before running the report generation function.\n")
return()
}
} else {
cat("All required packages are already installed.\n")
stop("The following required packages are not installed: ",
paste(missing_packages, collapse = ", "),
". Please install these packages before running this function.")
}

# Load all required packages
lapply(required_packages, library, character.only = TRUE)

cat("\nAll necessary packages are now loaded and ready to use.\n")

# Available themes
available_themes <- c("default", "cerulean", "journal", "flatly", "readable", "spacelab", "united", "cosmo", "lumen", "paper", "sandstone", "simplex", "yeti")

# Check if the provided theme is valid
if (!(theme %in% available_themes)) {
cat("Invalid theme selected. Available themes are:\n")
cat(paste("-", available_themes, collapse = "\n"), "\n\n")
theme_choice <- readline(prompt = "Please choose a valid theme: ")
theme <- match.arg(theme_choice, available_themes)
stop("Invalid theme selected. Available themes are: ", paste(available_themes, collapse = ", "))
}

# Create a temporary Rmd file
Expand Down Expand Up @@ -447,10 +397,10 @@ For any questions or further analysis requests, please contact the report author
writeLines(rmd_content, temp_rmd)

# Render the Rmd file to HTML
render(temp_rmd, output_file = output_file, output_dir = dirname(output_file))
rmarkdown::render(temp_rmd, output_file = output_file, output_dir = dirname(output_file))

# Clean up the temporary file
unlink(temp_rmd)

cat("Report successfully generated at:", normalizePath(output_file), "\n")
message("Report successfully generated at:", normalizePath(output_file), "\n")
}
8 changes: 4 additions & 4 deletions R/hello.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#' Print a Welcome Message
#'
#' This function prints a welcome message for ClinTrialX.
#' This function returns a welcome message for ClinTrialX.
#'
#' @return A character string containing the welcome message.
#' @export
#' @examples
#' hello()
hello <- function() {
message <- "Welcome to ClinTrialX!"
Encoding(message) <- "UTF-8"
print(message)
msg <- "Welcome to ClinTrialX!"
Encoding(msg) <- "UTF-8"
return(msg) # Return the message for further use
}
8 changes: 8 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ ctg_data_report(
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
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ ctg_data_report(
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
Expand Down
1 change: 0 additions & 1 deletion man/ctg_bulk_fetch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions man/ctg_data_report.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/hello.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a5bacca

Please sign in to comment.