Bioinformin.net




Links

  • R functions - stat.berkeley's nice intor to functions, scoping, environments.


Slides


R_intro 1

R_intro 2

R_intro 3

R_intro 4

R_intro 5 ( flow_data.txt, R_intro_5.R )

R_intro 6

R_intro 7

R_intro 8














R tips

GUIs for R


"No-saving" R


To axiomatically run R as R --no-save, so that it doesn't ask about workspace save option before quiting do:

  • In terminal run: sudo gedit .bashrc
  • In this file uncomment the right part to get:
    if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
    fi
  • Close and again in terminal: sudo gedit .bash_aliases
  • In this file add line: alias R='R --no-save'
  • Close, done. [Based on Allan Engelhardt note in CYBAEA]

Save R history


To automaticaly save/load commands history:

  • In terminal run: sudo gedit .bashrc
  • There add line:
    export R_HISTFILE=~/.Rhistory
  • Close and in .Rprofile file add lines:
    .Last <- function() {
      if (!any(commandArgs()=='--no-readline') && interactive()){
        require(utils)
        try(savehistory(Sys.getenv("R_HISTFILE")))
      }
    }
  • Close, done. [Based on Jeffrey Horner's advice on stackoverflow]

Speed up R


See: Måns Thulin's blog post:


slow fast
system.time( for(i in 1:1000000) { 1*(1+1) } ) system.time( for(i in 1:1000000) { 1*{1+1} } ) {} instead of ()
system.time( for(i in 1:10000000) 3^2 ) system.time( for(i in 1:10000000) 3*3 ) * instead of ^
system.time( for(i in 1:100000) { a<-NA; for(j in 1:100) a[j]<-j }) system.time( for(i in 1:100000) { a<-vector(length=100); for(j in 1:100) a[j]<-j }) allocate vectors for loops
x<- rnorm(50)
system.time(for(i in 1:100000){mean(x)})
x<- rnorm(50)
system.time(for(a in 1:100000) .Internal(mean(x)))
internal mean when you are sure it's numbers



Where R sit on Ubuntu (as of Oneiric):

  • /usr/local/bin … R executable (has the R_HOME_DIR setting). Is this standard?
  • /etc/R … Rprofile, Renviron, etc.
  • /usr/lib/R … base-R, recommended pckgs
  • /usr/lib/R/site-library … debian-packed pckgs or ?
  • /usr/share/R … architecture independent files (e.g. doc?)
  • /usr/local/lib/R/site-library … user installed pckgs or ?


Misc.


And don't forget to DRY KISS.


CRAN packages



Yet more Hadley (thanks Tom):




This does not belong here, move it: Designing projects