Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fcase breaks xts contracts #6574

Open
ethanbsmith opened this issue Oct 12, 2024 · 1 comment
Open

fcase breaks xts contracts #6574

ethanbsmith opened this issue Oct 12, 2024 · 1 comment

Comments

@ethanbsmith
Copy link
Contributor

ethanbsmith commented Oct 12, 2024

thank you for the fix to #6480. it mostly works great, but has introduced a weird scenario, where the result thinks its an xts object, but is not a matrix. as xts is an indexed matrix, this should never happen, and the result is now breaking subsequent code. this issue really applies to all zoo objects, not just xts

if fcase kept the ouput as a 1 column matrix, matching what was passed in, this works would be fine (suspect this may break other code)
if fcase returned a vector stripping the class and attributes, this would also be usable
returning this hybrid output (non matrix xts) is problematic

cc @joshuaulrich

MRE:
library(xts)
d <- xts(matrix(runif(4000, 0, 100), ncol = 4), order.by = Sys.Date() + (1:1000))
r <- data.table::fcase(d[,1] > d[,4], d[,2], default = (d[,2] + d[,3]) / 2)
class(r)
#[1] "xts" "zoo"
is.matrix(r)
#[1] FALSE

#data.table_1.16.2

@ethanbsmith
Copy link
Contributor Author

i guess, for me, it comes down to what is the design contract for fcase?
if it is to return what was passed in, it should probably not be converting 1 column matrix to a vector
if it is to return a vector, maybe calling as.vector on inputs would be safer as it would allow dispatching to handle things properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant