feat: check if a file / folder contains an ambiorix app
I use utility functions like this to determine if a folder / file contains a shiny app or plumber API.
I cannot come up with a way to do this for an ambiorix app.
Perhaps there can be a function that takes a file / path that contains an app and returns that Ambiorix object?
is_shiny_app <- function(path) {
tryCatch(
!is.null(shiny::shinyAppDir(path)),
error = function(cond) FALSE
)
}
is_plumber_api <- function(path) {
tryCatch(
length(plumber::plumb(dir = path)$routes) > 0,
error = function(cond) FALSE
)
}
my thoughts on this so far are:
- we'd have to agree on a series of files to check since ambiorix does not dictate the file naming. good candidates for this:
app.R: a general name (kind of a consensus in the R community?)index.R: for frontend appsserver.R: for JSON data APIs
- a very naive & brute-force approach would be to check for the existence of the string "Ambiorix$new" in the file (since that is the way to instantiate an ambiorix app).
Here plumber and shiny use the principle of convention over configuration. In many other languages frameworks you have a routes file always in the same place and it's easy to check it. In Ambiorix, the creation and routes can be in any file (or inside another package) If we go for option 2, I think we could have has_ambiorix_new_dir function (or similar name) to make it clar that looks Ambiorix::new in all .R files of the directory.