Install rfuns with uv:
uv add rfunsOr with pip:
pip install rfunsTo import all the functions defined in rfuns:
from rfuns import *
trimws([" hello ", "world "])
# ['hello', 'world']
strsplit("these words are split", " ")
# ["these", "words", "are", "split"]
x = vec(['a', 'b', 'c', 'b'])
which(x == 'b')
# [1, 3]Alternatively, import the library and use the functions with the a chosen prefix:
import rfuns as r
r.trimws([" hello ", "world "])
# ['hello', 'world']
r.strsplit("these words are split", " ")
# ["these", "words", "are", "split"]
x = r.vec(['a', 'b', 'c', 'b'])
r.which(x == 'b')
# [1, 3]The wrappers themselves are mostly for convenience and famliiarity for R users, and are not optimised for performance. For example, table() is implemented using collections.Counter as
from collections import Counter
def table(x):
return dict(sorted(Counter(x).items()))but I find table() to be a much cleaner abstraction of this.
Similarly, which() is implemented as a simple list comprehension:
def which(x):
return [i for i, v in enumerate(x) if v]but again, a one-word function seems (at least to me) vastly cleaner.
See this blog post for more background info.
If you encounter any issues, check the GitHub repository to see if it’s a known issue, and if not, feel free to report it: