1 / 8

Creating and Installing Packages in R: A Comprehensive Guide

This guide outlines the essential steps to create and install R packages, focusing on package structure, coding practices, and using R CMD commands. It explains how to use the package skeleton function or manually create folders, integrate C/C++/Fortran code, and edit help files. Additionally, it covers the use of R CMD build and check commands for package management. Important notes about software tools and setting up environment variables are also provided, ensuring users have a seamless experience. Ideal for beginners and experienced users alike.

lorin
Télécharger la présentation

Creating and Installing Packages in R: A Comprehensive Guide

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to create and installpackages 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/ • 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

  7. 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))

  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

More Related