Learn R Programming

MazamaCoreUtils (version 0.5.3)

lintFunctionArgs: Lint a source file's function arguments

Description

This function parses an R Script file, grouping function calls and the named arguments passed to those functions. Then, based on a set of rules, it is determined if functions of interest have specific named arguments specified.

Usage

lintFunctionArgs_file(filePath = NULL, rules = NULL, fullPath = FALSE)

lintFunctionArgs_dir(dirPath = "./R", rules = NULL, fullPath = FALSE)

Value

A tibble detailing the results of the lint.

Arguments

filePath

Path to a file, given as a length one character vector.

rules

A named list where the name of each element is a function name, and the value is a character vector of the named argument to check for. All arguments must be specified for a function to "pass".

fullPath

Logical specifying whether to display absolute paths.

dirPath

Path to a directory, given as a length one character vector.

Linting Output

The output of the function argument linter is a tibble with the following columns:

file_path

path to the source file

line_number

Line of the source file the function is on

column_number

Column of the source file the function starts at

function_name

The name of the function

named_args

A vector of the named arguments passed to the function

includes_required

True iff the function specifies all of the named arguments required by the given rules

Limitations

This function is only able to test for named arguments passed to a function. For example, it would report that foo(x = bar, "baz") has specified the named argument x, but not that bar was the value of the argument, or that "baz" had been passed as an unnamed argument.

Examples

Run this code
if (FALSE) {
library(MazamaCoreUtils)

# Example rule list for checking
exRules <- list(
  "fn_one" = "x",
  "fn_two" = c("foo", "bar")
)

# Example of using included timezone argument linter
lintFunctionArgs_file(
  "local_test/timezone_lint_test_script.R",
  MazamaCoreUtils::timezoneLintRules
)
}

Run the code above in your browser using DataLab