Skip to content

Commit

Permalink
Added check for timePoint column in fitSpline (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
BartJanvanRossum committed Jul 30, 2021
1 parent 63e4dc5 commit 5d7c932
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions R/fitSpline.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ fitSpline <- function(inDat,
stop("minNoTP should be a numerical value.\n")
}
if (!useTimeNumber) {
if (!inherits(inDat[["timePoint"]], "POSIXct")) {
stop("Column timePoint should be of class POSIXct.\n")
}
## Convert time point to time number with the first time point as 0.
minTime <- min(inDat[["timePoint"]], na.rm = TRUE)
inDat[["timeNumber"]] <- as.numeric(inDat[["timePoint"]] - minTime)
Expand Down Expand Up @@ -212,11 +215,18 @@ fitSpline <- function(inDat,
coeff <- data.frame(obj.coefficients = obj$splineCoeffs, plotId = plant)
coeff[["type"]] <- paste0("timeNumber", seq_len(nrow(coeff)))
## Restrict dense grid to points within observation range.
# timeRangePl <- timeRange[timeRange[["timeNumber"]] >=
# min(dat[!is.na(dat[[trait]]), "timeNumber"]) &
# timeRange[["timeNumber"]] <=
# max(dat[!is.na(dat[[trait]]), "timeNumber"]),
# , drop = FALSE]

timeRangePl <- timeRange[timeRange[["timeNumber"]] >=
min(dat[!is.na(dat[[trait]]), "timeNumber"]) &
min(dat[["timeNumber"]]) &
timeRange[["timeNumber"]] <=
max(dat[!is.na(dat[[trait]]), "timeNumber"]),
max(dat[["timeNumber"]]),
, drop = FALSE]

## Predictions on a dense grid.
yPred <- predict(obj, x = timeRangePl$timeNumber)
yDeriv <- predict(obj, x = timeRangePl$timeNumber, deriv = TRUE)
Expand Down

0 comments on commit 5d7c932

Please sign in to comment.