1R packages
2==========
3
4## Installation
5
6Define an environment for R that contains all the libraries that you'd like to
7use by adding the following snippet to your $HOME/.config/nixpkgs/config.nix file:
8
9```nix
10{
11 packageOverrides = super: let self = super.pkgs; in
12 {
13
14 rEnv = super.rWrapper.override {
15 packages = with self.rPackages; [
16 devtools
17 ggplot2
18 reshape2
19 yaml
20 optparse
21 ];
22 };
23 };
24}
25```
26
27Then you can use `nix-env -f "<nixpkgs>" -iA rEnv` to install it into your user
28profile. The set of available libraries can be discovered by running the
29command `nix-env -f "<nixpkgs>" -qaP -A rPackages`. The first column from that
30output is the name that has to be passed to rWrapper in the code snipped above.
31
32However, if you'd like to add a file to your project source to make the
33environment available for other contributors, you can create a `default.nix`
34file like so:
35```nix
36let
37 pkgs = import <nixpkgs> {};
38 stdenv = pkgs.stdenv;
39in with pkgs; {
40 myProject = stdenv.mkDerivation {
41 name = "myProject";
42 version = "1";
43 src = if pkgs.lib.inNixShell then null else nix;
44
45 buildInputs = with rPackages; [
46 R
47 ggplot2
48 knitr
49 ];
50 };
51}
52```
53and then run `nix-shell .` to be dropped into a shell with those packages
54available.
55
56## RStudio
57
58RStudio uses a standard set of packages and ignores any custom R
59environments or installed packages you may have. To create a custom
60environment, see `rstudioWrapper`, which functions similarly to
61`rWrapper`:
62
63```nix
64{
65 packageOverrides = super: let self = super.pkgs; in
66 {
67
68 rstudioEnv = super.rstudioWrapper.override {
69 packages = with self.rPackages; [
70 dplyr
71 ggplot2
72 reshape2
73 ];
74 };
75 };
76}
77```
78
79Then like above, `nix-env -f "<nixpkgs>" -iA rstudioEnv` will install
80this into your user profile.
81
82## Updating the package set
83
84```bash
85nix-shell generate-shell.nix
86
87Rscript generate-r-packages.R cran > cran-packages.nix.new
88mv cran-packages.nix.new cran-packages.nix
89
90Rscript generate-r-packages.R bioc > bioc-packages.nix.new
91mv bioc-packages.nix.new bioc-packages.nix
92```
93
94`generate-r-packages.R <repo>` reads `<repo>-packages.nix`, therefor the renaming.
95
96
97## Testing if the Nix-expression could be evaluated
98
99```bash
100nix-build test-evaluation.nix --dry-run
101```
102
103If this exits fine, the expression is ok. If not, you have to edit `default.nix`