Skip to content

Commit 557f506

Browse files
committed
[bugfix] Only compare matching length vectors
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]>
1 parent 1b7bd48 commit 557f506

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

R/calendR.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ calendR <- function(year = format(Sys.Date(), "%Y"),
289289
if(is.character(special.days)) {
290290

291291
if(length(special.days) != length(dates)){
292-
293-
if(special.days != "weekend") {
292+
if(length(special.days) != 1L || special.days != "weekend") {
294293
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'")
295294
} else {
296295
wend <- FALSE
@@ -372,7 +371,7 @@ calendR <- function(year = format(Sys.Date(), "%Y"),
372371
if (length(special.days) == length(dates)) {
373372
fills <- special.days
374373
} else {
375-
if (special.days == "weekend") {
374+
if (length(special.days) == 1L && special.days == "weekend") {
376375
fills <- t2$weekend
377376
}
378377
}
@@ -422,7 +421,7 @@ calendR <- function(year = format(Sys.Date(), "%Y"),
422421
if (length(special.days) == length(dates)) {
423422
fills <- special.days
424423
} else {
425-
if (special.days == "weekend") {
424+
if (length(special.days) == 1L && special.days == "weekend") {
426425
fills <- t2$weekend
427426
}
428427
}

0 commit comments

Comments
 (0)