joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
220 stars 71 forks source link

Warning when subsetting xts objects if warnPartialMatch options set #231

Closed gp2x closed 6 years ago

gp2x commented 6 years ago

Description

I run R with the options warnPartialMatchArgs, warnPartialMatchAttr, and warnPartialMatchDollar set to TRUE, in order to minimize the chances of inadvertently assigning data to the wrong variable. However, this has the effect of generating warnings in cases where, for example, a function in a package calls another function using a partial variable name, or the variable name has been lengthened since the calling function was written.

Reproducible example

options(warnPartialMatchArgs=TRUE,
             warnPartialMatchAttr=TRUE,
             warnPartialMatchDollar=TRUE)
library(xts)
test <- xts(x=seq(1:59),order.by=seq.Date(from=as.Date("2018-01-01"),to=as.Date("2018-02-28"),by=1))
test["2018-01-05/2018-02-05",]

On my machine, this results in the following warnings:

1: In (function (year = 1970, month = 1, day = 1, hour = 0, min = 0,  :
  partial argument match of 'mon' to 'month'
2: In (function (year = 1970, month = 12, day = 31, hour = 23, min = 59,  :
  partial argument match of 'mon' to 'month'

Session Info

R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS: /usr/lib/libblas.so.3.8.0
LAPACK: /usr/lib/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] xts_0.10-2 zoo_1.8-1 

loaded via a namespace (and not attached):
[1] compiler_3.4.4  grid_3.4.4      lattice_0.20-35

Possible cause

Digging around in the source a bit, it looks like the functions being referred to are firstof and lastof in the file endpoints.R. In parse8601.R these functions are called and fed output from the function parse.side... it looks like the issue is that the list returned by parse.side uses "mon" and not the "month" that firstof and lastof are expecting.

I believe you could fix the warning by changing line 98 in parse8601.R from:

 mon=as_numeric(MM),

to:

 month=as_numeric(MM),

...but I'm not an expert on the codebase and I could be wrong about this.

joshuaulrich commented 6 years ago

Thanks for the report! You analysis of the cause is correct, and I will implement it.