Skip to contents

check_blocks() checks the object blocks of a blocks file on 2 rules. It reports each rule as PASS, FAIL or SKIP, and it does not print or stop.

Usage

check_blocks(
  blocks,
  block_class = "writeit_block",
  require_block = TRUE,
  messages = writeit_messages()
)

Arguments

blocks

The object blocks of a blocks file.

block_class

The class of a block that block() declares. A package with its own block function passes its own class.

require_block

TRUE when each block MUST be of the class block_class. With FALSE, a block MAY be a plain function of the results object.

messages

The texts that name a function in a detail, a named list as writeit_messages() gives. The details use its element block.

Value

A data.frame with 2 rows, one for each rule, and the columns rule, status and detail. status is "PASS", "FAIL" or "SKIP".

Details

The 2 rules, in the order of the rows:

  • blocks_list: blocks is a list with 1 or more elements. Each element has a name that is not NA and not empty, and no name is there twice. Each element is a function or an object of the class block_class. NULL gives FAIL. The detail names each fault.

  • block_class: with require_block = TRUE, each element is of the class block_class, and the detail names each element that is not. With require_block = FALSE, the rule gives PASS and says that plain functions are allowed. With require_block = TRUE, it gives SKIP when blocks is not a list with 1 or more elements.

A detail names an element by its name, or as element <i> when its name is NA or empty.

Examples

blocks <- list(
  estimates = block(function(results) return(results$estimates), "ci"),
  counts = function(results) return(results$counts)
)
check_blocks(blocks)
#>          rule status
#> 1 blocks_list   PASS
#> 2 block_class   FAIL
#>                                                                                                          detail
#> 1                                                     blocks is a list of 2 blocks, each with a name of its own
#> 2 these elements of blocks are not of the class writeit_block: counts. Declare each block with writeit::block()
check_blocks(blocks, require_block = FALSE)
#>          rule status
#> 1 blocks_list   PASS
#> 2 block_class   PASS
#>                                                             detail
#> 1        blocks is a list of 2 blocks, each with a name of its own
#> 2 require_block is FALSE, so plain functions are allowed as blocks