Skip to content

Commit

Permalink
Merge pull request #80 from signaturescience/27-better-handling-of-da…
Browse files Browse the repository at this point in the history
…tes-in-to_signal

adding date conversion for character in to_signal
  • Loading branch information
vpnagraj authored Oct 12, 2023
2 parents 2cdb24b + 589e891 commit 53d770c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 4 additions & 3 deletions R/construct.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
#'
#' For "observed" data the data frame must at minimum include columns for **location** (geographic unit such as FIPS code) and **date** (date of reported value; must be `date` class). The data should also include a column that contains the outcome (e.g., case count).
#'
#' For "forecast" data the data frame must include columns for **location** (geographic unit such as FIPS code), **date** (date corresponding to forecast horizon; must be `date` class), **horizon** (forecast horizon), **lower** (the lower limit of the prediction interval for the forecast), **point** (the point estimate for the forecast), and **upper** (the upper limit of the prediction interval for the forecast). Note that the [read_forecast] function returns data in this format.
#' For "forecast" data the data frame must include columns for **location** (geographic unit such as FIPS code), **date** (date corresponding to forecast horizon; must be `date` class or character formatted as 'YYYY-MM-DD'), **horizon** (forecast horizon), **lower** (the lower limit of the prediction interval for the forecast), **point** (the point estimate for the forecast), and **upper** (the upper limit of the prediction interval for the forecast). Note that the [read_forecast] function returns data in this format.
#'
#' @return An object of the class `signal`. The object will have a second class of either `observed` or `forecast` depending on the value passed to the "type" argument.
#' @export
#'
#' @examples
#' hosp <- read.csv(system.file("extdata/observed/hdgov_hosp_weekly.csv", package = "rplanes"))
#' hosp$date <- as.Date(hosp$date, format = "%Y-%m-%d")
#' to_signal(hosp, outcome = "flu.admits", type = "observed", resolution = "weeks")
#'
#' fp <- system.file("extdata/forecast/2022-10-31-SigSci-TSENS.csv", package = "rplanes")
Expand All @@ -35,7 +34,9 @@ to_signal <- function(input,
resolution = "weeks",
horizon = NULL) {

## arg match if we want
if(!lubridate::is.Date(input$date)) {
input$date <- as.Date(input$date, format = "%Y-%m-%d")
}

if(type == "observed") {
## return special signal, observed list
Expand Down
3 changes: 1 addition & 2 deletions man/to_signal.Rd

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

0 comments on commit 53d770c

Please sign in to comment.