Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to install R packages using emacs?

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?

like image 314
user443854 Avatar asked Jul 08 '11 20:07

user443854


People also ask

How do I use R in emacs?

Start up Emacs without a file argument - just type emacs & at the prompt. Now execute R-mode - enter M-x R Think of M-x as `execute' and `R' for R. Emacs will then ask you for your R Starting Directory - enter the directory where you want to create a new (or open an already existing one) .

How do I install R packages?

Open R via your preferred method (icon on desktop, Start Menu, dock, etc.) Click “Packages” in the top menu then click “Install package(s)”. Choose a mirror that is closest to your geographical location. Now you get to choose which packages you want to install.

How do I manually install an R package?

Go into R, click on Packages (at the top of the R console), then click on "Install package(s) from local zip files", then find the zip file with arm from wherever you just saved it. Do the same thing to install each of the other packages you want to install.


4 Answers

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))
 })
like image 165
Dirk Eddelbuettel Avatar answered Oct 04 '22 21:10

Dirk Eddelbuettel


C-c C-e i

It will take a few seconds to load all packages.

like image 44
Anusha Avatar answered Oct 01 '22 21:10

Anusha


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

like image 27
Otto Pichlhoefer Avatar answered Oct 02 '22 21:10

Otto Pichlhoefer


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()
like image 42
antonio Avatar answered Oct 03 '22 21:10

antonio