1{ lib
2, python
3, buildPythonPackage
4, fetchPypi
5, isPyPy
6, isPy27
7, readline
8, R
9, rWrapper
10, rPackages
11, pcre
12, xz
13, bzip2
14, zlib
15, icu
16, singledispatch
17, six
18, jinja2
19, pytz
20, numpy
21, pytest
22, mock
23, extraRPackages ? []
24}:
25
26buildPythonPackage rec {
27 version = "2.8.6"; # python2 support dropped in 2.9.x
28 pname = "rpy2";
29 disabled = isPyPy;
30 src = fetchPypi {
31 inherit version pname;
32 sha256 = "162zki5c1apgv6qbafi7n66y4hgpgp43xag7q75qb6kv99ri6k80";
33 };
34 buildInputs = [
35 readline
36 R
37 pcre
38 xz
39 bzip2
40 zlib
41 icu
42 ] ++ (with rPackages; [
43 # packages expected by the test framework
44 ggplot2
45 dplyr
46 RSQLite
47 broom
48 DBI
49 dbplyr
50 hexbin
51 lme4
52 tidyr
53
54 # is in upstream's `requires` although it shouldn't be -- this is easier than patching it away
55 pytest
56 ]) ++ extraRPackages ++ rWrapper.recommendedPackages;
57
58 nativeBuildInputs = [
59 R # needed at setup time to detect R_HOME (alternatively set R_HOME explicitly)
60 ];
61
62 patches = [
63 # R_LIBS_SITE is used by the nix r package to point to the installed R libraries.
64 # This patch sets R_LIBS_SITE when rpy2 is imported.
65 ./r-libs-site.patch
66 ];
67 postPatch = ''
68 substituteInPlace ${ if isPy27 then "rpy/rinterface/__init__.py" else "rpy2/rinterface_lib/embedded.py" } --replace '@NIX_R_LIBS_SITE@' "$R_LIBS_SITE"
69 '';
70
71 doPatchelf = false; # fails because of "missing filename"
72 patchelfPhase = "";
73
74 propagatedBuildInputs = [
75 singledispatch
76 six
77 jinja2
78 pytz
79 numpy
80 ];
81
82 checkInputs = [
83 pytest
84 mock
85 ];
86 # One remaining test failure caused by different unicode encoding.
87 # https://bitbucket.org/rpy2/rpy2/issues/488
88 doCheck = false;
89 checkPhase = ''
90 ${python.interpreter} -m 'rpy2'
91 '';
92
93 # For some reason libreadline.so is not found. Curiously `ldd _rinterface.so | grep readline` shows two readline entries:
94 # libreadline.so.6 => not found
95 # libreadline.so.6 => /nix/store/z2zhmrg6jcrn5iq2779mav0nnq4vm2q6-readline-6.3p08/lib/libreadline.so.6 (0x00007f333ac43000)
96 # There must be a better way to fix this, but I don't know it.
97 postFixup = ''
98 patchelf --add-needed ${readline}/lib/libreadline.so "$out/${python.sitePackages}/rpy2/rinterface/"_rinterface*.so
99 '';
100
101 meta = {
102 homepage = "http://rpy.sourceforge.net/rpy2";
103 description = "Python interface to R";
104 license = lib.licenses.gpl2Plus;
105 platforms = lib.platforms.unix;
106 maintainers = with lib.maintainers; [ joelmo ];
107 };
108 }