|
library(plumber) |
|
library(jsonlite) |
|
|
|
|
|
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))) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function(package, function, params) { |
|
|
|
if (!requireNamespace(package, quietly = TRUE)) { |
|
res <- list(error = paste("Package", package, "is not installed.")) |
|
return(res) |
|
} |
|
|
|
|
|
suppressWarnings(suppressMessages(library(package, character.only = TRUE))) |
|
|
|
|
|
if (!exists(function, where = asNamespace(package), mode = "function")) { |
|
res <- list(error = paste("Function", function, "does not exist in package", package)) |
|
return(res) |
|
} |
|
|
|
|
|
params <- lapply(params, function(x) { |
|
if (is.character(x)) { |
|
|
|
parsed <- tryCatch(jsonlite::fromJSON(x), error = function(e) x) |
|
return(parsed) |
|
} else { |
|
return(x) |
|
} |
|
}) |
|
|
|
|
|
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) |
|
} |
|
|
|
|
|
function(pr) { |
|
pr$setDebug(TRUE) |
|
} |
|
|