Is there a way to install R packages using emacs?
Asked Answered
S

4

7

I am using ESS, but every time I need to install a new package I have to use R gui. Isn't there a way to do this without leaving emacs?

Sinful answered 8/7, 2011 at 20:39 Comment(5)
Why can't you use install.packages?Jarrodjarrow
R process hangs when it prompts to select mirror.Sinful
So set a mirror in your ~/.R/ files. Or as a argument to install.packages. Seems like a PBKAC.Lugo
I suspect your R doesn't have tcltk. R fails to pop up a cran chooser and tries to get input from the keyboard. what does capabilities() tell you?Trave
No need to be rude about the work of others via comments ad hominen.Buddhi
T
8

C-c C-e i

It will take a few seconds to load all packages.

Tupler answered 8/2, 2014 at 9:18 Comment(0)
L
9

From help(Startup):

 ## Example of Rprofile.site
 local({
   # add MASS to the default packages, set a CRAN mirror
   old <- getOption("defaultPackages"); r <- getOption("repos")
   r["CRAN"] <- "http://my.local.cran"
   options(defaultPackages = c(old, "MASS"), repos = r)
   ## (for Unix terminal users) set the width from COLUMNS if set
   cols <- Sys.getenv("COLUMNS")
   if(nzchar(cols)) options(width = as.integer(cols))
 })
Lugo answered 8/7, 2011 at 20:55 Comment(0)
T
8

C-c C-e i

It will take a few seconds to load all packages.

Tupler answered 8/2, 2014 at 9:18 Comment(0)
A
2

http://www.emacswiki.org/emacs/anything-R.el works well for me.

Avens answered 10/7, 2011 at 12:12 Comment(4)
Thanks for the pointer about 'anything', the Emacs Wiki entry is interesting. Yet another mode to try...Lugo
Thanks, I use anything, but did not know about anything-R. So once installed, which command should I use? I tried a few obvious choices such as "install package", but did not see anything promising.Sinful
@Sinful You need to define a function and then call it like:` (defun orp-R-anything () (interactive) (anything-other-buffer '( anything-c-source-R-local anything-c-source-R-help ;; anything-c-source-R-localpkg ;; anything-c-source-R-repospkg ) " R-anything")) 'Avens
Hmm, that can't be the "real" answer (@Otto), as the anything-R.el file explicitly contains functionality for install.packages()Scoot
C
2

If you don't remember the shortcut for package setup, you can go through the Handy commands main menu.

If you type , in the inferior R buffer as the first character (i.e. at the process marker), you trigger the handy commands menu in the minibuffer, like in the following figure:

install-pack

Note how you can interactively select menu items by typing the initial characters (like with Emacs isearch). Of course you can simply use the arrows.

Select install.packages (typing i followed by enter should be enough).

In the subsequent menu, you are presented with the CRAN mirror list:

CRAN mirror list

Select a convenient mirror. ESS will fetch the available packages

Fetch the available packages

You are then presented with the list of installable packages.

installable packages

Select the one that you need and you are done.

Note that the second time you install a package in the current session you are not requested to reselect the mirror.

If you are not familiar with ESS handy commands, you might find here many other commands very ... well handy. Particularly, as regards the subject matter here, the library command might help, because you can enjoy auto-completion, useful also when you need to load a package, but you do not remember its spelling.

You might want to use the standard R GUI dialogues from Emacs. In this case, at least in Windows, to display properly the dialogue boxes, use:

library('tcltk')
install.packages()
Charest answered 10/10, 2016 at 21:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.