/usr/lib/python3/dist-packages/rpy2/rlike/functional.py is in python3-rpy2 2.8.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import itertools
def tapply(seq, tag, fun):
""" Apply the function `fun` to the items in `seq`,
grouped by the tags defined in `tag`.
:param seq: sequence
:param tag: any sequence of tags
:param fun: function
:rtype: list
"""
if len(seq) != len(tag):
raise ValueError("seq and tag should have the same length.")
tag_grp = {}
for i, t in enumerate(tag):
try:
tag_grp[t].append(i)
except LookupError as le:
tag_grp[t] = [i, ]
res = [(tag, fun([seq[i] for i in ti])) for tag, ti in tag_grp.items()]
return res
def listify(fun):
""" Decorator to make a function apply
to each item in a sequence, and return a list. """
def f(seq):
res = [fun(x) for x in seq]
return res
return f
def iterify(fun):
""" Decorator to make a function apply
to each item in a sequence, and return an iterator. """
def f(seq):
for x in seq:
yield fun(x)
return f
|