Skip to content

Script to help with specifications

Tim Treis edited this page Jul 8, 2021 · 4 revisions

Since some of the test files are slowly becoming quite large and therefore hard to navigate, here is a script that scrapes the code and automatically outputs the order of specifications as found in the text. It does not have dependencies beyond base R.

Script: https://gist.github.com/timtreis/06935400580779c5a2cc731c6db0aaae

Usage:

Rscript ./spec_helper.R ./visR/tests/testthat/test-visr_plot.R

Output:

#' T1. visR::visr() only accepts `survfit` or `attrition`.
#' T1.1 No error when applied to a `survfit` object.
#' T1.2 No error when applied to a `attrition` object.
#' T1.3 An error when applied to an object that is not `survfit` or `attrition`.
#' T2. Invalid parameters are captured when applying `visR::visr()` to a `survfit` object and respective warnings/errors are thrown.
#' T2.1 No error when `x_label` is `NULL`, a `character` string or an `expression`.
#' T2.2 No error when `y_label` is `NULL`, a `character` string or an `expression`.
#' T2.3 No error when `x_units` is `NULL` or a `character` string.
#' T2.4 No error when `x_ticks` is `NULL` or a `numeric` value.
#' T2.5 No error when `y_ticks` is `NULL` or a `numeric` value.
#' T2.6 No error when a valid option is passed to `legend_position`.
#' T2.7 An error when `x_label` is not `NULL`, a `character` string or an `expression`.
#' T2.8 No warning when `x_label` is `NULL` and the `survfit` object has a `PARAM` and a `PARAMCD` column.
#' T2.9 No warning when `x_label` is `NULL` and the `survfit` object has a `PARAM` but no `PARAMCD` column.
#' T2.10 No warning when `x_label` is `NULL` and the `survfit` object has no `PARAM` but a `PARAMCD` column.
#' T2.11 A warning when `x_label` is `NULL` and the `survfit` object has no `PARAM` and no `PARAMCD` column.
#' T2.12 When `x_label` is `NULL` and the `survfit` object does have a `PARAM` column, the `x_label` is set to `PARAM`.
#' T2.13 When `x_label` is `NULL` and the `survfit` object does not have a `PARAM` but a `PARAMCD` column, the `x_label` is set to `PARAMCD`.
#' T2.14 When `x_label` is `NULL` and the `survfit` object does have a `PARAM` but no `PARAMCD` column, the `x_label` is set to `PARAM`.
#' T2.15 When `x_label` is `NULL` and the `survfit` object does not have a `PARAM` or `PARAMCD` column, the `x_label` is `NULL`.
#' T2.16 An error when `y_label` is not `NULL`, a `character` string or an `expression`.
#' T2.17 An error when `x_units` is not `NULL` or a `character` string.
#' T2.18 An error when `x_ticks` is not `NULL` or a `numeric`.
#' T2.19 An error when `y_ticks` is not `NULL` or a `numeric`.
#' T2.20 No error when a valid option is passed to `legend_position`.
#' T2.21 An error when the string is not amongst the valid options for `legend_position`.
#' T2.22 An error when an undefined option is passed to `legend_position`.
#' T3. The y-axis properties are correctly deducted from the provided `fun` when applying `visR::visr()` to a `survfit` object.
#' T3.1 No error when `y_label` is `NULL` and `fun` is one of the valid string options.
#' T3.2 An error when `y_label` is `NULL`, `fun` is a string but not one of the valid options.
#' T3.3 No error when `y_label` is a string and `fun` is a function.
#' T3.4 An error when `y_label` is `NULL` and `fun` is a function.
#' T3.5 A warning when the provided function causes undefined values, f.e. log(-log(2)).
#' T3.6 An error when `fun` is neither a `character` string nor a function.
#' T4. Invalid parameters are captured when applying `visR::visr()` to an `attrition` object and respective warnings/errors are thrown.
#' T4.1 No error when `description_column_name` is a `character` string that is found in the colnames of the `attrition` object.
#' T4.2 No error when `value_column_name` is a `character` string that is found in the colnames of the `attrition` object.
#' T4.3 No error when `complement_column_name` is a `character` string that is found in the colnames of the `attrition` object.
#' T4.4 No error when `box_width` is a `numeric` value.
#' T4.5 No error when `font_size` is a `numeric` value.
#' T4.6 No error when `fill` is a `character` string that is a valid colour.
#' T4.7 No error when `border` is a `character` string that is a valid colour.
#' T4.8 An error when `description_column_name` is a `character` string but is not found in the colnames of the `attrition` object.
#' T4.9 An error when `description_column_name` is not `character` string.
#' T4.10 An error when `value_column_name` is a `character` string but is not found in the colnames of the `attrition` object.
#' T4.11 An error when `value_column_name` is not `character` string.
#' T4.12 An error when `complement_column_name` is a `character` string but is not found in the colnames of the `attrition` object.
#' T4.13 An error when `complement_column_name` is not `character` string.
#' T4.14 A warning when `box_width` is not a `numeric` value.
#' T4.15 A warning when `font_size` is not a `numeric` value.
#' T4.16 An error when `fill` is a `character` string but not a valid colour.
#' T4.17 An error when `fill` is not a `character` string.
#' T4.18 An error when `border` is a `character` string but not a valid colour.
#' T4.19 An error when `border` is not a `character` string.