Download presentation
Presentation is loading. Please wait.
Published byLeslie Ellis Modified over 9 years ago
1
How to create and install packages in R Presenter: Roman Jandarov (raj153@psu.edu)
2
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)
3
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)
4
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) }
5
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")
6
How to run R CMD commands? (preparation) 1. Perl: http://www.activeperl.com/ 2. MinGW: http://www.mingw.org/http://www.mingw.org/ 3. Cygwin: http://www.cygwin.com/ 4. Mixtex: http://www.miktex.org/http://www.miktex.org/ 5. Microsoft HTML Help Downloads: http://msdn2.microsoft.com/en- us/library/ms669985.aspx
7
Important Notes: 1. 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) 2. You can download Rtools which replaces first three programs: http://www.murdoch- sutherland.com/Rtools/Rtools.exehttp://www.murdoch- sutherland.com/Rtools/Rtools.exe (Includes Perl, MinGV(Part), Cygwin(Part))
8
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.