To be a good programmer/bioinformatician, you have to be a little bit lazy.   You need to get tired of doing tasks manually and know that putting some amounts of effort now will pay off later.  Laziness sometimes makes your more efficient and productive!

For example, if you are tired of loading the same R packages manually everytime you open a new session or copy/pasting the required lines of code from script to script, there’s a way to tell R to load them when starting up.  The trick is to create or modify your .Rprofile file.   The .Rprofile file goes in your home directory.  It contains a function .First which is executed when R starts.  You can load all the package that you often use in this section.  .Last is for operations that you want R to do before leaving.  The simplest .Rprofile file can have only a .First and a .Last function.  But you can also set options in there.  

My .Rprofile looks like this :

.First <- function() {
cat("\nWelcome at", date(), "\n")
.Last <- function(){
cat("\nGoodbye at ", date(), "\n")

To know if the packages were loaded properly, call function sessionInfo() and see if they are listed or, if you're using RStudio, see if they are checked.  As always with R, you can do ?Rprofile to get more information.  So be lazy and update your .Rprofile

Edited : If you see a weird error message when installing a package with dev_tools, it might be caused by the cat () message…

By | 2014-09-19T11:11:43+00:00 March 14, 2014|Categories: R|0 Comments

About the Author:

I’ve started in biochemistry but it is as a bioinformatician that I’ve been having fun for several years now : whether doing data analysis and visualization in R, building interactive web interfaces in javascript or exploring machine learning in python.

Leave A Comment