Skip to content

Commit

Permalink
Fixing lintr indentations issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sadchla-codes committed Mar 8, 2024
1 parent e81fda8 commit 5e9e189
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 128 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ Imports:
readr,
rlang (>= 0.4.10),
stringr (>= 1.4.0),
tidyselect
tidyselect,
readxl
Suggests:
DT,
knitr,
labelled,
metacore,
readxl,
rmarkdown,
testthat (>= 3.0.0),
withr
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ importFrom(dplyr,ungroup)
importFrom(glue,glue)
importFrom(glue,glue_collapse)
importFrom(graphics,stem)
importFrom(haven,read_xpt)
importFrom(haven,write_xpt)
importFrom(lifecycle,deprecated)
importFrom(magrittr,"%>%")
Expand All @@ -66,6 +67,7 @@ importFrom(purrr,map_dbl)
importFrom(purrr,pluck)
importFrom(purrr,walk)
importFrom(readr,parse_number)
importFrom(readxl,read_xlsx)
importFrom(rlang,"%||%")
importFrom(rlang,":=")
importFrom(rlang,.data)
Expand Down
3 changes: 2 additions & 1 deletion R/xportr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
#' @aliases xportr-package
#'
#' @importFrom lifecycle deprecated
#' @importFrom haven write_xpt
#' @importFrom haven write_xpt read_xpt
#' @importFrom rlang abort warn inform with_options local_options .data := sym
#' %||%
#' @importFrom dplyr left_join bind_cols filter select rename rename_with n
Expand All @@ -121,6 +121,7 @@
#' @importFrom checkmate assert assert_character assert_choice assert_data_frame
#' assert_integer assert_logical assert_string makeAssertion check_data_frame
#' check_r6 test_data_frame test_string vname
#' @importFrom readxl read_xlsx
"_PACKAGE"

globalVariables(c(
Expand Down
28 changes: 15 additions & 13 deletions tests/testthat/test-format.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# xportr_format ----
## Test 1: xportr_format: error when metadata is not set ----
test_that("format Test 1: xportr_format: error when metadata is not set", {
test_that("format Test 1: error when metadata is not set", {
adsl <- data.frame(
USUBJID = c(1001, 1002, 1003),
BRTHDT = c(1, 1, 2)
Expand All @@ -12,7 +13,7 @@ test_that("format Test 1: xportr_format: error when metadata is not set", {
})

## Test 2: xportr_format: Gets warning when metadata has multiple rows with same variable ----
test_that("format Test 2: xportr_format: Gets warning when metadata has multiple rows with same variable", {
test_that("format Test 2: Gets warning when metadata has multiple rows with same variable", {
# This test uses the (2) functions below to reduce code duplication
# All `expect_*` are being called inside the functions
#
Expand All @@ -23,7 +24,7 @@ test_that("format Test 2: xportr_format: Gets warning when metadata has multiple
})

## Test 3: xportr_format: Works as expected with only one domain in metadata ----
test_that("format Test 3: xportr_format: Works as expected with only one domain in metadata", {
test_that("format Test 3: Works as expected with only one domain in metadata", {
adsl <- data.frame(
USUBJID = c(1001, 1002, 1003),
BRTHDT = c(1, 1, 2)
Expand All @@ -39,7 +40,7 @@ test_that("format Test 3: xportr_format: Works as expected with only one domain
})

## Test 4: xportr_format: Variable ending in DT should produce a warning if no format ----
test_that("format Test 4: xportr_format: Variable ending in DT should produce a warning if no format", {
test_that("format Test 4: Variable ending in DT should produce a warning if no format", {
adsl <- data.frame(
USUBJID = c(1001, 1002, 1003),
BRTHDT = c(1, 1, 2)
Expand All @@ -59,7 +60,7 @@ test_that("format Test 4: xportr_format: Variable ending in DT should produce a
})

## Test 5: xportr_format: Variable ending in TM should produce an error if no format ----
test_that("format Test 5: xportr_format: Variable ending in TM should produce an error if no format", {
test_that("format Test 5: Variable ending in TM should produce an error if no format", {
adsl <- data.frame(
USUBJID = c(1001, 1002, 1003),
BRTHTM = c(1, 1, 2)
Expand All @@ -79,7 +80,7 @@ test_that("format Test 5: xportr_format: Variable ending in TM should produce an
})

## Test 6: xportr_format: Variable ending in DTM should produce a warning if no format ----
test_that("format Test 6: xportr_format: Variable ending in DTM should produce a warning if no format", {
test_that("format Test 6: Variable ending in DTM should produce a warning if no format", {
adsl <- data.frame(
USUBJID = c(1001, 1002, 1003),
BRTHDTM = c(1, 1, 2)
Expand Down Expand Up @@ -121,7 +122,7 @@ test_that(
)

## Test 7: xportr_format: If a variable is character then a warning should be produced if format is > 32 in length ----
test_that("format Test 7: xportr_format: If a variable is character then a warning should be produced if format is > 32 in length", {
test_that("format Test 7: If a variable is character then a warning should be produced if format is > 32 in length", {#nolint
adsl <- data.frame(
USUBJID = c("1001", "1002", "1003"),
BRTHDT = c(1, 1, 2)
Expand Down Expand Up @@ -149,27 +150,28 @@ test_that("format Test 7: xportr_format: If a variable is character then a warni
})

## Test 8: xportr_format: If a variable is numeric then an error should be produced if a format starts with `$` ----
test_that("format Test 8: xportr_format: If a variable is numeric then an error should be produced if a format starts with `$`", {
adsl <- data.frame(
test_that(
"format Test 8: If a variable is numeric then an error should be produced if a format starts with `$`", {#nolint
adsl <- data.frame( #nolint
USUBJID = c(1001, 1002, 1003),
BRTHDT = c(1, 1, 2)
)

metadata <- data.frame(
metadata <- data.frame( #nolint
dataset = c("adsl", "adsl"),
variable = c("USUBJID", "BRTHDT"),
format = c("$4.", "DATE9.")
)

expect_error(
expect_error( #nolint
xportr_format(adsl, metadata, verbose = "stop"),
regexp = "(xportr::xportr_format) `USUBJID` is a numeric variable and should not have a `$` prefix.",
fixed = TRUE
)
})

## Test 9: xportr_format: If a variable is numeric then a warning should be produced if format is > 32 in length ----
test_that("format Test 9: xportr_format: If a variable is numeric then a warning should be produced if format is > 32 in length", {
## Test 9: xportr_format: If a variable is numeric then a warning should be produced if format is > 32 in length ---- #nolint
test_that("format Test 9: If a variable is numeric then a warning should be produced if format is > 32 in length", { #nolint
adsl <- data.frame(
USUBJID = c(1001, 1002, 1003),
BRTHDT = c(1, 1, 2)
Expand Down
19 changes: 10 additions & 9 deletions tests/testthat/test-length.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#' * Result of call will create SAS default length attribute (`width` for each
#' variable)

# xportr_length
## Test 1: xportr_length: Accepts valid domain names in metadata object ----
test_that("length Test 1: xportr_length: Accepts valid domain names in metadata object", {
test_that("length Test 1: Accepts valid domain names in metadata object", {
adsl <- minimal_table(30)
metadata <-
minimal_metadata(
Expand Down Expand Up @@ -51,7 +52,7 @@ test_that("length Test 1: xportr_length: Accepts valid domain names in metadata

## Test 2: xportr_length: CDISC data frame is being piped after another xportr function ----
test_that(
"length Test 2: xportr_length: CDISC data frame is being piped after another xportr function",
"length Test 2: CDISC data frame is being piped after another xportr function",
{
adsl <- minimal_table(30)
metadata <- minimal_metadata(
Expand Down Expand Up @@ -139,7 +140,7 @@ test_that("length Test 4: xportr_length: Throws message when variables not prese
})

## Test 5: xportr_length: Metacore instance can be used ----
test_that("length Test 5: xportr_length: Metacore instance can be used", {
test_that("length Test 5: Metacore instance can be used", {
skip_if_not_installed("metacore")
adsl <- minimal_table(30, cols = c("x", "b"))

Expand Down Expand Up @@ -170,7 +171,7 @@ test_that("length Test 5: xportr_length: Metacore instance can be used", {
})

## Test 6: xportr_length: Domain not in character format ----
test_that("length Test 6: xportr_length: Domain not in character format", {
test_that("length Test 6: Domain not in character format", {
skip_if_not_installed("readxl")

require(haven, quietly = TRUE)
Expand All @@ -185,7 +186,7 @@ test_that("length Test 6: xportr_length: Domain not in character format", {
})

## Test 7: xportr_length: error when metadata is not set ----
test_that("length Test 7: xportr_length: error when metadata is not set", {
test_that("length Test 7: error when metadata is not set", {
adsl <- minimal_table(30)

expect_error(xportr_length(adsl),
Expand All @@ -195,7 +196,7 @@ test_that("length Test 7: xportr_length: error when metadata is not set", {

## Test 8: xportr_length: Gets warning when metadata has multiple rows with same variable ----
test_that(
"length Test 8: xportr_length: Gets warning when metadata has multiple rows with same variable",
"length Test 8: Gets warning when metadata has multiple rows with same variable",
{
# This test uses the (2) functions below to reduce code duplication
# All `expect_*` are being called inside the functions
Expand All @@ -219,7 +220,7 @@ df <- data.frame(
)

## Test 9: xportr_length: length assigned as expected from metadata or data ----
test_that("length Test 9: xportr_length: length assigned as expected from metadata or data", {
test_that("length Test 9: length assigned as expected from metadata or data", {
result <- df %>%
xportr_length(meta_example, domain = "df", length_source = "metadata") %>%
expect_attr_width(c(10, 8))
Expand All @@ -232,7 +233,7 @@ test_that("length Test 9: xportr_length: length assigned as expected from metada

## Test 10: xportr_length: Gets message when length in metadata longer than data length ----
test_that(
"length Test 10: xportr_length: Gets message when length in metadata longer than data length",
"length Test 10: Gets message when length in metadata longer than data length",
{
result <- df %>%
xportr_length(meta_example, domain = "df", length_source = "data") %>%
Expand All @@ -241,7 +242,7 @@ test_that(
)

## Test 11: xportr_length: Works as expected with only one domain in metadata ----
test_that("length Test 11: xportr_length: Works as expected with only one domain in metadata", {
test_that("length Test 11: Works as expected with only one domain in metadata", {
adsl <- data.frame(
USUBJID = c(1001, 1002, 1003),
BRTHDT = c(1, 1, 2)
Expand Down
11 changes: 7 additions & 4 deletions tests/testthat/test-messages.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' Test `R/messages.R` functions

# xportr_logger ----
## Test 1: xportr_logger: Type parameter will create correct message type ----
test_that("messages Test 1: xportr_logger: Type parameter will create correct message type", {
test_that("messages Test 1: Type parameter will create correct message type", {
xportr_logger("A message", type = "none") %>%
expect_silent()

Expand All @@ -19,8 +20,9 @@ test_that("messages Test 1: xportr_logger: Type parameter will create correct me
expect_error("A message", class = "rlang_error")
})

# length_log ----
## Test 2: length_log: Missing lengths messages are shown ----
test_that("messages Test 2: length_log: Missing lengths messages are shown", {
test_that("messages Test 2: Missing lengths messages are shown", {
# Remove empty lines in cli theme
local_cli_theme()

Expand All @@ -31,7 +33,7 @@ test_that("messages Test 2: length_log: Missing lengths messages are shown", {
})

## Test 3: length_log: Missing variables messages are shown ----
test_that("messages Test 3: length_log: Missing variables messages are shown", {
test_that("messages Test 3: Missing variables messages are shown", {
# Remove empty lines in cli theme
local_cli_theme()

Expand All @@ -43,8 +45,9 @@ test_that("messages Test 3: length_log: Missing variables messages are shown", {
expect_message("Problem with `var1`.*`var2`.*`var3`")
})

# var_names_log ----
## Test 4: var_names_log: Renamed variables messages are shown ----
test_that("messages Test 4: var_names_log: Renamed variables messages are shown", {
test_that("messages Test 4: Renamed variables messages are shown", {
# Remove empty lines in cli theme
local_cli_theme()

Expand Down
Loading

0 comments on commit 5e9e189

Please sign in to comment.