Biotech 🦠, startups 🚀, tech 👨‍💻

My R Profile

Towards the end of my PhD I started to get really into R. During my undergraduate degree at the University of Leeds my whole class were really heavy users of Origin Pro which is a really great plotting tool with an easy to use GUI. Though the only real taste of programming during that period was the use of Maple for one practical.

Most of my data during my PhD was based on micrographs so numeric data was difficult to extract, eventually I started doing more spectroscopy and I needed to start doing more analysis and visualisation. Now whenever I have data processing work to do I turn to R, even now at Dentally. I thought it would be cool to share my R profile file which is copied and altered from a handful of different sources

All of it is pretty self explanatory but just to highlight that I load the colorout package that colours the text in the terminal window. In addition dplyr and ggplot2 are loaded at startup as I use these religiously. Additionally there is a set column width function which makes data output in the terminal so much more readable.

# My .Rprofile

# Create a new invisible environment for all the functions to go in so it doesn't clutter your workspace
.env <- new.env()

# aliases
s <- base::summary
h <- utils::head
n <- base::names

# Set terminal width
wideScreen <- function(howWide=Sys.getenv("COLUMNS")) {

# options

## Read data on clipboard.
.env$read.cb <- function(...) {
  ismac <-[1]=="Darwin"
  if (!ismac) read.table(file="clipboard", ...)
  else read.table(pipe("pbpaste"), ...)

## Attach all the variables above

## .First() run at the start of every R session.
## Use to load commonly used packages?
.First <- function() {
  # library
  setOutputColors256(normal = 70, number = 56, negnum = 56, date = 56, string = 179, const = 202, verbose = FALSE)
	cat("\nSuccessfully loaded .Rprofile at", date(), "\n")

## .Last() run at the end of the session
.Last <- function() {
	# save command history here?
	cat("\nGoodbye at ", date(), "\n")

I hope some of you find it useful, I know I will when I accidentally delete my .Rprofile!