messageGenerator: Produce a message for the output of a checkFunction

Description Usage Arguments Details Value See Also Examples

View source: R/messageGenerator.R

Description

Helper function for producing output messages for checkFunction type functions.

Usage

1
2
3
4
5
messageGenerator(
  problemStatus,
  message = "Note that a check function found the following problematic values:",
  nMax = 10
)

Arguments

problemStatus

A list consisting of two entries:

$problem - logical indicating whether a problem was found by the checkFunction responsible for the making the messageGenerator() call,

$problemValues - a vector of values from the variable that were deemed problematic (see details below).

message

Optional, but recommended. A message describing what problem the problem values are related to. If NULL a standard message is added using the name of the function that called messageGenerator.

nMax

Maximum number of problem values to be printed in the message. If the total number of problem values exceeds nMax, the number of omitted problem values are added to the message. Defaults to Inf, in which case all problem values are printed.

Details

This function is a tool for building checkFunctions for the dataMaid makeDataReport function. checkFunctions will often identify a number of values in a variable that are somehow problematic. messageGenerator takes these values, pastes them together with a problem description and makes sure that the formatting is appropriate for being rendered in a rmarkdown document. We recommend writing short and precise problem descriptions (see examples), but if no message is supplied, the following message is generated: "Note that a check function found the following problematic values: [problem values]".

Value

A character string with a problem description.

See Also

check, checkFunction, makeDataReport

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#Varibales with/without underscores
 noUSVar <- c(1:10)
 USVar <- c("_a", "n_b", "b_", "_", 1:10)

#Define a checkFunction using messageGenerator with a manual
#problem description:
identifyUnderscores <- function(v, nMax = Inf) {
  v <- as.character(v)
  underscorePlaces <- regexpr("_", v) > 0
  problemValues <- unique(v[underscorePlaces])
  problem <- any(underscorePlaces)
  message <- messageGenerator(list(problemValues = problemValues, problem = problem),
                              "The following values contain underscores:",
                              nMax = nMax)
  checkResult(list(problem = problem, message = message,
      problemValues = problemValues))
 }

 identifyUnderscores(noUSVar) #no problem
 identifyUnderscores(USVar) #problems
 
#Only print the first two problemvalues in the message:
 identifyUnderscores(USVar, nMax = 2)

#Define same function, but without a manual problem description in
#the messageGenerator-call:
 identifyUnderscores2 <- function(v, nMax = Inf) {
  v <- as.character(v)
  underscorePlaces <- regexpr("_", v) > 0
  problemValues <- unique(v[underscorePlaces])
  problem <- any(underscorePlaces)
  message <- messageGenerator(list(problemValues = problemValues,
                                   problem = problem), nMax = nMax)
  checkResult(list(problem = problem, message = message,
      problemValues = problemValues))
 }

 identifyUnderscores2(noUSVar) #no problem
 identifyUnderscores2(USVar) #problems

dataMaid documentation built on Oct. 8, 2021, 9:08 a.m.