Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #132 removing used SASlength from functions #216

Merged
merged 9 commits into from
Feb 5, 2024
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ done to make the use of xportr functions more explicit. (#182)
* The `label` argument from the `xportr_write()` function is deprecated in favor of the `metadata` argument. (#179)
* The `metacore` argument, which was renamed to `metadata` in the following six xportr functions: (`xportr_df_label()`, `xportr_format()`, `xportr_label()`, `xportr_length()`, `xportr_order()`, and `xportr_type()`) in version `0.3.0` with a soft deprecation warning, has now been hard deprecated. Please update your code to use the new `metadata` argument in place of `metacore`.

* `SASlength` and `SAStype` were removed since they did not have an impact on `xpt_validate` or any other functions (#132)

## Documentation

* Created development version of the website (#187)
Expand Down
2 changes: 1 addition & 1 deletion R/length.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#' the column. This is passed to `haven::write` to note the variable length.
#'
#'
#' @return Data frame with `SASlength` attributes for each variable.
#' @return Data frame with SAS default length attributes for each variable.
sadchla-codes marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @export
#'
Expand Down
24 changes: 3 additions & 21 deletions R/utils-xportr.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#' Extract Attribute From Data
#'
#' @param data Dataset to be exported as xpt file
#' @param attr SAS attributes such as label, format, type, length
#' @param attr SAS attributes such as label, format, type
#'
#' @return Character vector of attributes with column names assigned
#' @noRd
extract_attr <- function(data, attr = c("label", "format.sas", "SAStype", "SASlength")) {
extract_attr <- function(data, attr = c("label", "format.sas")) {
attr <- match.arg(attr)
out <- lapply(data, function(.x) attr(.x, attr))
out <- vapply(out,
Expand Down Expand Up @@ -216,26 +216,8 @@ xpt_validate <- function(data) {
)
}

# 3.0 VARIABLE TYPES ----
types <- tolower(extract_attr(data, attr = "SAStype"))

expected_types <- c(
"", "text", "integer", "float", "datetime", "date", "time",
"partialdate", "partialtime", "partialdatetime",
"incompletedatetime", "durationdatetime", "intervaldatetime"
)

# 3.1 Invalid types --
chk_types <- types[which(!types %in% expected_types)]

if (length(chk_types) > 0) {
err_cnd <- c(
err_cnd,
glue("{fmt_vars(names(types))} must have a valid type.")
)
}

# 4.0 Format Types ----
# 3.0 Format Types ----
formats <- extract_attr(data, attr = "format.sas")

## The usual expected formats in clinical trials: characters, dates
Expand Down
4 changes: 1 addition & 3 deletions R/write.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
#' @details
#' * Variable and dataset labels are stored in the "label" attribute.
#'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep the lines for the SAS length and replace 'SASlength' by 'width' :
#' * SAS length are stored in the "width" attribute.

#' * SAS length are stored in the "SASlength" attribute.
#'
#' * SAS format are stored in the "SASformat" attribute.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name for the SAS format attribute is 'format.sas'. Maybe we should also update 'SASformat' to 'format.sas', what do you think?

#'
#' * SAS type are stored in the "SAStype" attribute.
#' * SAS type are based on the `metadata` attribute.
#'
#' @return A data frame. `xportr_write()` returns the input data invisibly.
#' @export
Expand Down
2 changes: 0 additions & 2 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ PHUSE
Pharma
Repostiory
SASformat
SASlength
SAStype
SDSP
SDTM
Standardisation
Expand Down
2 changes: 1 addition & 1 deletion man/xportr_length.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/xportr_write.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-length.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Tests will check for:
#' * Errors
#' * Result of call will create `SASlength` attribute (`width` for each
#' * Result of call will create SAS default length attribute (`width` for each
#' variable)

test_that("xportr_length: Accepts valid domain names in metadata object", {
Expand Down
10 changes: 0 additions & 10 deletions tests/testthat/test-utils-xportr.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ test_that("xpt_validate: Get error message when the label contains over 40 chara
)
})

test_that("xpt_validate: Get error message when the variable type is invalid", {
df <- data.frame(A = 1, B = 2)
attr(df$A, "SAStype") <- "integer"
attr(df$B, "SAStype") <- "list"
expect_equal(
xpt_validate(df),
"Variables `A` and `B` must have a valid type."
)
})

test_that("xpt_validate: Doesn't error out with iso8601 format", {
df <- data.frame(A = 1, B = 2)
attr(df$A, "format.sas") <- "E8601LX."
Expand Down
Loading