Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
add checks for data.frame format in surrogate functions
Browse files Browse the repository at this point in the history
correct vignette name
  • Loading branch information
ha0ye committed Apr 21, 2019
1 parent 69a8dea commit a616d43
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ LinkingTo: Rcpp, RcppEigen
RcppModules: lnlp_module, block_lnlp_module, ccm_module
Suggests: knitr, rmarkdown, R.rsp, ggplot2, testthat, formatR, tibble, digest, pkgdown, covr
VignetteBuilder: knitr, R.rsp
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
9 changes: 9 additions & 0 deletions R/data_transformations.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ make_surrogate_shuffle <- function(ts, num_surr = 100)
#'
make_surrogate_ebisuzaki <- function(ts, num_surr = 100)
{
if (is.data.frame(ts))
{
ts <- ts[, 1]
}

if (any(!is.finite(ts)))
stop("input time series contained invalid values")

Expand Down Expand Up @@ -118,6 +123,10 @@ make_surrogate_ebisuzaki <- function(ts, num_surr = 100)
#'
make_surrogate_seasonal <- function(ts, num_surr = 100, T_period = 12)
{
if (is.data.frame(ts))
{
ts <- ts[, 1]
}

if (any(!is.finite(ts)))
stop("input time series contained invalid values")
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Rcpp::loadModule("xmap_module", TRUE)
if (!interactive()) return()

intro_message <- paste("If you're new to the rEDM package, please check out the tutorial:",
"> vignette(\"rEDM-tutorial\")", sep = "\n")
"> vignette(\"rEDM\")", sep = "\n")
packageStartupMessage(intro_message)
}
5 changes: 5 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
library(testthat)
library(rEDM)

if ("sample.kind" %in% names(formals(RNGkind)))
{
suppressWarnings(RNGkind(sample.kind = "Rounding"))
}

test_check("rEDM")
13 changes: 9 additions & 4 deletions tests/testthat/test_02_helper_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ test_that("make_surrogate_seasonal works", {
})

test_that("make_surrogate_twin works", {
if ("sample.kind" %in% names(formals(RNGkind)))
{
suppressWarnings(RNGkind(sample.kind = "Rounding"))
}
set.seed(12)
ts <- rnorm(100) + sin(1:100 * pi / 6)
set.seed(42)
Expand All @@ -206,3 +202,12 @@ test_that("make_surrogate_twin works", {
set.seed(42)
expect_error(dat3 <- make_surrogate_data(ts, "twin", 15, T_period = 13, dim = 2))
})

test_that("surrogate functions work data.frames", {
set.seed(42)
df <- data.frame(ts = rnorm(50))
expect_error(out <- make_surrogate_shuffle(df, num_surr = 4), NA)
expect_error(out <- make_surrogate_ebisuzaki(df, num_surr = 4), NA)
expect_error(out <- make_surrogate_seasonal(df, num_surr = 4), NA)
expect_error(out <- make_surrogate_twin(df, num_surr = 4, T_period = 2), NA)
})

0 comments on commit a616d43

Please sign in to comment.