From b247ba31bce26a4034f860685514d0a8b920beca Mon Sep 17 00:00:00 2001 From: sadchla-codes Date: Wed, 6 Mar 2024 02:25:20 -0500 Subject: [PATCH] updating documentations --- R/addin_format_testthat.R | 107 -------------------------------------- man/metadata.Rd | 2 +- man/xportr_df_label.Rd | 2 +- man/xportr_format.Rd | 2 +- man/xportr_label.Rd | 2 +- man/xportr_length.Rd | 2 +- man/xportr_order.Rd | 2 +- man/xportr_type.Rd | 2 +- man/xportr_write.Rd | 2 +- 9 files changed, 8 insertions(+), 115 deletions(-) delete mode 100644 R/addin_format_testthat.R diff --git a/R/addin_format_testthat.R b/R/addin_format_testthat.R deleted file mode 100644 index df6c5b0a..00000000 --- a/R/addin_format_testthat.R +++ /dev/null @@ -1,107 +0,0 @@ -# Returns the call for updating a given test_that test file -# by adding a function name, a test number, and a section. -# Call the function either by using RStudio Addin "format_test_that_file" or -# programmatically in a for loop on the test files and running -# rstudioapi::navigateToFile and format_test_that_file -prepare_test_that_file <- function(path) { - assert_character_scalar(path) - - # check that file exists - if (!file.exists(path)) { - stop("Invalid file path, the file does not exist.") - } - - # check that testthat is used and testing file is opened - uses_test_file <- grepl("tests/testthat/test-", path, fixed = TRUE) - if (!uses_test_file) { - stop("This Addin works only on unit test files that follow a testthat structure.") - } - - # parse the name of the testing function - testing_file <- sub("^test-", "", sub(".R$", "", basename(path))) - - # get file content - file_content <- readLines(path) - - # get locations of tests - match 'test_that("' strings - test_that_loc <- grep('^test_that\\("', file_content) - - if (length(test_that_loc) == 0) { - return(invisible(NULL)) - } - - #### - ## HANDLE test_that DESCRIPTIONS - #### - - # get and parse test descriptions - test_that_lines <- file_content[test_that_loc] - test_that_desc_parsed <- stringr::str_extract( - string = test_that_lines, - pattern = paste0( - '(?<=test_that\\(")', # positive look-ahead - search matching expression after test_that(" - ".*", # matching expression - match everything - '(?=")' # positive look-behind - search matching expression before " - ) - ) - test_that_desc_cleaned <- stringr::str_remove( - string = test_that_desc_parsed, - pattern = paste0("([\\w\\.]+,? )?[Tt]est \\d{1,} ?: ") - ) - - # determine name of function which is tested - # the function name can be specified by # function_name ---- comments - function_name <- str_match(file_content, "# ([\\w\\.]+) ----")[, 2] - if (is.na(function_name[1])) { - function_name[1] <- testing_file - } - function_name <- tidyr::fill(data.frame(name = function_name), name)$name - function_name <- function_name[test_that_loc] - - # formulate new test descriptions (update only those that don't include test_title) - new_desc <- paste0( - "Test ", seq_along(test_that_loc), ": ", - test_that_desc_cleaned - ) - - # insert new test descriptions into test_that lines - test_that_lines_updated <- stringr::str_replace( - string = test_that_lines, - pattern = '(?<=test_that\\(").*"', - replacement = paste0(function_name, " ", new_desc, '"') - ) - - # modify the file content - file_content[test_that_loc] <- test_that_lines_updated - - #### - ## HANDLE HEADERS - #### - - # formulate headers according to RStudio editor functionality - headers <- paste0("## ", new_desc, " ----") - - # get locations of headers created by this function - header_loc_lgl <- grepl(paste0("^##?( ----)?( \\w+)?,? [tT]est \\d{1,} ?: "), file_content) - - # remove those headers - file_content <- file_content[!header_loc_lgl] - - # add new headers just before test_that calls - header_loc <- grep('^test_that\\("', file_content) + seq_along(headers) - 1 - file_content_new <- vector(mode = "character", length = length(file_content) + length(headers)) - file_content_new[header_loc] <- headers - file_content_new[-header_loc] <- file_content - - list(file_content = file_content_new) -} - -# Function for the RStudio Addin, see inst/rstudio/addins.dcf. -# Wrapper of prepare_test_that_file. -format_test_that_file <- function() { - file_info <- rstudioapi::getActiveDocumentContext() - rstudioapi::documentSave(id = file_info$id) - result <- prepare_test_that_file(path = file_info$path) - rstudioapi::setDocumentContents(paste0(result$file_content, collapse = "\n"), id = file_info$id) - rstudioapi::documentSave(id = file_info$id) -} diff --git a/man/metadata.Rd b/man/metadata.Rd index 01942fa0..cd286905 100644 --- a/man/metadata.Rd +++ b/man/metadata.Rd @@ -12,7 +12,7 @@ xportr_metadata(.df, metadata = NULL, domain = NULL, verbose = NULL) \item{metadata}{A data frame containing variable level metadata. See 'Metadata' section for details.} -\item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDISC dataset name, e.g. ADAE, DM. Used to subset the metadata object. If none is passed, then name of the dataset passed as .df will be used.} diff --git a/man/xportr_df_label.Rd b/man/xportr_df_label.Rd index 691de990..5f95d771 100644 --- a/man/xportr_df_label.Rd +++ b/man/xportr_df_label.Rd @@ -12,7 +12,7 @@ xportr_df_label(.df, metadata = NULL, domain = NULL, metacore = deprecated()) \item{metadata}{A data frame containing dataset. See 'Metadata' section for details.} -\item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDISC dataset name, e.g. ADAE, DM. Used to subset the metadata object. If none is passed, then name of the dataset passed as .df will be used.} diff --git a/man/xportr_format.Rd b/man/xportr_format.Rd index c1e1fe16..e45f66dc 100644 --- a/man/xportr_format.Rd +++ b/man/xportr_format.Rd @@ -18,7 +18,7 @@ xportr_format( \item{metadata}{A data frame containing variable level metadata. See 'Metadata' section for details.} -\item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDISC dataset name, e.g. ADAE, DM. Used to subset the metadata object. If none is passed, then name of the dataset passed as .df will be used.} diff --git a/man/xportr_label.Rd b/man/xportr_label.Rd index eb03df81..a61e0583 100644 --- a/man/xportr_label.Rd +++ b/man/xportr_label.Rd @@ -18,7 +18,7 @@ xportr_label( \item{metadata}{A data frame containing variable level metadata. See 'Metadata' section for details.} -\item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDISC dataset name, e.g. ADAE, DM. Used to subset the metadata object. If none is passed, then name of the dataset passed as .df will be used.} diff --git a/man/xportr_length.Rd b/man/xportr_length.Rd index a2c2e01e..c3180a71 100644 --- a/man/xportr_length.Rd +++ b/man/xportr_length.Rd @@ -19,7 +19,7 @@ xportr_length( \item{metadata}{A data frame containing variable level metadata. See 'Metadata' section for details.} -\item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDISC dataset name, e.g. ADAE, DM. Used to subset the metadata object. If none is passed, then name of the dataset passed as .df will be used.} diff --git a/man/xportr_order.Rd b/man/xportr_order.Rd index 26b87f42..03617d4f 100644 --- a/man/xportr_order.Rd +++ b/man/xportr_order.Rd @@ -18,7 +18,7 @@ xportr_order( \item{metadata}{A data frame containing variable level metadata. See 'Metadata' section for details.} -\item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDISC dataset name, e.g. ADAE, DM. Used to subset the metadata object. If none is passed, then name of the dataset passed as .df will be used.} diff --git a/man/xportr_type.Rd b/man/xportr_type.Rd index 736fe0c6..05489fcf 100644 --- a/man/xportr_type.Rd +++ b/man/xportr_type.Rd @@ -18,7 +18,7 @@ xportr_type( \item{metadata}{A data frame containing variable level metadata. See 'Metadata' section for details.} -\item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDISC dataset name, e.g. ADAE, DM. Used to subset the metadata object. If none is passed, then name of the dataset passed as .df will be used.} diff --git a/man/xportr_write.Rd b/man/xportr_write.Rd index c6bd4a1d..bde66844 100644 --- a/man/xportr_write.Rd +++ b/man/xportr_write.Rd @@ -22,7 +22,7 @@ used as \code{xpt} name.} \item{metadata}{A data frame containing dataset. See 'Metadata' section for details.} -\item{domain}{Appropriate CDSIC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDISC dataset name, e.g. ADAE, DM. Used to subset the metadata object. If none is passed, then name of the dataset passed as .df will be used.}