1{
2 stdenv,
3 lib,
4 buildPythonPackage,
5 fetchPypi,
6 fetchpatch,
7 isPyPy,
8 R,
9 rWrapper,
10 rPackages,
11 pcre,
12 xz,
13 bzip2,
14 zlib,
15 icu,
16 ipython,
17 jinja2,
18 pytz,
19 pandas,
20 numpy,
21 cffi,
22 tzlocal,
23 simplegeneric,
24 pytestCheckHook,
25 extraRPackages ? [ ],
26}:
27
28buildPythonPackage rec {
29 version = "3.5.16";
30 format = "setuptools";
31 pname = "rpy2";
32
33 disabled = isPyPy;
34 src = fetchPypi {
35 inherit version pname;
36 hash = "sha256-g34vdFg2WKXEwzl2GnP5Q08z75ztPjDGTadWIWXCgBs=";
37 };
38
39 patches = [
40 # R_LIBS_SITE is used by the nix r package to point to the installed R libraries.
41 # This patch sets R_LIBS_SITE when rpy2 is imported.
42 ./rpy2-3.x-r-libs-site.patch
43 ];
44
45 postPatch = ''
46 substituteInPlace 'rpy2/rinterface_lib/embedded.py' --replace '@NIX_R_LIBS_SITE@' "$R_LIBS_SITE"
47 substituteInPlace 'requirements.txt' --replace 'pytest' ""
48 '';
49
50 buildInputs =
51 [
52 pcre
53 xz
54 bzip2
55 zlib
56 icu
57 ]
58 ++ (with rPackages; [
59 # packages expected by the test framework
60 ggplot2
61 dplyr
62 RSQLite
63 broom
64 DBI
65 dbplyr
66 hexbin
67 lazyeval
68 lme4
69 tidyr
70 ])
71 ++ extraRPackages
72 ++ rWrapper.recommendedPackages;
73
74 nativeBuildInputs = [
75 R # needed at setup time to detect R_HOME (alternatively set R_HOME explicitly)
76 ];
77
78 propagatedBuildInputs = [
79 ipython
80 jinja2
81 pytz
82 pandas
83 numpy
84 cffi
85 tzlocal
86 simplegeneric
87 ];
88
89 doCheck = !stdenv.isDarwin;
90
91 nativeCheckInputs = [ pytestCheckHook ];
92
93 meta = {
94 homepage = "https://rpy2.github.io/";
95 description = "Python interface to R";
96 license = lib.licenses.gpl2Plus;
97 platforms = lib.platforms.unix;
98 maintainers = with lib.maintainers; [ joelmo ];
99 };
100}