80 likes | 196 Views
How to create and install packages in R. Presenter: Roman Jandarov (raj153@psu.edu). How to create a package?. Create the structure for a new package By package.skeleton() function or By creating each folder of the package Read Read-and-Delete Files Put any C/C++/Fortran code in 'src‘
E N D
How to create and installpackages in R Presenter: Roman Jandarov (raj153@psu.edu)
How to create a package? • Create the structure for a new package • By package.skeleton() function or • By creating each folder of the package • Read Read-and-Delete Files\ • Put any C/C++/Fortran code in 'src‘ • Edit the help file skeletons in 'man‘ (Note: to be able to compile easily, create your package structure in R’s bin folder)
Run R CMD build to create the index files • Run R CMD check to check the package • Run R CMD build to make the package file (Later about how to use this commands)
Example (Create a structure): rmixnorm<-function(n,p=1,mu=0,sigma=1){ if(sum(p)!=1)stop("Sum(p) should be = 1") if(sum(p*mu)!=0)stop("Sum(p*mu) should be = 0") x=numeric(n) for(i in 1:n){ …(omitted) } x[i]=sqrt(sigma[j])*rnorm(1)+mu[j] } return(x) }
med.method<-function(x,y){ mid=(min(x)+max(x))/2 x1=x[x<mid] x2=x[x>=mid] y1=y[x<mid] y2=y[x>=mid] … return(l=list(slope=slope, intercept=intercept)) } mydata=rnorm(100) package.skeleton(list=c("med.method","rmixnorm","mydata"), name="stat597c")
How to run R CMD commands?(preparation) • 1. Perl: http://www.activeperl.com/ • 2. MinGW: http://www.mingw.org/ • 3. Cygwin: http://www.cygwin.com/ • 4. Mixtex: http://www.miktex.org/ • 5. Microsoft HTML Help Downloads: http://msdn2.microsoft.com/en-us/library/ms669985.aspx
Important Notes: • After Installing this programs, do not forget to change the PATH variable of your system. (You should add path to these software's’ bin folders by clicking right mouse button on My Computer->Properties->Advanced->Environmental Variables->PATH->Edit) • You can download Rtools which replaces first three programs: http://www.murdoch-sutherland.com/Rtools/Rtools.exe (Includes Perl, MinGV(Part), Cygwin(Part))
How to run R CMD commands?(usage) • Launch Command line • Change the current directory to bin folder of R (cd c:\Program Files\R\R-2.5.1\bin) • For help: R CMD --help R CMD command --help