3 ## Installation {#installation}
5 Define an environment for R that contains all the libraries that you'd like to
6 use by adding the following snippet to your $HOME/.config/nixpkgs/config.nix file:
10 packageOverrides = super: let self = super.pkgs; in
13 rEnv = super.rWrapper.override {
14 packages = with self.rPackages; [
26 Then you can use `nix-env -f "<nixpkgs>" -iA rEnv` to install it into your user
27 profile. The set of available libraries can be discovered by running the
28 command `nix-env -f "<nixpkgs>" -qaP -A rPackages`. The first column from that
29 output is the name that has to be passed to rWrapper in the code snipped above.
31 However, if you'd like to add a file to your project source to make the
32 environment available for other contributors, you can create a `default.nix`
36 with import <nixpkgs> {};
38 myProject = stdenv.mkDerivation {
41 src = if lib.inNixShell then null else nix;
43 buildInputs = with rPackages; [
51 and then run `nix-shell .` to be dropped into a shell with those packages
56 RStudio uses a standard set of packages and ignores any custom R
57 environments or installed packages you may have. To create a custom
58 environment, see `rstudioWrapper`, which functions similarly to
63 packageOverrides = super: let self = super.pkgs; in
66 rstudioEnv = super.rstudioWrapper.override {
67 packages = with self.rPackages; [
77 Then like above, `nix-env -f "<nixpkgs>" -iA rstudioEnv` will install
78 this into your user profile.
80 Alternatively, you can create a self-contained `shell.nix` without the need to
81 modify any configuration files:
84 { pkgs ? import <nixpkgs> {}
87 pkgs.rstudioWrapper.override {
88 packages = with pkgs.rPackages; [ dplyr ggplot2 reshape2 ];
93 Executing `nix-shell` will then drop you into an environment equivalent to the
94 one above. If you need additional packages just add them to the list and
97 ## Updating the package set {#updating-the-package-set}
99 There is a script and associated environment for regenerating the package
100 sets and synchronising the rPackages tree to the current CRAN and matching
101 BIOC release. These scripts are found in the `pkgs/development/r-modules`
102 directory and executed as follows:
105 nix-shell generate-shell.nix
107 Rscript generate-r-packages.R cran > cran-packages.json.new
108 mv cran-packages.json.new cran-packages.json
110 Rscript generate-r-packages.R bioc > bioc-packages.json.new
111 mv bioc-packages.json.new bioc-packages.json
113 Rscript generate-r-packages.R bioc-annotation > bioc-annotation-packages.json.new
114 mv bioc-annotation-packages.json.new bioc-annotation-packages.json
116 Rscript generate-r-packages.R bioc-experiment > bioc-experiment-packages.json.new
117 mv bioc-experiment-packages.json.new bioc-experiment-packages.json
120 `generate-r-packages.R <repo>` reads `<repo>-packages.json`, therefore
123 The contents of a generated `*-packages.json` file will be used to
124 create a package derivation for each R package listed in the file.
126 Some packages require overrides to specify external dependencies or other
127 patches and special requirements. These overrides are specified in the
128 `pkgs/development/r-modules/default.nix` file. As the `*-packages.json`
129 contents are automatically generated it should not be edited and broken
130 builds should be addressed using overrides.