Skip to content

Commit

Permalink
Added a suppress.message option to import.Statechanges, to not make t…
Browse files Browse the repository at this point in the history
…he test fail.
  • Loading branch information
JZauner committed Oct 19, 2023
1 parent 0a9091b commit 2050fd1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 42 deletions.
10 changes: 8 additions & 2 deletions R/import_States.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#' @param ID.newname Column name used for renaming the `ID.colname` column.
#' @param keepAllColumns Logical that specifies whether all columns should be
#' kept in the output. Defaults to `FALSE`.
#' @param suppress.summary Logical that specifies whether a summary of the
#' imported data should not be shown. Defaults to `FALSE`.
#'
#' @return a dataset with the `ID`, `State`, and `Datetime` columns. May contain
#' additional columns if `keepAllColumns` is `TRUE`.
Expand Down Expand Up @@ -80,7 +82,8 @@ import.Statechanges <- function(filename, path = NULL,
ID.colname,
State.newname = State,
ID.newname = Id,
keepAllColumns = FALSE) {
keepAllColumns = FALSE,
suppress.summary = FALSE) {

# Initial Checks ----------------------------------------------------------

Expand Down Expand Up @@ -115,6 +118,9 @@ import.Statechanges <- function(filename, path = NULL,
if(!tz %in% OlsonNames()) {
stop("The specified tz must be a valid time zone from the OlsonNames vector")
}
if(!is.logical(suppress.summary)) {
stop("The specified suppress.summary must be a logical")
}

# Logic ----------------------------------------------------------

Expand Down Expand Up @@ -199,7 +205,7 @@ import.Statechanges <- function(filename, path = NULL,
)
}

import.info(data, "Statechanges", tz, {{ ID.newname }})
if(!suppress.summary) import.info(data, "Statechanges", tz, {{ ID.newname }})

return(data)
}
4 changes: 2 additions & 2 deletions man/import.Dataset.Rd

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion man/import.Statechanges.Rd

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

37 changes: 2 additions & 35 deletions tests/testthat/_snaps/import_States.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,8 @@
Code
import.Statechanges(file.sleep, path, Datetime.format = "dmyHM",
State.colnames = c("sleep", "offset"), State.encoding = c("sleep", "wake"),
ID.colname = record_id, sep = ";", dec = ",", tz = tz)
ID.colname = record_id, sep = ";", dec = ",", tz = tz, suppress.summary = TRUE)
Output
Successfully read in 14 observations from Statechanges-file
Timezone set is Europe/Berlin.
Start: 2023-08-28 23:20:00
End: 2023-09-04 07:25:00
Timespan: 6.3 days
Observation intervals:
Id interval.time n pct
1 205 34860s (~9.68 hours) 1 8%
2 205 35520s (~9.87 hours) 1 8%
3 205 35700s (~9.92 hours) 1 8%
4 205 36000s (~10 hours) 1 8%
5 205 36900s (~10.25 hours) 1 8%
6 205 37020s (~10.28 hours) 1 8%
7 205 37920s (~10.53 hours) 1 8%
8 205 45780s (~12.72 hours) 1 8%
9 205 48480s (~13.47 hours) 1 8%
10 205 49200s (~13.67 hours) 1 8%
11 205 49500s (~13.75 hours) 1 8%
12 205 50040s (~13.9 hours) 1 8%
13 205 50580s (~14.05 hours) 1 8%
# A tibble: 14 x 3
# Groups: Id [1]
Id State Datetime
Expand All @@ -49,21 +29,8 @@
Code
import.Statechanges(file.sleep, path, Datetime.format = "dmyHM",
State.colnames = "comments", Datetime.column = sleep, ID.colname = record_id,
sep = ";", dec = ",", structure = "long", tz = tz)
sep = ";", dec = ",", structure = "long", tz = tz, suppress.summary = TRUE)
Output
Successfully read in 7 observations from Statechanges-file
Timezone set is Europe/Berlin.
Start: 2023-08-28 23:20:00
End: 2023-09-03 21:30:00
Timespan: 5.9 days
Observation intervals:
Id interval.time n pct
1 205 81300s (~22.58 hours) 1 17%
2 205 84900s (~23.58 hours) 1 17%
3 205 85500s (~23.75 hours) 1 17%
4 205 86100s (~23.92 hours) 1 17%
5 205 86400s (~1 days) 1 17%
6 205 87600s (~1.01 days) 1 17%
# A tibble: 7 x 3
# Groups: Id [1]
Id State Datetime
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-import_States.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ test_that("imports a wide and long dataset", {
path <- system.file("extdata/",
package = "LightLogR")
file.sleep <- "205_sleepdiary_all_20230904.csv"

tz <- "Europe/Berlin"

#wide data
Expand All @@ -15,7 +16,8 @@ test_that("imports a wide and long dataset", {
ID.colname = record_id,
sep = ";",
dec = ",",
tz = tz)
tz = tz,
suppress.summary = TRUE)
}
)

Expand All @@ -29,7 +31,7 @@ test_that("imports a wide and long dataset", {
ID.colname = record_id,
sep = ";",
dec = ",", structure = "long",
tz = tz)
tz = tz, suppress.summary = TRUE)
}
)
}
Expand Down

0 comments on commit 2050fd1

Please sign in to comment.