【发布时间】:2018-07-12 17:17:39
【问题描述】:
我想将 ESS 与 R 的 nix 版本和我需要的包一起使用。
这是我可以通过 shell 执行的操作
nix-shell shell.nix -I nixpkgs=/Users/dom/nixpkgs --run R
shell.nix 确保我有 R 和可用的 R 包,而不必做install.packages。例如。我在 nix 中得到了 ggplot2 的版本:
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 有变量
inferior-R-program-nameinferior-R-args
这是我为 python 所做的,但请注意 python 模式有python-shell-process-environment,它允许我设置 NIX 环境变量。
'(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"))))
重复我最初的问题,我可以做些什么来说服 ESS 使用 R 的 nix 版本(和相关软件包)?
【问题讨论】:
-
您可能想使用nix-buffer 来运行由 Nix 构建的 Elisp。你可以用它把你的R环境放在
exec-path -
谢谢,但我不确定如何使用它。我把它放在包含我的 .R 文件的目录中:gist.github.com/idontgetoutmuch/…,然后执行
nix-buffer,但得到了nix-buffer--nix-build: Searching for program: No such file or directory, nix-build。在我在 shell 中使用 nix 之前,我会执行source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh所以在执行nix-buffer之前我可能需要做些什么? -
通过将
(exec-path-from-shell-initialize)放入我的.emacs中,我得到了一些进一步的信息,但现在我得到了nix-build for nix-buffer for mrp_script.R<Tidy> exited abnormally with code 1 with error output: error: Nix database directory ‘/nix/var/nix/db’ is not writable: Permission denied,我很确定这是由于没有设置NIX环境变量造成的。跨度> -
通过设置 NIX 环境变量,
nix-buffer运行完成,如果我再执行getenv PATH我可以看到它包含/nix/store/cz79yxnzsi2262i972pbfgvd93lf9y5k-R-3.4.3/bin:...但是如果我尝试通过 ESS 调用 R 我得到 @ 987654343@ 并且如果我执行 Mx shell 和echo $PATH那么包含 R 在 nix 中的位置的前缀不再是路径的前缀。 -
用
M-x shell打开一个常规的shell缓冲区,在那里运行你的nix-shell命令,然后运行M-x ess-remote并选择R。然后 ESS 会将此缓冲区识别为其交互式 R 会话。