0

How can I work with bitsets in R? I googled and found bit and pack packages but I'm not sure it's what I need. I have big raw object that is loaded from DB which is array of bytes. I want to access it as if it was bitset to have following operations

  1. count set bits;
  2. iterate through set bits in foreach loop;
  3. set and unset individual bits.

I can probably just convert raw to array of bytes (don't know to do that yet btw) and do everything I described using bitwise operators but perhaps some existing package already has that ?

expert
  • 29,290
  • 30
  • 110
  • 214
  • 2
    I edited this to avoid the appearance that you're looking for a package recommendation, which would be off topic. – joran Apr 20 '17 at 15:42
  • *"I googled and found bit and pack packages but I'm not sure it's what I need."* -- Please elaborate on your needs; your question is fairly broad at the moment. – nrussell Apr 20 '17 at 19:17
  • @nrussell Done. – expert Apr 20 '17 at 19:24
  • 1
    Possibly `rawToBits`; e.g. `rawToBits(charToRaw("abcd"))` will give you 32 indexable bits. This may or may not fit your needs. – nrussell Apr 20 '17 at 19:33
  • @nrussell Yep, that did it. It returned value that looks like array of booleans. How do I check if `x` position is TRUE ? – expert Apr 21 '17 at 18:03
  • @expert Can you add a reproducible example? – nrussell Apr 21 '17 at 18:55

1 Answers1

1

I ended up using rawToBits that @nrussell recommended but unfortunately it simply converts raw into vector of booleans with one byte per item. If anyone knows more memory efficient way let me know.

expert
  • 29,290
  • 30
  • 110
  • 214