Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the script/source history in RStudio?

Tags:

r

rstudio

I would like to access the history of what have been typed in the source panel in RStudio.

I'm interested in the way we learn and type code. Three things I would like to analyse are: i) the way a single person type code, ii) how different persons type code, iii) the way a beginner improve typing.

Grabbing the history of commands is quite satisfying as first attempt in this way but I would like to reach a finer granularity and thus access the successive changes, within a single line in a way.

So, to be clear, I'm neither looking for the history of commands or for a diff between different versions of and .R file.

What I would like to access is really the successive alterations to the source panel that are visible when you recursively press Ctrl+Z. I do not know if there is a more accurate word for what I describe, but again what I'm interested in is how bits of code are added/moved/deleted/corrected/improved in the source panel but not necessary passed to the Console and thus absent from the history of command.

This must be somewhere/somehow saved by RStudio as it is accessible by the later. This may be saved in a quite hidden/private/memory/process/... way and I have a very vague idea of how a GUI works. I do not know it if would be easily accessible, then programmaticaly analyzed, typically if we could save a file from it. Timestamps would be the cherry on top but I would be happy without.

Do you have idea how to access this history?

like image 841
Vincent Bonhomme Avatar asked Jun 08 '16 15:06

Vincent Bonhomme


People also ask

How do I view history in RStudio?

2.4. In the upper right pane of R Studio, you'll see the Environment and History pane. Click on the History tab, and you should see a history of all of the commands that you have sent to the R console in this session. Figure 2.8: Notice the code in the History tab.

What is the use of history () in R?

The command history() will recall the last 25 used commands, whereas history(max. show=Inf) will get back all previous ones. If you are using RStudio on top of your R distro, CTRL + UP will give you the list of all previous commands.


1 Answers

RStudio's source panel is essentially a view to an Ace Editor. As such you'd need to access the editor session's editSession and use getDocument or getWordRange along with the undo of the editSession's undoManager instance.

I don't think you'll be doing that from within RStudio without hacking on the RStudio code unless the RStudio Addin api is made to pass-thru editor events in the future.

It might be easier to write a session recorder as changes are made rather than try to mess with the undo history. I imagine you could write an Addin that calls a javascript to communicate over the existing RStudio port using the Ace Editor's events (ie. onChange).

like image 102
Thell Avatar answered Sep 20 '22 05:09

Thell