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

Investigate checkUsage() output on internal functions #314

Open joshuaulrich opened 4 years ago

joshuaulrich commented 4 years ago

@harvey131 discovered an unused environment variable in .rbind.xts() in #313. So it would be a good idea to check for similar issues in all other unexported functions. That will avoid similar confusion in the future.

Here's some code that lists the output of codetools::checkUsage() on the xts namespace.

xtsNamespace <- asNamespace("xts")
xtsNsNames <- ls(xtsNamespace, all = TRUE)
xtsNsObj <- setNames(lapply(xtsNsNames, get, xtsNamespace), xtsNsNames)
xtsNsFunc <- xtsNsObj[sapply(xtsNsObj, is.function)]
checkFunc <- function(fbody, fname) {
  capture.output(codetools::checkUsage(fbody, fname))
}
out <- Map(checkFunc, xtsNsFunc, names(xtsNsFunc))
toCheck <- out[sapply(out, length) > 0]

And here's the output.

R> toCheck
$.rbind.xts
[1] ".rbind.xts: local variable 'env' assigned but may not be used"

$`[<-.xts`
[1] "[<-.xts: local variable '.Class' assigned but may not be used"

$addEventLines
[1] "addEventLines : <anonymous>: local variable 'ta.x' assigned but may not be used"
[2] "addEventLines: local variable 'ind' assigned but may not be used"               

$addLegend
[1] "addLegend: local variable 'ind' assigned but may not be used"

$addPolygon
[1] "addPolygon : <anonymous>: local variable 'ta.x' assigned but may not be used"

$as.fts.xts
[1] "as.fts.xts: local variable 'fts' assigned but may not be used"

$as.timeSeries.xts
[1] "as.timeSeries.xts: local variable 'timeSeries' assigned but may not be used"

$merge.xts
[1] "merge.xts: local variable 'sfx' assigned but may not be used"

$new.replot_xts
[1] "new.replot_xts: local variable 'get_pad' assigned but may not be used"   
[2] "new.replot_xts: local variable 'move_frame' assigned but may not be used"

$re.fts
[1] "re.fts: local variable 'fts' assigned but may not be used"

$re.irts
[1] "re.irts: local variable 'irts' assigned but may not be used"

$re.timeSeries
[1] "re.timeSeries: local variable 'timeSeries' assigned but may not be used"

$re.ts
[1] "re.ts: local variable 'dn' assigned but may not be used"

$re.ts2
[1] "re.ts2 : na.replace: local variable 'ncols' assigned but may not be used"
[2] "re.ts2: local variable 'na.replace' assigned but may not be used"        

$rollcov.xts
[1] "rollcov.xts: local variable 'n1' assigned but may not be used"

$rollmax.xts
[1] "rollmax.xts: local variable 'n1' assigned but may not be used"

$rollmin.xts
[1] "rollmin.xts: local variable 'n1' assigned but may not be used"

$rollsum.xts
[1] "rollsum.xts: local variable 'n1' assigned but may not be used"

$`tzone<-.default`
[1] "tzone<-.default: local variable 'tzone' assigned but may not be used"

It looks like some of those may be bugs... so we should discuss here, and then open issues for the ones that are actually bugs and not false positives.

harvey131 commented 4 years ago