[Nix-dev] Developing R modules with nix

Peter Simons simons at cryp.to
Fri Sep 12 15:38:36 CEST 2014


Hi Michel,

 > Currently I have in my `.nixpkgs/config.nix` an entry with
 >
 >     rToolsEnv = pkgs.buildEnv {
 >         name = "rTools";
 >         paths = with rPackages; [
 >             devtools
 >             ggplot2
 >         ];
 >       };
 >
 > and I am installing it with `nix-env -i rTools`

interesting ... why do you prefer that approach? I would have used

  rWrapper = super.rWrapper.override {
    packages = with self.rPackages; [ devtools ggplot2 ]
  };

to install a variant of R that knows about these two packages.

 > Could I somehow fix the CRAN-mirror to use eg.  with
 > `cranMirror = "http://stat.ethz.ch/CRAN/src/contrib/"`

I am not aware of any way to customize the mirror list. The set of mirrors
for CRAN is hard-coded in pkgs/build-support/fetchurl/mirrors.nix, and the
function in pkgs/build-support/fetchurl/default.nix doesn't seem to offer a
way to modify those choices.


 > I'm looking for an example default.nix file, which I can put into my R-package
 > directory; could someone suggest me a common workflow for developing the R-package?

I'm not much of an R developer, so I cannot say much about this subject.
A default.nix that you could use to build your local project with Nix
is:

 | let
 |
 |   pkgs = import <nixpkgs> {};
 |   buildRPackage = import <nixpkgs/pkgs/development/r-modules/generic-builder.nix> pkgs.R;
 |
 | in
 |
 | with pkgs.rPackages;
 |
 | {
 |   foobar = buildRPackage {
 |     name = "your-package-name-1.0";
 |     src = ./.;
 |     propagatedBuildInputs = [/* required dependencies go here */];
 |   };
 | }

The command "nix-build . -A foobar" would then compile it.

I hope this helps,
Peter



More information about the nix-dev mailing list