Export output and command lines in R [duplicate] - r

Is there an easy way to have R record all input and output from your R session to disk while you are working with R interactively?
In R.app on Mac OS X I can do a File->Save..., but it isn't much help in recovering the commands I had entered when R crashes.
I have tried using sink(...,split=T), but it doesn't seem to do exactly what I am looking for.

Many of us use ESS / Emacs for this very reason. Saving old sessions with extension '.Rt' even gives you mode-specific commands for re-running parts of your session.

Greg Snow wrote recently on the R-help list (a very valuable resource, SO R people!):
"You may also want to look at ?TeachingDemos::txtStart as an alternative to sink, one advantage is that the commands as well as the output can be included. With a little more work you can also include graphical output into a transcript file."
r-help

Check out the savehistory() command

I'm not sure yet how to answer an answer, but there is an updated version of Ranke's vim r-plugin called r-plugin2 available here. It seems more user-friendly and robust than the original.

Emacs is good, but for those of us with a vi preference there's the vim-r plugin at:
http://www.uft.uni-bremen.de/chemie/ranke/index.php?page=vim_R_linux
It works brilliantly and has a tiny memory footprint.

Related

R - what are the R CMD Check arguments?

Is there a comprehensive list somewhere of what you can pass to R CMD CHECK? I don't see anything in the manual but it's brutal to read. It'd be great if every line of this output could be run independently or if I could at least skip some things but I don't see a comprehensive list describing how to do this.
Even better would be something I could use like
check_dependencies()
check_executable_files()
check_hidden_files()
For context, I had a note about large file sizes that was hard to debug (it was plotly using it's full JS library in my vignettes) and devtools::check() took 3 minutes each time I ran it.
As rawr# points out, the "official" answer is to run R CMD check --help, which will give the most accurate results for the version of R you are running.
Still, it is surprisingly difficult to find this info online. It would be nice not to need the terminal to look this up... so I'm filing this answer with some pointers in the right direction for anyone else that manages to Google their way to this Q&A:
This permalink highlights the documentation as of this writing, but that will stale as the function evolves.
tools/R/check.R is the correct file at HEAD; search for "Usage <- function", where the contents of R CMD check --help are maintained. (in principle, this could also change, but this anchor has remained accurate for the entire 12-year history of the R implementation of R CMD check)

Rgui command-line for sourcing R file

What command line option to use behind Rgui.exe for immediately sourcing an R source file? Instead of having to type source("c:\MyGreatSource.R") manually afterwards. Something like:
Rgui.exe --source "c:\MyGreatSource.R"
Sounds like a simple question answered in any beginner's manual, but I couldn't find such an option anywhere.
I found a workable solution, maybe others are interested. Again, what I like to do is to start the Rgui and work there. All my work environment and functions are defined in an R source file, which I constantly develop further during working. So each of my commands in the GUI starts with Load1(); where Load1 is a function which simply sources my R file, to update the changes I have just made. Obviously, Load1 is also defined in my R file, so I need to get it in the first place, without much effort. I have set the command-line options for neither loading nor saving the workplace; I don't like my old mess from the previous session with test variables and so.
However, my solution now is to just create a workplace RData file which only contains the definition of my Load1 function. This workplace file is easily loaded at every start by just adding its path into the command-line options "D:\MyLoad1.RData"
I use a AutoHotkey Script
run,C:\Program Files\R\R-3.3.3\bin\x64\Rgui.exe
WinWait,RGui (64-bit)
WinWaitActive,RGui (64-bit)
Sleep 100
Send,source("%1%")
Send,{enter}

ESS and RScript : Executing in style of `compile-dwim-run'

I just got ESS set up in EMACS (I'm a relative newbie in this area). I have figured out how to take an R script and fire up an interactive R shell and evaluate a whole buffer ("C-c C-b"). But I'd also like to have the ability to submit an R script via RScript in the way that you can with Perl or Python with `compile-dwim-run', which I have bound to "C-c r", and have the whole output returned to me in a separate buffer without keeping open an interactive R shell.
I can't seem to find a default way to do this, and I'd like to leverage whatever ESS has to work that (I assume there is) before I go off and attempt to roll my own.
Thank you,
Matt
C-c C-l is what you are looking for? Use C-c C-h to see all the keys that are bound on C-c map (an even better approach is to install helm-descrbind from emacs package manager - you will be pleasantly surprised :).
[edit:] Sorry, misread your post slightly. You want batch evaluation. That is not available for R. The reason, the analysis in R is usually a complex process which you don't want to execute again and again. So you keep your interactive session open and iteratively achieve what you want.
There have been talks inside ESS to add some batch functionality, but it seems like very few people really need that.

emacs ess crashes when trying to access h_elp

My emacs/ess session crashes when I try to access help. This happens if I have two packages loaded with the same functions; for example:
library(lubridate)
library(data.table)
?month
In Rgui interface pops out and asks to choose from which packages I want help. Emacs just crashes. Similar issues happens with install.packages, but there is a way to specify mirror Is there a way to install R packages using emacs?
Is there a similar trick with help?
Well, there is no full proof solution for time being as nobody really understands why these crashes happen. I assume you are on windows, right?
There are plans in ESS to completely internalize all the help (and other) calls in order not to depend on R dialogs. Hopefully in the next version.
For time being put this into your .Rprofile
tis <- utils:::index.search
formals(tis)[["firstOnly"]] <- TRUE
assignInNamespace("index.search", tis, "utils")
It basically makes help system to pick the first package with the found topic. In your case month help page in data.table package will be ignored. Not a big deal as common topic names are quite rare anyways.
I found out that starting library(tcltk) solves this problem. Menu appears even after it is called from emacs+ess. I added library(tcltk) to my Rprofile.site and now everything works great, install.packages() and accessing help when multiple packages load same function

maintaining an input / output log in R

Is there an easy way to have R record all input and output from your R session to disk while you are working with R interactively?
In R.app on Mac OS X I can do a File->Save..., but it isn't much help in recovering the commands I had entered when R crashes.
I have tried using sink(...,split=T), but it doesn't seem to do exactly what I am looking for.
Many of us use ESS / Emacs for this very reason. Saving old sessions with extension '.Rt' even gives you mode-specific commands for re-running parts of your session.
Greg Snow wrote recently on the R-help list (a very valuable resource, SO R people!):
"You may also want to look at ?TeachingDemos::txtStart as an alternative to sink, one advantage is that the commands as well as the output can be included. With a little more work you can also include graphical output into a transcript file."
r-help
Check out the savehistory() command
I'm not sure yet how to answer an answer, but there is an updated version of Ranke's vim r-plugin called r-plugin2 available here. It seems more user-friendly and robust than the original.
Emacs is good, but for those of us with a vi preference there's the vim-r plugin at:
http://www.uft.uni-bremen.de/chemie/ranke/index.php?page=vim_R_linux
It works brilliantly and has a tiny memory footprint.

Resources