Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need function to run pkg plumber API's #440

Closed
schloerke opened this issue May 23, 2019 · 3 comments
Closed

Need function to run pkg plumber API's #440

schloerke opened this issue May 23, 2019 · 3 comments
Labels
difficulty: novice Anyone could help effort: low < 1 day of work help wanted Solution is well-specified enough that any community member could fix priority: low Will be fixed eventually type: enhancement Adds a new, backwards-compatible feature

Comments

@schloerke
Copy link
Collaborator

Given a package structure... https://community.rstudio.com/t/plumber-api-and-package-structure/18099/6?u=barret

Use something similar to ...

pkg_plumb <- function(package, name, ...) {
  plumb(dir = system.file(file.path("plumber", name), package = package))
}

... with roxygen docs (and examples?).

Maybe need to copy the inst/examples directory to inst/plumber/? (Should follow own pattern)

@schloerke schloerke added type: enhancement Adds a new, backwards-compatible feature difficulty: novice Anyone could help effort: low < 1 day of work priority: low Will be fixed eventually help wanted Solution is well-specified enough that any community member could fix labels May 23, 2019
@schloerke schloerke added this to the v0.5.0 - Next CRAN release milestone May 23, 2019
@meztez
Copy link
Collaborator

meztez commented Jun 26, 2020

This seems interesting, so basically expose all public function in a package?

Should be pretty simple, loop through exposed objects, when function add handle, when object add static.

makes sense?

@schloerke
Copy link
Collaborator Author

so basically expose all public function in a package?

I don't think so as some APIs should not have all pkg functionality.

I think it's more of a consistent way to distribute multiple plumber apis within a single package.

I think it should be something similar to learnr::run_tutorial(name, package), but I like the api structure of plumb_pkg(package, name) (with package before the name).

The solution for plumb_pkg() could be as short as the code above.


Regarding...

Maybe need to copy the inst/examples directory to inst/plumber/? (Should follow own pattern)

The plumber's own repo examples ./inst/examples folder should be moved to ./inst/plumber so that we can call all plumber examples using the new function.


To add into this, there should be a available_apis(package = NULL) function that inspects for installed apis. See learnr::available_tutorials(package = NULL) for an example: https://github.com/rstudio/learnr/blob/9dfe4a94fa3f8e0fa02b35fa55f9bcc0b571c49e/R/available_tutorials.R#L2-L33

If package is not provided, it should return all available apis for all packages. See: https://github.com/rstudio/learnr/blob/9dfe4a94fa3f8e0fa02b35fa55f9bcc0b571c49e/R/available_tutorials.R#L123-L130 . Yes, this is slow, but it is not a critical path for execution.

Given there is no yaml front matter to consume, I think we could just return a data.frame of package, name.


Then to tie it all off, we could have a print method. See: https://github.com/rstudio/learnr/blob/9dfe4a94fa3f8e0fa02b35fa55f9bcc0b571c49e/R/available_tutorials.R#L167-L209

I would expect something similar to

PKG:
 - Name1
 - Name2
 - Name3

PKG2:
 - Name1
 - Name2

.. but with no other information to consume from the file (ex yaml front matter), maybe the data.frame print method is ok. 🤷

@schloerke
Copy link
Collaborator Author

Fixed in #631

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: novice Anyone could help effort: low < 1 day of work help wanted Solution is well-specified enough that any community member could fix priority: low Will be fixed eventually type: enhancement Adds a new, backwards-compatible feature
Projects
None yet
Development

No branches or pull requests

3 participants