From 8a46862ecb7cc52079f05dc5aa6ae7bf75c2bfbf Mon Sep 17 00:00:00 2001 From: Sophie Shapcott Date: Sun, 18 Feb 2024 15:27:20 +0000 Subject: [PATCH] #164 - Changes due to devtools::check() and devtools::document(). --- R/format.R | 30 ++++++++++----------- man/metadata.Rd | 2 +- man/xportr-package.Rd | 3 ++- man/xportr_df_label.Rd | 2 +- man/xportr_format.Rd | 59 +++++++++++++++++++++++++++++++++++++++++- 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 +- 10 files changed, 82 insertions(+), 24 deletions(-) diff --git a/R/format.R b/R/format.R index e27049d4..d067623c 100644 --- a/R/format.R +++ b/R/format.R @@ -229,18 +229,18 @@ xportr_format <- function(.df, # character variable formats should start with a $ if (grepl("^\\$", format_sas) == FALSE) { message <- glue( - "(xportr::xportr_format) - {encode_vars(colnames(.df)[i])} is a character variable and - should have a `$` prefix." + "(xportr::xportr_format)", + " {encode_vars(colnames(.df)[i])} is a character variable", + " and should have a `$` prefix." ) xportr_logger(message, type = "warn") } # character variable formats should have length <= 31 (excluding the $) if (nchar(gsub(".$", "", format_sas)) > 32) { message <- glue( - "(xportr::xportr_format) - Format for character variable {encode_vars(colnames(.df)[i])} - should have length <= 31 (excluding `$`)." + "(xportr::xportr_format)", + " Format for character variable {encode_vars(colnames(.df)[i])}", + " should have length <= 31 (excluding `$`)." ) xportr_logger(message, type = "warn") } @@ -251,18 +251,18 @@ xportr_format <- function(.df, # numeric variables should not start with a $ if (grepl("^\\$", format_sas) == TRUE) { message <- glue( - "(xportr::xportr_format) - {encode_vars(colnames(.df)[i])} is a numeric variable - and should not have a `$` prefix." + "(xportr::xportr_format)", + " {encode_vars(colnames(.df)[i])} is a numeric variable and", + " should not have a `$` prefix." ) xportr_logger(message, type = "warn") } # numeric variable formats should have length <= 32 if (nchar(gsub(".$", "", format_sas)) > 32) { message <- glue( - "(xportr::xportr_format) - Format for numeric variable {encode_vars(colnames(.df)[i])} - should have length <= 32." + "(xportr::xportr_format)", + " Format for numeric variable {encode_vars(colnames(.df)[i])}", + " should have length <= 32." ) xportr_logger(message, type = "warn") } @@ -273,9 +273,9 @@ xportr_format <- function(.df, !(format_sas %in% toupper(expected_formats)) && (stringr::str_detect(format_sas, pattern = format_regex) == FALSE)) { message <- glue( - "(xportr::xportr_format) - Check format {encode_vars(format_sas)} for variable {encode_vars(colnames(.df)[i])} - - is this correct?" + "(xportr::xportr_format)", + " Check format {encode_vars(format_sas)} for variable {encode_vars(colnames(.df)[i])}", + " - is this correct?" ) xportr_logger(message, type = "message") } diff --git a/man/metadata.Rd b/man/metadata.Rd index 9df1c6c8..30918a0c 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 CDISC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDSIC 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-package.Rd b/man/xportr-package.Rd index 2f38a255..bcd0521d 100644 --- a/man/xportr-package.Rd +++ b/man/xportr-package.Rd @@ -85,7 +85,8 @@ coerce R classes to numeric XPT types. Default: c("integer", "numeric", "num", " } \item{ xportr.numeric_types - The default character vector used to explicitly -coerce R classes to numeric XPT types. Default: c("integer", "float", "numeric", "posixct", "posixt", "time", "date") +coerce R classes to numeric XPT types. Default: c("integer", "float", +"numeric", "posixct", "posixt", "time", "date") } } } diff --git a/man/xportr_df_label.Rd b/man/xportr_df_label.Rd index 5f95d771..691de990 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 CDISC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDSIC 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 0c00da1b..fcee3db1 100644 --- a/man/xportr_format.Rd +++ b/man/xportr_format.Rd @@ -12,7 +12,7 @@ xportr_format(.df, metadata = NULL, domain = NULL, metacore = deprecated()) \item{metadata}{A data frame containing variable level metadata. See 'Metadata' section for details.} -\item{domain}{Appropriate CDISC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDSIC 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.} @@ -27,6 +27,63 @@ Assigns a SAS format from a variable level metadata to a given data frame. If no format is found for a given variable, it is set as an empty character vector. This is stored in the '\code{format.sas}' attribute. } +\section{Format Checks}{ + This function carries out a series of basic +checks to ensure the formats being applied make sense. +\enumerate{ +\item If the variable has a suffix of \code{DT}, \code{DTM}, \code{TM} (indicating a +numeric date/time variable) then a warning will be shown if there is +no format associated with it. +\item If a variable is character then a warning will be shown if there is +no \code{$} prefix in the associated format. +\item If a variable is character then a warning will be shown if the +associated format has greater than 31 characters (excluding the \code{$}). +\item If a variable is numeric then a warning will be shown if there is a +\code{$} prefix in the associated format. +\item If a variable is numeric then a warning will be shown if the +associated format has greater than 32 characters. +\item All formats will be checked against a list of formats considered +'standard' as part of an ADaM dataset. Note, however, this list is not +exhaustive (it would not be feasible to check all the functions +within the scope of this package). If the format is not found in the +'standard' list, then a message is created advising the user to +check. +} + +|-------------|------------|-----------|\tabular{lll}{ + Format Name \tab w Values \tab d Values \cr + w.d \tab 1 - 32 \tab ., 0 - 31 \cr + $w. \tab 1 - 200 \tab \cr + ------------- \tab ------------ \tab ----------- \cr + DATEw. \tab ., 5 - 11 \tab \cr + DATETIMEw. \tab 7 - 40 \tab \cr + DDMMYYw. \tab ., 2 - 10 \tab \cr + HHMM. \tab \tab \cr + MMDDYYw. \tab ., 2 - 10 \tab \cr + TIMEw. \tab ., 2 - 20 \tab \cr + WEEKDATEw. \tab ., 3 - 37 \tab \cr + YYMMDDw. \tab ., 2 - 10 \tab \cr + ------------- \tab ------------ \tab ----------- \cr + B8601DAw. \tab ., 8 - 10 \tab \cr + B8601DTw.d \tab ., 15 - 26 \tab ., 0 - 6 \cr + B8601TM. \tab \tab \cr + ------------- \tab ------------ \tab ----------- \cr + IS8601DA. \tab \tab \cr + IS8601TM. \tab \tab \cr + ------------- \tab ------------ \tab ----------- \cr + E8601DAw. \tab ., 10 \tab \cr + E8601DNw. \tab ., 10 \tab \cr + E8601DTw.d \tab ., 16 - 26 \tab ., 0 - 6 \cr + E8601DXw. \tab ., 20 - 35 \tab \cr + E8601LXw. \tab ., 20 - 35 \tab \cr + E8601LZw. \tab ., 9 - 20 \tab \cr + E8601TMw.d \tab ., 8 - 15 \tab ., 0 - 6 \cr + E8601TXw. \tab ., 9 - 20 \tab \cr + E8601TZw.d \tab ., 9 - 20 \tab ., 0 - 6 \cr + ------------- \tab ------------ \tab ----------- \cr +} +} + \section{Metadata}{ The argument passed in the 'metadata' argument can either be a metacore object, or a data.frame containing the data listed below. If diff --git a/man/xportr_label.Rd b/man/xportr_label.Rd index a61e0583..eb03df81 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 CDISC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDSIC 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 93425808..8d034eb8 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 CDISC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDSIC 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 03617d4f..26b87f42 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 CDISC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDSIC 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 05489fcf..736fe0c6 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 CDISC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDSIC 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 bde66844..c6bd4a1d 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 CDISC dataset name, e.g. ADAE, DM. Used to subset +\item{domain}{Appropriate CDSIC 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.}