R Packages Not Available via Nix?
idontgetoutmuch opened this issue · comments
idontgetoutmuch commented
I have
let
rOverlay = rself: rsuper: {
myR = rsuper.rWrapper.override {
packages = with rsuper.rPackages; [
ggplot2
dplyr
xts
purrr
];
};
};
haskellOverlay = hself: hsuper: {
my-inline-r = hself.haskell.lib.dontCheck (hsuper.haskellPackages.inline-r);
};
in
let
pkgs = import <nixpkgs> { overlays = [ rOverlay haskellOverlay ]; };
h = pkgs.haskellPackages.extend (self: super: {
nz-inline-r = pkgs.haskell.lib.dontCheck super.inline-r;
});
in
pkgs.mkShell {
buildInputs = [
pkgs.myR
(h.ghcWithPackages (p: [ (p.nz-inline-r) ]))
];
}
nix-shell bar.nix -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.03.tar.gz
[nix-shell:~/nix2]$ ghci -fno-ghci-sandbox
GHCi, version 8.6.4: http://www.haskell.org/ghc/ :? for help
Prelude> :set -XQuasiQuotes
Prelude> :set -XTemplateHaskell
Prelude> import qualified Language.R as R
Prelude R> import Language.R.QQ
Prelude R Language.R.QQ> R.runRegion $ do _ <- [r| print(pi) |]; return ()
[1] 3.141593
Prelude R Language.R.QQ> R.runRegion $ do x <- [r| loadedNamespaces() |]; [r| print(x_hs) |]; return ()
[1] "compiler" "graphics" "utils" "grDevices" "stats" "datasets"
[7] "methods" "base"
Prelude R Language.R.QQ> R.runRegion $ do x <- [r| library(dplyr) |]; [r| print(x_hs) |]; return ()
*** Exception: R Runtime Error: Error in library(dplyr) : there is no package called ‘dplyr’
Prelude R Language.R.QQ> import System.Process
Prelude R Language.R.QQ System.Process> r <- createProcess (proc "which" ["R"])
Prelude R Language.R.QQ System.Process> /nix/store/rs8l60kcfbz2jbq5g4b75n82jvlpjydm-R-3.5.2-wrapper/bin/R
OTOH
[nix-shell:~/nix2]$ R
R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.7.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> loadedNamespaces()
[1] "compiler" "graphics" "utils" "grDevices" "stats" "datasets"
[7] "methods" "base"
> library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
and
[nix-shell:~/nix2]$ which R
/nix/store/rs8l60kcfbz2jbq5g4b75n82jvlpjydm-R-3.5.2-wrapper/bin/R
idontgetoutmuch commented
This seems to work
{ nixpkgs ? import <nixpkgs> {} }:
let
haskellDeps = ps: with ps; [
(nixpkgs.haskell.lib.dontCheck inline-r)
];
in
nixpkgs.stdenv.mkDerivation {
name = "env";
buildInputs = [
(nixpkgs.haskellPackages.ghcWithPackages haskellDeps)
nixpkgs.R
nixpkgs.rPackages.dplyr
];
}