KxSystems / rkdb

R client for kdb+
https://code.kx.com/q/interfaces
Apache License 2.0
41 stars 29 forks source link

Make data types bijective #72

Open travis-leith opened 9 months ago

travis-leith commented 9 months ago

right now, we have clear conversions from KDB types to R types, but it is not bijective so converting from R to KDB is not clear. For example, KDB time converts to R difftime, but KDB minute also converts to R difftime.

If I send R difftime to KDB, I get a dictionary on the other side with the attributes as keys.

But this gives us a clue for a useful refactor of rkdb. Lets use custom attributes in R to construct types that rkdb can convert into proper KDB types. For exmaple, make a function like rkdb::minute() that sets the attribute and ultimate results in a minute type in KDB. On the way back, the same thing happens. It is still a difftime in R, but has this attribute indicating which KDB type it came from.