diff --git a/DESCRIPTION b/DESCRIPTION index 7a4cad8..bb343ba 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,7 +39,9 @@ Imports: stringr (>= 1.3.0), tools, utils, - readr + readr, + RSQLite, + DBI Encoding: UTF-8 LazyData: true RoxygenNote: 7.1.1 diff --git a/R/read_agd.R b/R/read_agd.R index 0ad156e..252caab 100644 --- a/R/read_agd.R +++ b/R/read_agd.R @@ -18,7 +18,7 @@ #' @export #' #' @examples -#' agd_file <- system.file("example1sec.csv", package = "AGread") +#' agd_file <- system.file("extdata", "example1sec.agd", package = "AGread") #' read_agd(agd_file, "both") read_agd <- function( file, return = c("data", "settings", "both"), tz = "UTC", verbose = FALSE diff --git a/man/read_agd.Rd b/man/read_agd.Rd index a6b3e42..0c7bfc6 100644 --- a/man/read_agd.Rd +++ b/man/read_agd.Rd @@ -33,6 +33,10 @@ The agd is made up of a \code{settings} element and a \code{data} \code{data} are in data frame format. If \code{return = "both"}, they are given as a list. } +\examples{ +agd_file <- system.file("extdata", "example1sec.agd", package = "AGread") +read_agd(agd_file, "both") +} \seealso{ \href{https://github.com/actigraph/ActiLifeManual/blob/master/docs/appendix.rst}{ActiGraph documentation} } diff --git a/tests/testthat/agd_read_cache.rds b/tests/testthat/agd_read_cache.rds new file mode 100644 index 0000000..b648dcc Binary files /dev/null and b/tests/testthat/agd_read_cache.rds differ diff --git a/tests/testthat/test_agd.R b/tests/testthat/test_agd.R new file mode 100644 index 0000000..d260f27 --- /dev/null +++ b/tests/testthat/test_agd.R @@ -0,0 +1,47 @@ +context("agd file reading") +library(AGread) + +## MANUAL LEGACY TEST (verified 2/14/19) +# AG_legacy <- readRDS("data-raw/counts_legacy.rds") +# AG <- read_AG_counts( +# system.file( +# "extdata", "example1sec.csv", package = "AGread" +# ), verbose = TRUE, skip = 11 +# ) +# > all.equal(AG, AG_legacy) +# [1] TRUE + +testthat::test_that("agd file reading produces expected output", { + + agd <- system.file( + "extdata", "example1sec.agd", package = "AGread" + ) + + csv <- system.file( + "extdata", "example1sec.csv", package = "AGread" + ) + + test <- read_agd(agd) + ref <- read_AG_counts(csv) + + testthat::expect_equal_to_reference( + test, "agd_read_cache.rds" + ) + + test2 <- read_agd(agd, "settings") + test3 <- read_agd(agd, "data") + test4 <- read_agd(agd, "both") + + format_test <- all( + identical(test, test3), + identical(test, test4$data), + identical(test2, test4$settings), + identical(class(test), class(ref)), + identical(class(test4$data), class(ref)) + ) + + testthat::expect_true(format_test) + + testthat::expect_equal(test, ref, scale = 1) + +}) diff --git a/tests/testthat/test_counts.R b/tests/testthat/test_counts.R index 4019748..9d42545 100644 --- a/tests/testthat/test_counts.R +++ b/tests/testthat/test_counts.R @@ -11,7 +11,7 @@ library(AGread) # > all.equal(AG, AG_legacy) # [1] TRUE -testthat::test_that("File reading produces expected output", { +testthat::test_that("csv file reading produces expected output", { testthat::expect_equal_to_reference( read_AG_counts( system.file(