gp_endpoint_from_clip: Adds an endpoint function to the plumber.R from clipboard.

View source: R/endpoint_from_clip.R

gp_endpoint_from_clipR Documentation

Adds an endpoint function to the plumber.R from clipboard.

Description

To use this function, write the endpoint somewhere and then copy it into clipboard. Then call this function. This function uses clipr to write it to the 'plumber.R' file. For now only file will be plumber.R

Usage

gp_endpoint_from_clip(evaluate = FALSE)

Arguments

evaluate

extra check on clipboard content

Details

TODO: add silent param, write to other .R files.

Value

None

Examples

## Not run: 
# Following is a valid endpoint to serve geoplumber::traffic dataset:
# = begin ===>
# Serve geoplumber::traffic from /api/data

# @get /api/data
# get_traffic <- function(res) {
#   geojson <- geojsonio::geojson_json(geoplumber::traffic)
#   res$body <- geojson
#   res
# }
# <==== end =
# holindg current clipboard
old_clip <- clipr::read_clip()
# adding above to clipboard
clipr::write_clip(c(
"#' Serve geoplumber::traffic from /api/data",
"@get /api/data",
"get_traffic <- function(res) {",
"geojson <- geojsonio::geojson_json(geoplumber::traffic)",
 "res$body <- geojson",
 "res",
"}"
))
# clipr::read_clip()
gp_endpoint_from_clip()
clipr::write_clip(old_clip)

## End(Not run)


ATFutures/geoplumber documentation built on July 4, 2023, 12:18 a.m.