In R, I like to use reverse search (ctrl+r) to redo infrequent but complex commands without a script. Frequently, I will do so many other commands in between that the command history discards the old command. How can I change the default length of the command history?
If you are using RStudio on top of your R distro, CTRL + UP will give you the list of all previous commands.
You can save the output in the history window by clicking on the save button using a *. r extension on your file so that the file can be automatically opened in R. (You can similarly have a written record of your commands by using the script window and saving a file with the commands that you created.)
1 The History Tab. 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.
This is platform and console specific. From the help for ?savehistory
:
There are several history mechanisms available for the different R consoles, which work in similar but not identical ways...
...
The history mechanism is controlled by two environment variables: R_HISTSIZE controls the number of lines that are saved (default 512), and R_HISTFILE sets the filename used for the loading/saving of history if requested at the beginning/end of a session (but not the default for these functions). There is no limit on the number of lines of history retained during a session, so setting R_HISTSIZE to a large value has no penalty unless a large file is actually generated.
So, in theory, you can read and set R_HISTSIZE
with:
Sys.getenv("R_HISTSIZE")
Sys.setenv(R_HISTSIZE = new_number)
But, in practise, this may or may not have any effect.
See also ?Sys.setenv
and ?EnvVar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With