File size: 2,138 Bytes
62a36f4 1e5380c 2499d49 62a36f4 1e5380c 62a36f4 1e5380c 62a36f4 1e5380c 62a36f4 1e5380c 62a36f4 1e5380c 62a36f4 1e5380c 62a36f4 1e5380c 62a36f4 1e5380c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
library(plumber)
library(jsonlite)
# Load all the meta-analysis packages (as per your original code)
packages <- nstall.packages(c("nlme", "lme4", "GLMMadaptive", "glmmML", "glmmTMB", "MCMCglmm", "brms", "mbest", "survival", "CAMAN", "mclust", "flexclust", "aods3", "censReg", "betareg", "VGAM", "gee", "geepack", "glmtoolbox", "mgcv", "devtools", "remotes", "testthat", "covr", "Formula", "mathjaxr", "pander", "knitr", "rmarkdown", "tidyverse", "table1", "tableone"))
for (pkg in packages) {
suppressWarnings(suppressMessages(library(pkg, character.only = TRUE)))
}
#* @apiTitle Comprehensive Meta-Analysis API
#* Perform meta-analysis using the selected package and function
#* @param package The name of the package to use
#* @param function The name of the function within the package to execute
#* @param params A list containing all necessary parameters for the function
#* @post /analyze
function(package, function, params) {
# Check if the package is installed
if (!requireNamespace(package, quietly = TRUE)) {
res <- list(error = paste("Package", package, "is not installed."))
return(res)
}
# Load the package
suppressWarnings(suppressMessages(library(package, character.only = TRUE)))
# Check if the function exists in the package
if (!exists(function, where = asNamespace(package), mode = "function")) {
res <- list(error = paste("Function", function, "does not exist in package", package))
return(res)
}
# Convert params from JSON to R objects if necessary
params <- lapply(params, function(x) {
if (is.character(x)) {
# Attempt to parse JSON strings
parsed <- tryCatch(jsonlite::fromJSON(x), error = function(e) x)
return(parsed)
} else {
return(x)
}
})
# Perform the analysis by calling the specified function with the provided params
result <- tryCatch({
func <- get(function, envir = asNamespace(package))
do.call(func, params)
}, error = function(e) {
list(error = paste("Error in", package, "function", function, ":", e$message))
})
return(result)
}
#* @plumber
function(pr) {
pr$setDebug(TRUE)
}
|