function (file, dir = ".") { dirMode <- NULL if (!missing(file) && !missing(dir)) { stop("You must set either the file or the directory parameter, not both") } else if (missing(file)) { if (identical(dir, "")) { stop("You must specify either a file or directory parameter") } dirMode <- TRUE dir <- sub("/$", "", dir) file <- list.files(dir, "^plumber\\.r$", ignore.case = TRUE, full.names = TRUE) if (length(file) == 0) { stop("No plumber.R file found in the specified directory: ", dir) } } else { dirMode <- FALSE } entrypoint <- list.files(dir, "^entrypoint\\.r$", ignore.case = TRUE) if (dirMode && length(entrypoint) > 0) { old <- setwd(dir) on.exit(setwd(old)) x <- source(entrypoint) pr <- x$value if (!("plumber" %in% class(pr))) { stop("entrypoint.R must return a runnable Plumber router.") } pr } else if (file.exists(file)) { plumber$new(file) } else { stop("File does not exist: ", file) } }