I'd like to use ESS with the nix version of R and the packages I need.
Here's what I can do via the shell
nix-shell shell.nix -I nixpkgs=/Users/dom/nixpkgs --run R
shell.nix
ensures I have R and the R packages available without have to do install.packages
. E.g. I get the version of ggplot2 in nix:
R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.3.0 (64-bit)
> installed.packages()["ggplot2","LibPath"]
installed.packages()["ggplot2","LibPath"]
[1] "/nix/store/4nm5rs5d0ywpw7ksd0hblminim4kvnr0-r-ggplot2-2.2.1/library"
ESS has the variables
inferior-R-program-name
inferior-R-args
Here's what I did for python but note that python mode has python-shell-process-environment
which allows me to set the NIX environment variables.
'(python-shell-interpreter "/nix/var/nix/profiles/default/bin/nix-shell")
'(python-shell-interpreter-args
"-p \"callPackage /Users/dom/Dropbox/Tidy/mrp/dl.nix {}\" -I nixpkgs=/Users/dom/nixpkgs --run python")
'(python-shell-process-environment
(quote
("NIX_PROFILES=/nix/var/nix/profiles/default /Users/dom/.nix-profile" "NIX_REMOTE=daemon" "NIX_PATH=/nix/var/nix/profiles/per-user/root/channels" "NIX_SSL_CERT_FILE=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt" "NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/dom"))))
Repeating my original question, is there anything similar I can do to persuade ESS to use the nix version of R (and associated packages)?
Open a regular shell buffer with M-x shell, run your nix-shell command there, then do M-x ess-remote and select R. ESS will then recognize this buffer as its interactive R session.
NB You need to run R before M-x ess-remote.