Check Script and Function Names in a Package Directory
checkPkg_scrpt_fnctn_names.RdThis is a convenience function that helps encourage package development by performing an automated check to ensure that script names match the function names contained within them. It also counts the number of functions in each script and returns a table listing the scripts, the functions inside each script, whether the script name matches any function name, and if there are multiple functions in the script.
Value
A data frame with the following columns:
- multiple_functions
Logical, indicating if there are multiple functions in the script.
- number_functions
Integer, the number of functions in the script.
- name_match
Logical, indicating if the script name matches any function name inside it.
- script_name
Character, the name of the script without the ".R" extension.
- function_names
Character, the names of the functions found inside the script.
Examples
if (FALSE) { # \dontrun{
# Load necessary libraries
library(purrr)
library(dplyr)
library(stringr)
# Function to create temporary R scripts with matching function names
create_temp_scripts <- function(directory) {
for (i in 1:3) {
script_name <- file.path(directory, paste0("function", i, ".R"))
function_name <- paste0("function", i)
function_code <- paste0(function_name, " <- function() {\n # Placeholder function\n}\n")
writeLines(function_code, script_name)
}
}
# Create a temporary directory
temp_dir <- tempdir()
temp_sub_dir <- file.path(temp_dir, "temporary_directory_one")
dir.create(temp_sub_dir)
# Create temporary R scripts with matching function names
create_temp_scripts(temp_sub_dir)
# Check the script and function names using the provided function
result <- checkPkg_scrpt_fnctn_names(temp_sub_dir)
# Print the result
print(result)
} # }