Step By Step Tutorial To Creating R Packages

1y ago
19 Views
2 Downloads
525.50 KB
20 Pages
Last View : 25d ago
Last Download : 3m ago
Upload by : Milo Davies
Transcription

Step by Step Tutorial to creatingR PackagesHeng WangMichigan State University

Introduction R is an open source statistical software R provides functions to perform statisticaloperationso Classical (regression, logistic regression,ANOVA, etc)o Modern (neural networks, bootstrap,genomic selection, etc) Can be easily extended by make newpackages

To install an R package, use functioninstall.packages() For example, to fit a mixed model, we coulduse function mixed.solve(). It requirespackage “rrBLUP”.

Steps to Build an R package Step 1. Prepare your functions Step 2. Build the structure of the package usingpackage.skeleton() Step 3. Edit DESCRIPTION File Step 4. Edit the help File Step 5. Preparation for Windows Users (RTools) Step 6. Build and install the R package Step 7. Check the R package Step 8. Add functions and data to a package

Build an R Package-- Step 1. Prepare your functions Before you write your functions, clear theworking space using rm(list ls()). Write your function. Load all the data youwant to include in the package. Set working directory to the positioncontaining the .R file.

Build an R Package-- Step 2. package.skeleton() Run package.skeleton(name, list). For example: package.skeleton(name "cum",list c("my.cumsumprod", "xvec.example","output.example") Or, package.skeleton(name “cum",code files "cumsumprod.R") A new folder cum is built. If just runpackage.skeleton(), then anRpackage will bebuilt.

Step 2 (Cont.) Inside cum / anRpackage you many findseveral folders:o R: contains R code fileso data: contains data fileso man: contains documentation files (.Rd)o You may also have src folder, if your functioncontains C, C , or FORTRAN source.o Other files: tests, exec, inst, etc.

Step 2 (Cont.) also some files.o Read-and-delete-me : contain instructions for following steps.* Edit the help file skeletons in 'man', possibly combining help filesfor multiple functions.* Edit the exports in 'NAMESPACE', and add necessary imports.* Put any C/C /Fortran code in 'src'.* If you have compiled code, add a useDynLib() directive to'NAMESPACE'.* Run R CMD build to build the package tarball.* Run R CMD check to check the package tarball.Read "Writing R Extensions" for more information.o DESCRIPTION: manual file for the users.o NAMESPACE

Build an R Package-- Step 3. Edit DESCRIPTION File Package: cum-- name of the packageType: PackageTitle: What the package does (short line)-- contains no more than 65 charactersVersion: 1.0-- a sequence of non-negative integers, like: 1.0.2, 1-0-2Date: 2013-02-27-- Date that the package was created. Today’s date by defaultAuthor: Who wrote it-- all the authors, no limitMaintainer: Who to complain to yourfault@somewhere.net-- one name and an email addressDescription: More about what it does (maybe more than one line)-- Description of the package, no length limitLicense: What license is it under?-- Usually GPL-2 (GNU General Public License Version 2), which is good for CRAN/ Bioconductor. Check “Writing R Extensions” for all license abbreviations.

Build an R Package-- Step 4. Edit the help File Fill the content in each category Delete the comments or instructions. Changethe default content Do this for each .Rd file in man folder.

Build an R Package-- Step 5. Preparation for WindowsUsers Download and install Rtools. http://cran.rproject.org/bin/windows/Rtools/ Attention! Check the checkbox to update thecurrent PATH.

Step 5 (Cont.) Change the PATH in Control Panel. Click System, then Advanced system settings. Click the Advanced tap in the prompt window. Thenclick the Environment Variables. In PATH, click Edit 6.3\bin;C:\Program c:\ProgramFiles\MiKTex 2.6\miktex\bin;C:\Program Files(x86)\SSH Communications Security\SSH Secure Shell

Build an R Package-- Step 6. Build and install the Rpackage In search box, type command prompt In command prompt, change directory to theplace that contains the R package Build R package using R CMD build pkgName.For example I use R CMD build cum. A tar.gzfile is built under the working directory.

Step 6 (Cont.) Install the R package using R CMD INSTALLpkgName. Here I use R CMD INSTALLcum 1.0.tar.gz. If any error occurs, check the .Rd file. Then rerun R CMD build, R CMD INSTALL.

Build an R Package-- Step 7. Check the R package Install Miktex / (Mactex) package inconsolata usingmpm --verbose --install inconsolata. Check the R package using R CMD check pkgName. Iuse R CMD check cum. In R environment, type library(pkgName). Forexample, library(cum). You can type?cum?my.cumsumprod?xvec.example?output.example

Build an R Package-- Step 8. Add functions and data to apackage Change the working directory to the folder thatcontains your new functions and/or data. Copy the functions into working space. Run prompt() to the new function, i.e.,prompt(cumadd). Now you have a help file forcumadd. Edit the .Rd help file. Move the .R file and the .Rd file to the packagefolder. Put the .R file in the R folder. Put the .Rdfile in the man folder.

Step 8 (Cont.) Read the data file into the working space.Save the data as an .rda file.Create the help file using prompt() function.Edit the .Rd help file.Move the .rda file and the .Rd file to thepackage folder. The .rda file goes to the datafolder. The .Rd file goes to the man folder.

Step 8 (Cont.) ooo Build and install the package again.R CMD build cumR CMD INSTALL cum 1.0.tar.gzR CMD check cumIn R console, tput.example?yvec?cumadd

Questions?

Thank you!

Steps to Build an R package Step 1. Prepare your functions Step 2. Build the structure of the package using package.skeleton() Step 3. Edit DESCRIPTION File Step 4. Edit the help File Step 5. Preparation for Windows Users (RTools) Step 6. Build and install the R package Step 7. Check the R package Step 8.

Related Documents:

grade step 1 step 11 step 2 step 12 step 3 step 13 step 4 step 14 step 5 step 15 step 6 step 16 step 7 step 17 step 8 step 18 step 9 step 19 step 10 step 20 /muimn 17,635 18,737 19,840 20,942 22,014 22,926 23,808 24,689 325,57! 26,453 /2qsohrs steps 11-20 8.48 9.0! 9.54 10.07 10.60 11.02 11.45 11.87 12.29 12.72-

Special Rates 562-600 Station Number 564 Duty Sta Occupation 0083-00 City: FAYETTEVILL State: AR Grade Suppl Rate Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 7 Step 8 Step 9 Step 10 Min OPM Tab Eff Date Duty Sta Occupation 0601-13 City: FAYETTEVILL State: AR Grade Suppl Rate Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 7 Step 8 Step 9 Step 10 Min OPM Tab Eff Date

Grade Minimum Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 7 Mid-Point Step 8 Step 9 Step 10 Step 11 Step 12 Step 13 Step 14 Maximum Step 15 12/31/2022 Accounting Services Coordinator O-19 45.20 55.15 65.10 Hourly 94,016 114,712 135,408 Appx Annual 12/31/2022 Accounting Services Manager O-20 47.45 57.90 68.34 Hourly

Tutorial Process The AVID tutorial process has been divided into three partsÑ before the tutorial, during the tutorial and after the tutorial. These three parts provide a framework for the 10 steps that need to take place to create effective, rigorous and collaborative tutorials. Read and note the key components of each step of the tutorial .

Tutorial Process The AVID tutorial process has been divided into three partsÑ before the tutorial, during the tutorial and after the tutorial. These three parts provide a framework for the 10 steps that need to take place to create effective, rigorous and collaborative tutorials. Read and note the key components of each step of the tutorial .

Tutorial 1: Basic Concepts 10 Tutorial 1: Basic Concepts The goal of this tutorial is to provide you with a quick but successful experience creating and streaming a presentation using Wirecast. This tutorial requires that you open the tutorial document in Wirecast. To do this, select Create Document for Tutorial from the Help menu in Wirecast.

Tutorial 16: Urban Planning In this tutorial Introduction Urban Planning tools Zoning Masterplanning Download items Tutorial data Tutorial pdf This tutorial describes how CityEngine can be used for typical urban planning tasks. Introduction This tutorial describes how CityEngine can be used to work for typical urban .

Tutorial 1: Basic Concepts 10 Tutorial 1: Basic Concepts The goal of this tutorial is to provide you with a quick but successful experience creating and streaming a presentation using Wirecast. This tutorial requires that you open the tutorial document in Wirecast. To do this, select Create Document for Tutorial from the Help menu in Wirecast.