Skip to content

slidingwin does not recognize reference date and type when checking data coverage #35

Description

@AlexFerentinos

I ran code with an absolute reference day, but received the error that "Error in convertdate(bdate = bdate, cdate = cdate, xvar = xvar, cinterval = cinterval, : Climate data does not cover all years of biological data at site Tally. Latest climate data is 2019-07-01 Latest biological data is 2018-06-26. Please increase range of climate data"

As this didn't make sense, I checked my data, and found that the issue appeared to be that even though I was using an absolute reference date, convertdate still generated the error because my biological dates at the Tally site exceeded the climate data dates, even though there was enough climate data to satisfy my absolute reference date and window length.

I was able to fix this by altering the date to manually bring all dates within the date range of the climate data (which was fine as it not change the year they were in), but this error could be harder to fix for others. I have attached a toy example with the Mass datasets which recreates and resolves the issue in the same way it appeared in my code. Once the biological dates are corrected to be within the climate dates again, the code will run and provide identical results to the vignette.

library(climwin)
library(tidyverse)

Mass.toy <- Mass
Mass.toy$Date <- as.Date(Mass.toy$Date, "%d/%m/%Y")
Mass.toy$Date <- Mass.toy$Date + as.difftime(20, unit="days")

MassClimate.toy <- MassClimate
MassClimate.toy$Date <- as.Date(MassClimate.toy$Date, "%d/%m/%Y")
MassClimate.toy <- MassClimate.toy %>% filter(Date < as.Date("2012-05-21"))

MassWin <- slidingwin(xvar = list(Temp = MassClimate.toy$Temp),
                      cdate = MassClimate.toy$Date,
                      bdate = Mass.toy$Date,
                      baseline = lm(Mass ~ 1, data = Mass.toy),
                      cinterval = "day",
                      range = c(150, 0),
                      type = "absolute", refday = c(20, 05),
                      stat = "mean",
                      func = "lin")

Mass.toy$Date <- Mass.toy$Date - as.difftime(5, unit="days")

MassWin <- slidingwin(xvar = list(Temp = MassClimate.toy$Temp),
                      cdate = MassClimate.toy$Date,
                      bdate = Mass.toy$Date,
                      baseline = lm(Mass ~ 1, data = Mass.toy),
                      cinterval = "day",
                      range = c(150, 0),
                      type = "absolute", refday = c(20, 05),
                      stat = "mean",
                      func = "lin")

head(MassWin[[1]]$Dataset)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions