Let's try and find out what parameters are undocumented in my package QualtricsTools.

This uses some internals (such as parse_rd and .Rd_get_argument_names) from the tools package with the .Rd files generated by Roxygen with the args function to get arguments of functions loaded from the QualtricsTools in order to approximately tell which parameters are undocumented in the package.

The script below seems to be prone to false-positives where the documentation for a parameter does exist but the script lists the parameter as undocumented because the .Rd file is formatted unexpectedly or differently from usual. The documentation for some of these functions both exists and seems to render these false-positive parameters just fine, so this script is, for the moment, just a good way of finding what are likely candidates to be undocumented parameters.

References

setwd("Q:/Student Work/Emma's Student Work/Report Generation/QualtricsTools/")
devtools::load_all(".")
library(tools)

# List the Rd files from the QualtricsTools/man/ directory.
# Get just the filename from each full file-path.
# Then remove ".Rd" from the end.
documentation_files <- list.files(file.path(path.package("QualtricsTools"), "man"), full.names = TRUE)
documentation_files_basename <- lapply(documentation_files, basename)
documentation_files_without_rd <- lapply(documentation_files_basename, function(x) gsub("*.Rd", "", x))

# Get the function names in the QualtricsTools package.
function_names <- lsf.str(env=as.environment("package:QualtricsTools"))

# Save messages output in this script into a list.
output_messages <- list()

# For each function in QualtricsTools...
for (function_name in function_names) {
  # Check which documentation files match.
  corresponding_doc_file <- which(documentation_files_without_rd == function_name)
  # If there are none, print that there are no documentation files for that function.
  if (length(corresponding_doc_file) == 0) {
    output_list <- c(output_messages, paste0("There is no documentation file for ", function_name))
  } else {
    # If there is a matching documentation file, check the first for its documented arguments
    # and compare with the function's arguments.
    corresponding_doc_file <- documentation_files[[corresponding_doc_file[[1]]]]
    documentation <- tools::parse_Rd(corresponding_doc_file)
    argument_names_from_documentation <- tools:::.Rd_get_argument_names(documentation)
    argument_names_from_function <- Filter(function(x) x != "", names(as.list(args(function_name))))
    undocumented_parameters <- which(! argument_names_from_function %in% argument_names_from_documentation)
    if (length(undocumented_parameters) > 0) {
      output_messages <- c(
        output_messages,
        paste0(c(
          function_name,
          " has the following undocumented parameters: \n",
          paste0(argument_names_from_function[undocumented_parameters],
                 collapse = "\n"),
          "\n\n"
        ), collapse = ""))
    }
  }
}

# Output to a temporary file
output_file <- tempfile()
write(x = paste0(output_messages, collapse="\n"), file = output_file)

# And open the temporary file in Rstudio
# file.edit(output_file)
shiny::includeMarkdown(output_file)


ctesta01/QualtricsTools documentation built on May 14, 2019, 12:27 p.m.