SCM

Forum: open-discussion

Monitor Forum | Start New Thread Start New Thread
RE: Return.calculate in PerformanceAnalytics is broken if you load the dplyr library [ Reply ]
By: Brian Peterson on 2015-06-07 02:49
[forum:42284]
r3662 on R-Forge uses lag.xts

Hadley is determined that he knows best and will behave badly regardless of the imapct on other packages.

RE: Return.calculate in PerformanceAnalytics is broken if you load the dplyr library [ Reply ]
By: Roger Bos on 2015-06-05 15:41
[forum:42282]
I understand where the responsibility lies, but how about a warning in blotter and PerformanceAnalytics just to provide a heads up to unsuspecting users?

if (isNamespaceLoaded("dplyr"))
print("WARNING: loaded package dplyr overwrites lag, which breaks many functions. Please consider a workaround such as lag <- lag.xts")

RE: Return.calculate in PerformanceAnalytics is broken if you load the dplyr library [ Reply ]
By: Brian Peterson on 2015-06-05 13:44
[forum:42281]
Roger,

You need to plead with Hadley not to break dispatch. If he is going to override a core R function, it is his responsibility to play nicely with others. We'll talk with him, but he's the one who is doing dispatch incorrectly. The bug is in dplyr, and you should file an issue on the dplyr github to ask them to fix it.

Regards,

Brian

RE: Return.calculate in PerformanceAnalytics is broken if you load the dplyr library [ Reply ]
By: Roger Bos on 2015-06-05 13:30
[forum:42280]
I respect whatever decision you end up making, but my final plea would be to say that you would be accomodating users like myself who spent time figuring out why code that was working a few weeks ago now doesn't work and users to have to create a modified version of Return.calculate to run in their environment. Return.calculate is used in so many examples for quantstrat, blotter, etc. If adding ".xts" to the end of the lag function prevents some new users from getting cryptic error messages when running example code, it is probably worth it.

RE: Return.calculate in PerformanceAnalytics is broken if you load the dplyr library [ Reply ]
By: Joshua Ulrich on 2015-06-04 22:08
[forum:42278]
Hadley re-overrode stats::lag 2 weeks ago: https://github.com/hadley/dplyr/commit/f8a46e030b7b899900f2091f41071619d0a46288

I'm extremely reluctant to accommodate someone, however popular, because they decided it was a good idea to override a generic function that has existed for more than a decade.

RE: Return.calculate in PerformanceAnalytics is broken if you load the dplyr library [ Reply ]
By: Roger Bos on 2015-06-04 21:36
[forum:42277]

Thanks for getting back to me. Using lag.xts also works for my example problem. I just installed all my packages from scratch today because I was trying to get blotter to install from source (finally got that working). So I am using dplyr_0.4.1.9000. I installed it from his github repo ("hadley/dplyr") so it should be the latest one.

RE: Return.calculate in PerformanceAnalytics is broken if you load the dplyr library [ Reply ]
By: Brian Peterson on 2015-06-04 21:28
[forum:42276]
Josh indicates that you shold try updating dplyr, as this may have been fixed on that end (dplyr broke dispatch).

Regards,

Brian

RE: Return.calculate in PerformanceAnalytics is broken if you load the dplyr library [ Reply ]
By: Brian Peterson on 2015-06-04 21:24
[forum:42275]
We can try explicitly calling lag.xts.

We'll also talk to Hadley about fixing his dispatch, but I don't use dplyr, since it is too slow for my data, so it's not a super high priority.

Regards,

Brian

Return.calculate in PerformanceAnalytics is broken if you load the dplyr library [ Reply ]
By: Roger Bos on 2015-06-04 21:09
[forum:42274]
Hadley has a function called lag which causes Return.calculate to give an error if dplyr is loaded. It would have been better if he had used a different name, but dplyr is pretty popular, so does it make sense to use stats::lag in Return.calculate?

Return.calculate <- function (prices, method = c("discrete", "log")) {
method = method[1]
pr = checkData(prices, method = "xts")
if (method == "simple" || method == "discrete") {
Returns = pr/stats::lag(pr) - 1
xtsAttributes(Returns) <- list(ret_type = "discrete")
}
if (method == "compound" || method == "log") {
Returns = diff(log(pr))
xtsAttributes(Returns) <- list(ret_type = "log")
}
reclass(Returns, match.to = pr)
}

Thanks to:
Vienna University of Economics and Business Powered By FusionForge