Skip to content

Commit

Permalink
Added getTimePoints convenience function (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
BartJanvanRossum committed Oct 23, 2019
1 parent 9cd226c commit 71a50b2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export(getCorrected)
export(getEffDims)
export(getGenoPred)
export(getHerit)
export(getTimePoints)
export(getVar)
import(ggplot2)
import(stats)
Expand Down
19 changes: 19 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,22 @@ checkAsreml <- function() {
invisible(TRUE)
}

#' Extract time points
#'
#' Function for extracting a data.frame with timeNumbers and timePoints from
#' an object of class TP or fitMod.
#'
#' @param x An object of class TP or fitMod
#'
#' @return A data.frame with columns timeNumber and timePoint listing the
#' time points in x
#'
#' @export
getTimePoints <- function(x) {
## Check input.
if (!inherits(x, "TP") && !inherits(x, "fitMod")) {
stop("x should be an object of class TP or fitMod")
}
return(attr(x = x, which = "timePoints"))
}

6 changes: 6 additions & 0 deletions inst/tinytest/test_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,11 @@ expect_true(inherits(statgenHTP:::chkTimePoints(testTP, 1), "character"))
expect_equal(statgenHTP:::chkTimePoints(testTP, 1),
statgenHTP:::chkTimePoints(testTP, "2018-06-01 16:37:00"))

### Test getTimePoints

expect_error(getTimePoints(x = 1:3),
"x should be an object of class TP or fitMod")
## Create TP object.
expect_true(inherits(getTimePoints(testTP), "data.frame"))
expect_equal(getTimePoints(testTP), attr(x = testTP, which = "timePoints"))

19 changes: 19 additions & 0 deletions man/getTimePoints.Rd

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

0 comments on commit 71a50b2

Please sign in to comment.