2016-02-22 07:52:22 +00:00
|
|
|
R packages
|
|
|
|
==========
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
Define an environment for R that contains all the libraries that you'd like to
|
2017-02-01 15:03:42 +00:00
|
|
|
use by adding the following snippet to your $HOME/.config/nixpkgs/config.nix file:
|
2016-02-22 07:52:22 +00:00
|
|
|
|
|
|
|
```nix
|
|
|
|
{
|
|
|
|
packageOverrides = super: let self = super.pkgs; in
|
|
|
|
{
|
|
|
|
|
|
|
|
rEnv = super.rWrapper.override {
|
2017-04-21 19:00:32 +01:00
|
|
|
packages = with self.rPackages; [
|
2016-02-22 07:52:22 +00:00
|
|
|
devtools
|
|
|
|
ggplot2
|
|
|
|
reshape2
|
|
|
|
yaml
|
|
|
|
optparse
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Then you can use `nix-env -f "<nixpkgs>" -iA rEnv` to install it into your user
|
|
|
|
profile. The set of available libraries can be discovered by running the
|
|
|
|
command `nix-env -f "<nixpkgs>" -qaP -A rPackages`. The first column from that
|
|
|
|
output is the name that has to be passed to rWrapper in the code snipped above.
|
|
|
|
|
2016-10-13 23:18:16 +01:00
|
|
|
However, if you'd like to add a file to your project source to make the
|
|
|
|
environment available for other contributors, you can create a `default.nix`
|
|
|
|
file like so:
|
|
|
|
```nix
|
|
|
|
let
|
|
|
|
pkgs = import <nixpkgs> {};
|
|
|
|
stdenv = pkgs.stdenv;
|
|
|
|
in with pkgs; {
|
|
|
|
myProject = stdenv.mkDerivation {
|
|
|
|
name = "myProject";
|
|
|
|
version = "1";
|
|
|
|
src = if pkgs.lib.inNixShell then null else nix;
|
|
|
|
|
|
|
|
buildInputs = with rPackages; [
|
|
|
|
R
|
|
|
|
ggplot2
|
|
|
|
knitr
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
```
|
|
|
|
and then run `nix-shell .` to be dropped into a shell with those packages
|
|
|
|
available.
|
|
|
|
|
2017-01-27 23:54:50 +00:00
|
|
|
## RStudio
|
|
|
|
|
2017-05-01 13:59:43 +01:00
|
|
|
RStudio uses a standard set of packages and ignores any custom R
|
|
|
|
environments or installed packages you may have. To create a custom
|
|
|
|
environment, see `rstudioWrapper`, which functions similarly to
|
|
|
|
`rWrapper`:
|
2017-01-27 23:54:50 +00:00
|
|
|
|
|
|
|
```nix
|
|
|
|
{
|
|
|
|
packageOverrides = super: let self = super.pkgs; in
|
|
|
|
{
|
|
|
|
|
2017-05-01 13:59:43 +01:00
|
|
|
rstudioEnv = super.rstudioWrapper.override {
|
2017-04-21 19:00:32 +01:00
|
|
|
packages = with self.rPackages; [
|
2017-05-01 13:59:43 +01:00
|
|
|
dplyr
|
2017-01-27 23:54:50 +00:00
|
|
|
ggplot2
|
|
|
|
reshape2
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Then like above, `nix-env -f "<nixpkgs>" -iA rstudioEnv` will install
|
|
|
|
this into your user profile.
|
|
|
|
|
2016-02-22 07:52:22 +00:00
|
|
|
## Updating the package set
|
|
|
|
|
|
|
|
```bash
|
2017-02-22 04:48:50 +00:00
|
|
|
nix-shell generate-shell.nix
|
|
|
|
|
2016-02-22 07:52:22 +00:00
|
|
|
Rscript generate-r-packages.R cran > cran-packages.nix.new
|
|
|
|
mv cran-packages.nix.new cran-packages.nix
|
|
|
|
|
|
|
|
Rscript generate-r-packages.R bioc > bioc-packages.nix.new
|
|
|
|
mv bioc-packages.nix.new bioc-packages.nix
|
|
|
|
```
|
|
|
|
|
|
|
|
`generate-r-packages.R <repo>` reads `<repo>-packages.nix`, therefor the renaming.
|
|
|
|
|
|
|
|
|
|
|
|
## Testing if the Nix-expression could be evaluated
|
|
|
|
|
|
|
|
```bash
|
|
|
|
nix-build test-evaluation.nix --dry-run
|
|
|
|
```
|
|
|
|
|
|
|
|
If this exits fine, the expression is ok. If not, you have to edit `default.nix`
|