MazamaScience/beakr

reformatted code snippets should work if copy-pasted

Closed this issue · 0 comments

Several functions currently have examples in the form of preformatted code snippets. We aren't using @example because we don't actually want to start up a web service.

To encourage people to use a new package it is really nice to have examples that can just be copy-pasted into the RStudio console where a user can observe what happens. The code examples are currently structured as pseudo-code where a user has to modify things before they can be run. This acts as a barrier to first-time users.

All examples should instead modify the existing example in README.md using comment lines to explain rather than pseudo-code. The goal is to have all examples work if copy-pasted into the RStudio console.

library(beakr)

# Create a new beakr server
newBeakr() %>% 

  # Respond to GET requests at the "/hi" route
  httpGET(path = "/hi", function(req, res, err) {
    print("Hello, World!")
  }) %>% 
  
  # Respond to GET requests at the "/bye" route
  httpGET(path = "/bye", function(req, res, err) {
    print("Farewell, my friends.")
  }) %>% 
  
  # Start the server on port 25118
  listen(host = "127.0.0.1", port = 25118)