A package (of my) Rprofile customisations. The goal is it broaden the package to be of use to other people.
You can install the development version from GitHub with:
# install.packages("remotes")
remotes::install_github("csgillespie/rprofile")
The package also uses two non-cran packages
# Used for nice prompts
remotes::install_github("gaborcsardi/prompt")
# Used for nice colours in the terminal
# Not for Windows
remotes::install_github("jalvesaq/colorout")
The R prompt has also been customised (using the prompt package):
A distinction needs to be made between the RStudio Console and the terminal. The console already has lots of nice features, e.g. syntax highlighting. So I have two separated functions.
Currently three start-up messages are displayed:
It’s always dangerous to load functions in your start-up script, so I’ve only included functions I’m fairly sure won’t be used in a script.
create_make_functions()
- if you have a Makefile
in your working directory, this will automatically generate all associated make functions. For example, if you have a force
argument in the Makefile
this will generate make_force()
lsos()
- a handy function for listing large objects
library()
- Over writes the library()
function with a smarter version. If a package is missing, automatically provides the option to install from CRAN or GitHub
last_error()
and last_trace()
- pre-loads from rlang. Nicer error investigation
op(path = ".")
- Creates & opens an RStudio project in the the directory specified
cp()
- Lists previous RStudio projects and gives an option to open.
inf_mr()
- Shortcut to xaringan::inf_mr()
.
options()
The set_startup_options()
function sets better (in my opinion) set of start-up options. These include
Ncpus
to run parallel installs by defaultI’ve also created a convenience function for adding additional R repositories - set_repos()
. Probably not needed by most people.
.Rprofile
Open your .Rprofile
, e.g. file.edit("~/.Rprofile")
and customise however you want. Here’s an example
# Set options for Rscript -e calls
if (requireNamespace("rprofile.setup", quietly = TRUE)) {
# Call here if needed
# rprofile.setup::set_repos()
::set_startup_options()
rprofile.setup
}
if (interactive() && requireNamespace("rprofile.setup", quietly = TRUE)) {
::create_make_functions()
rprofile.setup# Not RStudio OR RStudio console
if (rprofile.setup::is_terminal()) {
::set_terminal()
rprofile.setupelse {
} ::set_rstudio()
rprofile.setup
}= rprofile.setup::set_functions()
.env attach(.env)
# Display wifi and no of R sessions
# Linux only
::set_startup_info()
rprofile.setup
}
# Prints RStudio project on start-up
setHook("rstudio.sessionInit", function(newSession) {
= rprofile.setup::get_active_rproj()
active_rproj if (!is.null(active_rproj)) {
message(glue::glue("{crayon::yellow('R-project:')} {active_rproj}"))
}action = "append") },
The lsos()
function was taken from the SO question.
The improved version of library()
was adapted from the autoinst. I did think about importing the package, but I had made too many personal tweaks.
Setting the prompt uses the excellent prompt package.
I’ve probably “borrowed” some of the other ideas from blogposts and SO questions. If I’ve missed crediting you, please let me know and I’ll rectify it.