function_checks {cleanr}R Documentation

Function Checks

Description

A set of tiny functions to check that functions adhere to a layout style. A function should have a clear layout, it should

Usage

check_num_arguments(object, max_num_arguments = gco("max_num_arguments"))

check_nesting_depth(object, max_nesting_depth = gco("max_nesting_depth"))

check_num_lines(object, max_lines = gco("max_lines"))

check_num_lines_of_code(object, max_lines_of_code = gco("max_lines_of_code"))

check_line_width(object, max_line_width = gco("max_line_width"))

check_return(object, check_return = gco("check_return"))

Arguments

object

The function to be checked. Should have been sourced with keep.source = TRUE (see get_function_body).

max_num_arguments

The maximum number of arguments accepted. Set (preferably via set_cleanr_options) to NULL or FALSE to disable the check.

max_nesting_depth

The maximum nesting depth accepted. Set (preferably via set_cleanr_options) to NULL or FALSE to disable the check.

max_lines

The maximum number of lines accepted. Set (preferably via set_cleanr_options) to NULL or FALSE to disable the check.

max_lines_of_code

The maximum number of lines of code accepted. Set (preferably via set_cleanr_options) to NULL or FALSE to disable the check.

max_line_width

The maximum line width accepted. Set (preferably via set_cleanr_options) to NULL or FALSE to disable the check.

check_return

Set (preferably via set_cleanr_options) to NULL or FALSE to disable the check.

Details

In case of a fail all function_checks throw a condition of class c("cleanr", "error", "condition").

Value

Invisibly TRUE, but see Details.

Warning

check_return just greps for a for a line starting with a return statement (ah, see the code for the real thing). This does not ensure that all return paths from the function are explicit and it may miss a return path after a semicolon. It just checks if you use return at all.

See Also

Other check functions: file_checks

Examples

print(cleanr::check_num_arguments(cleanr::check_num_arguments))
print(cleanr::check_nesting_depth(cleanr::check_nesting_depth))
print(cleanr::check_num_lines(cleanr::check_num_lines))
print(cleanr::check_num_lines_of_code(cleanr::check_num_lines_of_code))
print(cleanr::check_return(cleanr::check_return))
# R reformats functions on import (see
# help(get_function_body, package = "cleanr")), so we need 90 characters:
print(cleanr::check_line_width(cleanr::check_line_width,
                               max_line_width = 90))

[Package cleanr version 1.4.0 Index]