Ess to Call Different Installations of R

ESS to call different installations of R

ESS can start other versions of R, provided that it knows where on your system they are located. Pasted below is the relevant section from the ESS manual:

If you have other versions of R or
S-Plus available on the system, ESS is
also able to start those versions. How
this exactly works depend on which OS
you are using, as described in the
following paragraphs. The general
principle, regardless of OS, is that
ESS searches the paths listed in the
variable exec-path for R binaries. If
ESS cannot find your R binaries, on
Unix you can change the unix
environment variable PATH, as this
variable is used to set exec-path.

R on Unix systems: If you have
"R-1.8.1" on your exec-path, it can be
started using M-x R-1.8.1. By default,
ESS will find versions of R beginning
"R-1" or "R-2". If your versions of R
are called other names, consider
renaming them with a symbolic link or
change the variable ess-r-versions. To
see which functions have been created
for starting different versions of R,
type M-x R- and then hit [Tab]. These
other versions of R can also be
started from the "ESS->Start
Process->Other" menu.

How can I specify the R version opened by ESS session in emacs?

The non-ESS answer is to make sure your PATH is identical, and the version you want comes first. There appears to be difference between the shell you launch, and the launch involving Emacs. You could launch Emacs from your shell with its PATH.

The ESS answer probably involves setting some magic variable... On Windows we often set the binary directly. Here the lisp code says:

;; If you wish to call other versions of R on a Unix system, ESS
;; should auto-detect other versions of R, according to matches to the
;; variable `ess-r-versions' as described in its docstring. Consider
;; changing that variable rather than changing inferior-R-program-name
;; if your version of R is not already auto-detected.
;;(setq-default inferior-R-program-name "R") ; unix systems

so it should just work. I keep only R in my PATH, and another out of it so I can't test this here for you. But try fiddling with ess-r-version and/or inferior-R-program-name.

How can I load a server's specific R installation (environment module) when launching a local installation of emacs?

TL;DR

  1. Identify path of R module: module show R/3.0.1
  2. add to your .emacs: (add-to-list 'tramp-remote-path "/path/to/R-3.0.1/bin")

bash called by TRAMP via ssh does execute its initialization files but which files ultimately get executed depends on several things. You can check if your ~/.bashrc gets executed at all when you use TRAMP to connect to the server by adding something like echo "bashrc here" to the file. Then set variable

(setq tramp-verbose 9)

and try connecting. Now see if you can spot that message in a buffer called *debug tramp/ssh...*.

If you don't have any additional settings, TRAMP calls remote shell as /bin/sh (http://www.gnu.org/software/tramp/#Remote-shell-setup) so bash will execute /etc/profile and ~/.profile (http://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html#Bash-Startup-Files). You can also see how the shell is called in that *debug tramp/ssh...* buffer, the relevant line will be

tramp-open-shell (5) # Opening remote shell `/bin/sh'...done

Try adding the module load R/3.0.1 to ~/.profile first. If that does not help, try forcing TRAMP to call bash by its proper name by setting

(setq explicit-shell-file-name "bash")
(setq shell-file-name "bash")

UPDATE: If all else fails, you can just open shell M-x shell, then ssh to you server which should take care of the proper modules initialization (because you mentioned that interactive ssh connection works as expected). Once on the server, launch R and then do M-x ess-remote to make ESS aware of existing R session. This way you don't rely on TRAMP at all.

Display four lineChart() in different windows or simultaneously in R and ESS, quantmod

The quantmod plotting functions, nice and powerful as they are, will not respect par(c(mfrow())) or the equally nice (but less well-known layout()) so you have to create new plotting devices -- via x11() or window()-- and arrange them via your operating system / window manager.

For me:

R> x11(); lineChart(XAUUSD, subset='2018-03::2018-03')
R> x11(); lineChart(XAUUSD, subset='2018-04::2018-04')
R> x11(); lineChart(XPTUSD, subset='2018-03::2018-03')
R> x11(); lineChart(XPTUSD, subset='2018-04::2018-04')

yielded

Sample Image

and note that these are four distinct window. See dev.new() and dev.next() and those functions.

Is there a way to install R packages using emacs?

C-c C-e i

It will take a few seconds to load all packages.

Start a named ESS R process from a function

There are plenty of options that ess respects on startup. So emacs dynamic scope really helps here:

(defun jb-so ()
"Start R for StackOverflow layout"
(interactive)
(find-file "/tmp/so.R")
(let ((ess-ask-for-ess-directory nil)
(inferior-ess-same-window nil)
(ess-gen-proc-buffer-name-function (lambda (nm) "*RSO*")))
(R)
(pop-to-buffer "so.R")))

Note that this will work only in the recent versions of ESS that provide the facility to set custom names for process buffers (see ess-gen-proc-buffer-name-function). You can also rename inferior buffers with M-x rename-buffer.

Message error 'C:/Program' not found with glmmadmb() in R

The hack I employed so that EMACS/ESS could run the code was the following Sys.setenv() statement before the function call.

>   Sys.setenv(R_SHELL = "C:\\Windows\\system32\\cmd.exe")
> gaFP0<-glmmadmb(count~tx,
random=~(1|Feed)+(1 | Pint),
data=dnoNM,family="nbinom",zeroInflation=TRUE,
debug=TRUE)

Now glmmadmb() runs as expected. See the reasons as explained by Ross Boylan (this Q&A stackoverflow post was written with his permission).



Related Topics



Leave a reply



Submit