I am trying to set a variable for ESS. This is how I load ESS:

;; ess / try to not (require 'ess-site) as it slows down start-up
(autoload 'R-mode "ess-site.el" "Major mode for editing R source." t)
(autoload 'Rd-mode "ess-rd" "Major mode for editing R documentation." t)
(add-to-list 'auto-mode-alist '("\\.[rR]\\'" . R-mode))
(add-to-list 'auto-mode-alist '("\\.[Rr]out" . R-transcript-mode))
(add-to-list 'auto-mode-alist '("\\.Rd\\'" . Rd-mode))
(add-to-list 'interpreter-mode-alist '("Rscript" . R-mode))
(add-to-list 'interpreter-mode-alist '("r" . R-mode))

I tried

(eval-after-load "ess"
     (setq inferior-R-args "--no-save --quiet")))

(eval-after-load "ess-site"
     (setq inferior-R-args "--no-save --quiet")))

(add-hook 'ess-mode-hook
          (lambda ()
            (setq inferior-R-args "--no-save --quiet")))

(setq inferior-R-args "--no-save --quiet")

(setq-default inferior-R-args "--no-save --quiet")

But none works. When ESS starts, the value of inferior-R-args is "". Any ideas?

  • Did you restart Emacs after making these changes? Sorry, just trying to get the obvious out of the way. Did you actually evaluated the setq form? I.e. did you C-x e on it? (Alternatively, you could C-: (setq inferior-R-args "--no-save --quiet"). – wvxvw Apr 12 '15 at 20:29
  • 1
    Yes, I did restart. If I evaluate inferior-R-args in the *scratch* buffer after starting Emacs, I get void variable. If I evaluate the setq form in *scratch* and then start ESS, everything works as expected. But the setq in the init file does nothing. Strange... OK mystery solved, I had an init.elc lying around. – Ernest A Apr 12 '15 at 20:42
  • Well, you need to setq only after that variable is declared somewhere with defvar or similar. So, I'd try to first (require 'ess) or (require 'ess-site), (I think the later should load the variable declaration), and then to setq it. – wvxvw Apr 12 '15 at 20:44
  • It's not necessary, you can setq before defvar. I don't know if it's a recent feature but it works. – Ernest A Apr 12 '15 at 20:59
  • Yes, it's not necessary, but it may have a different effect. The code initializing the variable my try to check for previous values. Or, there can be other code that runs assuming the variable hadn't been initialized yet and so on. So, just to make sure, I'd wait for the library to load and only then tried to customize it. – wvxvw Apr 13 '15 at 5:52

inferior-r-args is a customization variable, so you can edit it via M-x customize-variable inferior-r-args.

ESS is a fairly complex package, and figuring out the timing for modifying variables can be a bit tricky - easier to use the customize facility when possible!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.