Skip to content

Commit

Permalink
[bugfix] Only compare matching length vectors
Browse files Browse the repository at this point in the history
Ensure `length(special.days) == 1L` before comparing to `"weekends"`.
This is requried for newer versions of R.

As far as I can tell, this does not limit any functionality, but masks
the informative error message when specifying the wrong number of days
(i.e. 365 for a leap year) with an uninformative one.

This commit fixes issue #30.

Signed-off-by: Marcel Schilling <[email protected]>
  • Loading branch information
mschilli87 committed Dec 21, 2024
1 parent 1b7bd48 commit 557f506
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions R/calendR.R
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ calendR <- function(year = format(Sys.Date(), "%Y"),
if(is.character(special.days)) {

if(length(special.days) != length(dates)){

if(special.days != "weekend") {
if(length(special.days) != 1L || special.days != "weekend") {
stop("special.days must be a numeric vector, a character vector of the length of the number of days of the year or month or 'weekend'")
} else {
wend <- FALSE
Expand Down Expand Up @@ -372,7 +371,7 @@ calendR <- function(year = format(Sys.Date(), "%Y"),
if (length(special.days) == length(dates)) {
fills <- special.days
} else {
if (special.days == "weekend") {
if (length(special.days) == 1L && special.days == "weekend") {
fills <- t2$weekend
}
}
Expand Down Expand Up @@ -422,7 +421,7 @@ calendR <- function(year = format(Sys.Date(), "%Y"),
if (length(special.days) == length(dates)) {
fills <- special.days
} else {
if (special.days == "weekend") {
if (length(special.days) == 1L && special.days == "weekend") {
fills <- t2$weekend
}
}
Expand Down

0 comments on commit 557f506

Please sign in to comment.