@@ -1,10 +1,13 @@
11{ lib
2+, python
23, buildPythonPackage
34, fetchPypi
45, isPyPy
56, isPy27
67, readline
78, R
9+, rWrapper
10+, rPackages
811, pcre
912, lzma
1013, bzip2
@@ -13,7 +16,11 @@
1316, singledispatch
1417, six
1518, jinja2
19+, pytz
20+, numpy
1621, pytest
22+, mock
23+, extraRPackages ? []
1724}:
1825
1926buildPythonPackage rec {
@@ -38,18 +45,54 @@ buildPythonPackage rec {
3845 bzip2
3946 zlib
4047 icu
48+ ] ++ (with rPackages; [
49+ # packages expected by the test framework
50+ ggplot2
51+ dplyr
52+ RSQLite
53+ broom
54+ DBI
55+ dbplyr
56+ hexbin
57+ lme4
58+ tidyr
59+ ]) ++ extraRPackages ++ rWrapper.recommendedPackages;
60+
61+ patches = [
62+ # R_LIBS_SITE is used by the nix r package to point to the installed R libraries.
63+ # This patch sets R_LIBS_SITE when rpy2 is imported.
64+ ./r-libs-site.patch
4165 ];
66+ postPatch = ''
67+ substituteInPlace rpy/rinterface/__init__.py --replace '@NIX_R_LIBS_SITE@' "$R_LIBS_SITE"
68+ '';
69+
4270 propagatedBuildInputs = [
4371 singledispatch
4472 six
4573 jinja2
74+ pytz
75+ numpy
4676 ];
47− checkInputs = [ pytest ];
48− # Tests fail with `assert not _relpath.startswith('..'), "Path must be within the project"`
49− # in the unittest `loader.py`. I don't know what causes this.
77+
78+ checkInputs = [
79+ pytest
80+ mock
81+ ];
82+ # One remaining test failure caused by different unicode encoding.
83+ # https://bitbucket.org/rpy2/rpy2/issues/488
5084 doCheck = false;
51− # without this tests fail when looking for libreadline.so
52− LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
85+ checkPhase = ''
86+ ${python.interpreter} -m 'rpy2.tests'
87+ '';
88+
89+ # For some reason libreadline.so is not found. Curiously `ldd _rinterface.so | grep readline` shows two readline entries:
90+ # libreadline.so.6 => not found
91+ # libreadline.so.6 => /nix/store/z2zhmrg6jcrn5iq2779mav0nnq4vm2q6-readline-6.3p08/lib/libreadline.so.6 (0x00007f333ac43000)
92+ # There must be a better way to fix this, but I don't know it.
93+ postFixup = ''
94+ patchelf --add-needed ${readline}/lib/libreadline.so "$out/${python.sitePackages}/rpy2/rinterface/"_rinterface*.so
95+ '';
5396
5497 meta = {
5598 homepage = http://rpy.sourceforge.net/rpy2;