Efficient R Programming

http://bioconductor.org/help/course-materials/2010/BioC2010/EfficientRProgramming.pdf

Note however that Netcdf4 is available for windows contrary to what is presented in these slides

Having just gone through this, here are my notes:

Starting from

 http://www.unidata.ucar.edu/software/netcdf/docs/faq.html#windows_netcdf4

download

ftp://ftp.unidata.ucar.edu/pub/netcdf/contrib/win32/netcdf-4.0_dlls_snapshot2008092909.zip
 ftp://ftp.unidata.ucar.edu/pub/netcdf/contrib/win32/5-181-win-vs2005.zip

(or wherever it points to - im sure there will be updates)

Unzip those and copy the following dlls to a directory in your PATH or 
LD_LIBRARY_PATH:

Netcdf4 DLLs:
 netcdf.dll

HDF5 DLLs:
 hdf5_hldll.dll         
 hdf5dll.dll

(also see http://www.hdfgroup.uiuc.edu/windows/faq.html)

Go to ftp://ftp.hdfgroup.org/lib-external/ and get the szip and zlib DLLS. I 
took

ftp://ftp.hdfgroup.org/lib-external/szip/2.1/bin/windows/szip21-vs2005-enc.zip
ftp://ftp.hdfgroup.org/lib-external/zlib/1.2/bin/windows/?? (missing - i have 
reported to THG)

Or get zlib from http://www.winimage.com/zLibDll/.

unzip to get:

 szlibdll.dll  
zlib1.dll

These also depend on Microsoft DLLs (typically found in C:\WINDOWS\system32), 
but they will already be in your path:
 kernel32.dll           
 msvcr80.dll            
 msvcrt.dll             
 ntdll.dll              

All of these DLLs are pure win32 "unmanaged code", as opposed to .Net "managed 
code". win32 will work on both 32 bit and 64 bit systems
Posted in Uncategorized | Leave a comment

Read excel data in format code|year|month|daysx31| to make ts

#get|excel|data
library(gdata)
 dat<-read.xls("C:/All.xls",sheet=2);dat[dat==999]<-NA
 stdata<-function(sname,scode,dat,prm) #dat= df(scode|year|mon|X1:X31 )
 {
 require(zoo)
 stnobj<-dat[which(dat[,1]==scode),]|#subset
 vals<-c(t(as.matrix(stnobj[,4:34]))|)#values
 dates<-matrix(rep(1:31,dim(stnobj)[1]),dim(stnobj)[1],31,byrow=T)
 for(i|in|1:dim(stnobj)[1]){for(j|in|1:31){dates[i,j]<-paste(stnobj[i,2],stnobj[i,3],dates[i,j],sep="-")}}
 dates<-as.Date(c(t(dates)))
 idt<-which(!is.na(dates))
 dates<-dates[idt]
 vals<-vals[idt]
 stnobj.prec<-zoo(vals,dates)
 return(stnobj)
 }
Posted in Uncategorized | Leave a comment

Quick R & R plot margins

http://www.statmethods.net/advstats/matrix.html

http://rgraphics.limnology.wisc.edu/rmargins_layout.php

Posted in Uncategorized | Leave a comment

R auto complete in notepad++

http://yihui.name/en/2010/08/auto-completion-in-notepad-for-r-script/

Auto-completion is fancy in a text editor. Notepad++ does not support auto-completion for the R language, so I spent a couple of hours on creating such an XML file to support R:

Download: R.xml (938Kb)

Put it under ‘plugins/APIs‘ in the installation directory of Notepad++ (you can see several other XML files there supporting different languages such as C), and make sure you have enabled auto-completion in Notepad++ (Settings --> Preferences --> Backup/Auto-completion). Open an R script and start typing a familiar function (e.g. paste()), you will see some candidates in a drop-down list like this:

Show parameters of R functions in Notepad++Show parameters of R functions in Notepad++

Hit the Enter key if the function name selected in the list is correct for you, then type ‘(‘ and you will see hints for parameters:

Auto-completion in Notepad++ for R scriptAuto-completion in Notepad++ for R script

The file R.xml was actually generated from R; it contains almost all visible R objects in base R packages as well as recommended packages like MASS. You may create an extended XML file (containing keywords from other packages) by yourself after loading the packages you need into your current workspace, and run:

1
2
# R.xml will be generated under your current work directory: getwd()
Posted in Uncategorized | Leave a comment

R and Google Earth: Animation

http://blog.revolutionanalytics.com/2010/08/how-to-animate-google-earth-with-r.html

Posted in Uncategorized | Leave a comment

R syntax highlighting on WordPress blogs

open-square-bracket sourcecode language="r" close-square bracket
R_code
open-square-bracket/sourcecode close-square-bracket
 
test.function = function(r) {return(pi * r^2)}
test.function(1)
Posted in Uncategorized | 1 Comment

my R

Thought it a good thing to share knowledge on R from myself and others

Enjoy

Posted in Uncategorized | 1 Comment