Skip to content

Add edit parameter to plumb_api() #699

@blairj09

Description

@blairj09

After an extensive conversation with @schloerke, we've decided to add an edit parameter to the plumb_api() function. This parameter will open the plumber.R or entrypoint.R file associated with a specified Plumber API. This will enable Plumber users to quickly and easily view source code for Plumber APIs that are included in R packages.

The expected behavior of this feature is as follows:

plumb_api("plumber", "01-append", edit = TRUE)
  1. A message is presented to the user specifying the path of the directory containing the source code and a warning that if they want to make persistent changes to the code, they should copy it to a separate file.
  2. The associated plumber.R file is opened for editing
  3. If using RStudio, the files pane is directed to the directory containing the source code

There were a few alternative options discussed that were ultimately rejected:

  • Copying the source directory to a temporary location and opening the files from there
    This idea was based on preventing users from accidentally changing the behavior of API examples included with installed packages. It was ultimately decided that the simplest solution is to just open the original source file and provide the user with a warning about permanently editing the files.

  • Creating a separate pr_view_source() function.
    This idea was based around the private $filename value for Plumber routers. The idea was to capture that filename and to open the source file. This approach was rejected in favor of adding edit to plumb_api() for simplicity sake. Using plumb_api() instead of introducing a new function also restricts this functionality to APIs included in installed packages, which is a desired characteristic.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions