IHaskell example has problem (MASS package missing)
djsamperi opened this issue · comments
Describe the bug
The last graph in the demo tutorial-ihaskell-inline-r.ipynb fails (crashes the kernel).
Running it directly using 'stack --nix exec R' shows that the MASS package is missing.
To Reproduce
Just execute the ipynb file.
Expected behavior
Executing the last cell should produce a graph.
Environment
- Ubuntu Linux 22.04
- HaskellR v1.0.0
Additional context
The example works if run in the version of R that is not part of Nix, so
Nix configuration seems to have a problem.
The above reminded me that when I use R with packages in nix, not only do I have to have a special R with the required nix package but I also have to set up various environment variables.
Something like
R-with-my-packages = pkgs.rWrapper.override{
packages = with pkgs.rPackages; [
ggplot2
ggridges
outbreaks
tidyverse
(buildRPackage {
name = "smcsamplers";
src = pkgs.fetchFromGitHub {
owner = "pierrejacob";
repo = "smcsamplers";
rev = "097192f7d5df520d9b026d442dfec493a3051374";
sha256 = "00facn1ylcbai4sbcidpp991899csz2ppmmkv0khvqxfncddr0f2";
};
propagatedBuildInputs = [ coda MASS mvtnorm loo shape rstan tidyverse doParallel igraph ggraph doRNG reshape2 ];
})
]; };
and
pkgs.stdenv.mkDerivation {
name = "xxx";
buildInputs = [
pkgs.libintlOrEmpty
R-with-my-packages
pkgs.pandoc
pkgs.cabal-install
pkgs.inkscape
pkgs.texlive.combined.scheme-full
(pkgs.myHaskellPackages.ghcWithPackages haskellDeps)
];
shellHook = ''
R_LIBS_USER=$(Rscript -e ".libPaths()" | cut -c 6- | sed 's/[ \t]*$//' | sed 's/"//g' | sed -z 's/\n/:/g;s/:'''$/\n/' | sed 's/ //g')
export R_LIBS_USER
'';
}
but do not use my mess of sed - it worked for me on that occasion because something was 6 characters long.
If you don’t set this up then inline-r looks in the wrong place for R packages.
Thanks for the bug report!
I just made a VM on Ubuntu 20.04 and also got a missing package (in my case, ggplot
). I'll see what I can do!
EDIT: I also tried stack --nix exec jupyter notebook
from within nix-shell
and the issue still occurs. I'll try @idontgetoutmuch's suggestion of modifying R_LIBS_USER
next.
I found a fix (actually, I found this fix years ago). In shell.nix, add the following to buildInputs...
rPackages.MASS
rPackages.ggplot2
@djsamperi can you verify that the example notebook runs without rPackages.MASS
?
On Ubuntu 20.04, I was able to use
stack --nix exec -- jupyter nbconvert --to notebook --inplace --execute ./IHaskell/examples/tutorial-ihaskell-inline-r.ipynb
and the notebook ran successfully/regenerated the graphs (without need MASS
).
I'll add rPackages.ggplot2
to the shell.nix
file the example works.
You are probably correct, rPackages.MASS is not needed, as my notes on this do not include this.
The MASS R package should be automatically installed.