Skip to content

error in using %m+% when NA involved and rollback required #463

@zhangkd5

Description

@zhangkd5

When using %m+% function to add months to a date-time vector I noticed in a special situation where the date-time object includes both NA and month-end dates that require rollback, an error will occur:

> ymd(c('20150131')) %m+% months(1)  # OK when no NA
[1] "2015-02-28"
> ymd(c('2015-01-31', NA)) %m+% months(2)  # OK when no rollback
[1] "2015-03-31" NA  
> ymd(c('20150131', NA)) %m+% months(1) # Error when combining the two
Error in NextMethod(.Generic) : 
  NAs are not allowed in subscripted assignments

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] lubridate_1.5.6

loaded via a namespace (and not attached):
[1] magrittr_1.5  tools_3.3.1   stringi_1.1.1 stringr_1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions