All Projects → rich-iannone → messaging

rich-iannone / messaging

Licence: other
Conveniently issue messages, warnings, and errors

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to messaging

catchr
catchr: Flexible, useful tools for dealing with conditions in R, for new users and veterans
Stars: ✭ 17 (+41.67%)
Mutual labels:  messages, warnings
Reattempt
🤞 Give your functions another chance
Stars: ✭ 570 (+4650%)
Mutual labels:  errors, functions
linbaser
The program on a given grid from a file builds an approximation of the function by a piecewise linear basis. Made mostly in Russian, because of university subject.
Stars: ✭ 10 (-16.67%)
Mutual labels:  functions
failure
An error handling package for Go.
Stars: ✭ 24 (+100%)
Mutual labels:  errors
functions-recipes
Functions Recipes is a library of examples to help you getting started with Salesforce Functions and get used to their main features.
Stars: ✭ 150 (+1150%)
Mutual labels:  functions
openwhisk-runtime-go
Apache OpenWhisk Runtime Go supports Apache OpenWhisk functions written in Go
Stars: ✭ 31 (+158.33%)
Mutual labels:  functions
openfaas-rstats-templates
OpenFaaS templates for R
Stars: ✭ 17 (+41.67%)
Mutual labels:  functions
eth-rpc-errors
Ethereum RPC Errors
Stars: ✭ 78 (+550%)
Mutual labels:  errors
gcf-packs
Library packs for google cloud functions
Stars: ✭ 48 (+300%)
Mutual labels:  functions
ftrace
Simple Function calls tracer
Stars: ✭ 65 (+441.67%)
Mutual labels:  functions
effepi
Fun functional programming with pipelinable functions
Stars: ✭ 13 (+8.33%)
Mutual labels:  functions
safe
🛡 PHP functions smarten up to throw exceptions instead of returning false or triggering errors.
Stars: ✭ 15 (+25%)
Mutual labels:  errors
vcore
Common, utility packages for Go
Stars: ✭ 16 (+33.33%)
Mutual labels:  errors
fqn-check
Checks source trees for not fully qualified function calls.
Stars: ✭ 15 (+25%)
Mutual labels:  functions
C-Complete-practice
This repository will contains C programs from beginners to advance level
Stars: ✭ 59 (+391.67%)
Mutual labels:  functions
rudash
Rudash - Lodash for Ruby Apps
Stars: ✭ 27 (+125%)
Mutual labels:  functions
sequence-as-promise
Executes array of functions as sequence and returns promise
Stars: ✭ 23 (+91.67%)
Mutual labels:  functions
sendmessage
SendMessage is a little tool to send Windows messages to any window.
Stars: ✭ 93 (+675%)
Mutual labels:  messages
openwhisk-runtime-python
Apache OpenWhisk Runtime Python supports Apache OpenWhisk functions written in Python
Stars: ✭ 39 (+225%)
Mutual labels:  functions
extract-react-intl
Extract react-intl messages
Stars: ✭ 18 (+50%)
Mutual labels:  messages

Travis build status Coverage status CRAN status

The messaging Package

The goal of messaging is to provide a toolset for creating and issuing nicely-formatted text within R diagnostic messages and those messages given during warnings and errors. The formatting of the messages can be customized using templating features. Issues with singular and plural forms can be handled through specialized syntax.

Example for Emitting Messages

For for the purpose of demonstrating how messaging can help you format and issue messages, we can create a function (yield_a_message()) that uses the emit_message() function for the sole purpose of displaying a message.

library(messaging)

yield_a_message <- function() {
  
  # This function's only aim is to produce
  # a message; throughout the function body, we
  # can generate objects that can be assembled
  # into a customizable message with `emit_message()`
  
  # Create some strings can serve as additional
  # info for the message 
  important_message_parts <- 
    c("* message info part 1",
      "* message info part 2",
      "* message info part 3")
  
  # Get a numeric value to use in the message
  n_info_lines <- length(important_message_parts)
  
  # Generate and emit a formatted message
  emit_message(
    "There (is/are) {number} thing(s) to note", # on line 1; singular/plural syntax
    important_message_parts, # 3 additional lines (all lines are separated with `/n`)
    number = n_info_lines, # a named argument; `n_info_lines` inserted into {number}
    .format = "{.f_name} info: {text}") # an optional template
}

Within the main function body, there’s the creation of character (important_message_parts) and numeric (number_of_info_lines) values that will help us compose our message. This combination of function-scope objects will work alongside templated expression strings in the emit_message() function. Multiple expression strings can be provided to emit_message() to serve as components of the message (newlines will separate each of the expressions provided).

Using curly braces, we can enable text interpolation (e.g., The number is {number} and this is considered {level}) where named arguments (e.g., number = 3, level = "high", etc.) provide the values for the message components.

If there is interpolation of numerical values, there is also the option to provide singular and plural forms for words associated with the the values. Simply enclose the singular and plural alternatives in parentheses and the function will finalize the statement based on the associated numerical values. Some syntax examples are: (is/are), analys(is/es), result(s).

Upon calling yield_a_message() we see that a message does appear and that the text on the first line has been processed such that it’s grammatically correct.

# Call the `yield_a_message()` function
yield_a_message()
#> `yield_a_message()` info: There are 3 things to note
#> * message info part 1
#> * message info part 2
#> * message info part 3

We can also emit warnings and errors by using the emit_warning() and emit_error() functions within those functions of our own design. Here’s a function that might provide a warning (if the sum of x and y is greater than 100):

might_warn_you <- function(x, y) {
  
  sum_xy <- x + y

  if (sum_xy > 100) {
    emit_warning(
      "This value ({sum_xy}) is greater than 100.",
      sum_xy = sum_xy)
  }
  
  return(sum_xy)
}

This won’t warn:

might_warn_you(40, 50)
#> [1] 90

This warns and provides the custom warning.

might_warn_you(60, 50)
#> Warning: `might_warn_you()`: This value (110) is greater than 100.
#> [1] 110

We can exit a function early with a message using the emit_error() function:

will_stop_if_not_careful <- function(x, y) {
  
  sum_xy <- x + y

  if (sum_xy > 100) {
    emit_error(
      "This value ({sum_xy}) is greater than 100. That is bad.",
      sum_xy = sum_xy)
  }
  
  return(sum_xy)
}

This function call will stop the function:

will_stop_if_not_careful(60, 50)

Here is a reproduction of the error message:

Error: `will_stop_if_not_careful()`: This value (110) is greater than 100. That is bad.

Installation of the package

messaging is used in an R environment. If you don’t have an R installation, it can be obtained from the Comprehensive R Archive Network (CRAN).

You can install messaging from CRAN with install.packages().

install.packages("messaging")

Also, the development version of messaging from GitHub can be installed using the devtools package.

devtools::install_github("rich-iannone/messaging")

If you encounter a bug, have usage questions, or want to share ideas to make this package better, feel free to file an issue.

Code of Conduct

Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

License

MIT © Richard Iannone

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].