utilValidateElectionYears <- function(year, sinceYear){
# find out current year
currYear <- as.integer(format.Date(Sys.Date(), format = "%Y"))
# vector of all election years which have available data for download
electionYears <- seq(from = 2002, to = currYear, by = 2)
# if no year was passed to the "year" parameter
if (is.na(year)) {
# assume we'll download data from all elections available
year <- electionYears
}
if (electionType == "LOCAL") {
validYears <- seq(from = 2004, to = currYear, by = 4)
} else{
if (electionType == "MAJOR"){
validYears <- seq(from = 2002, to = currYear, by = 4)
} else{
validYears <- electionYears
}
}
# we should only try extract data from valid years
year <- intersect(year, validYears)
# if no year was left, display error message
if (length(year) < 1) {
stop("Please type valid election year(s)")
}
# if the "sinceYear" parameter got a value
if (!is.na(sinceYear)){
# fill a vector of all valid years since "sinceYear"
year <- intersect(validYears[validYears > min(sinceYear)])
}
return(year)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.