README.md

README

  1. Install these packages: devtools, roxygen2,

  2. Inside RStudio or R, load the package devtools first and run:

# no spaces, no underscores, no dashes
create("C:/Users/ptech/git.projects/CreatingPackages")   

Quit RStudio or R and from the command line, create a git repository with:

cd CreatingPackages
git init

Open RStudio and push the original structure just created.

Modify the file DESCRIPTION and add this line at the end:

VignetteBuilder: knitr

Add these folders: data, inst, inst/extdata to the project root.

Copy these raw data files to inst/extdata:

We will use these files for processing later. All processed data will go to ./data

Under Roxygen Options check Vignettes and Build & Reload

Run for the first time from Build with Build and Reload. There should be no errors. Take a look at the output:

==> devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette'))

Updating CreatingPackages documentation
Loading CreatingPackages
Updating roxygen version in  C:\Users\ptech\git.projects\CreatingPackages/DESCRIPTION 
Writing NAMESPACE
Updating vignettes
Documentation completed

==> Rcmd.exe INSTALL --no-multiarch --with-keep.source CreatingPackages

* installing to library 'C:/Users/ptech/Documents/R/win-library/3.3'
* installing *source* package 'CreatingPackages' ...
** inst
No man pages found in package  'CreatingPackages' 
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (CreatingPackages)

The man folder is created during this process.

Main folder structure:


-<>-|---- data
    |---- inst
            |---- extdata
    |---- R
    |---- src
    |---- vignettes


  ==> devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette'))

  Updating CreatingPackages documentation
  Loading CreatingPackages
  Writing ismbTweetAnalysis.Rd
  Writing ismb2012.Rd
  Writing readTweetData.Rd
  Writing ismb2014.Rd
  Writing tweetCounts.Rd
  Writing retweetCount.Rd
  Writing tweetRank.Rd
  Writing totalRT.Rd
  Writing NAMESPACE
  Updating vignettes
  Documentation completed

  ==> Rcmd.exe INSTALL --no-multiarch --with-keep.source CreatingPackages

  * installing to library 'C:/Users/ptech/Documents/R/win-library/3.3'
  * installing *source* package 'CreatingPackages' ...
  ** R
  ** inst
  ** preparing package for lazy loading
  ** help
  *** installing help indices
  ** building package indices
  ** installing vignettes
  ** testing if installed package can be loaded
  * DONE (CreatingPackages)

Notice that the functions are now documented as Rd files under the man folder.

Check if the notebook is running

We will modify the notebook a little bit. Starting with the objects baseLoc and extPath. Modify the first chunk into this:

```{r datamunging}
baseLoc <- system.file(package="ismbTweetAnalysis")
extPath <- file.path(baseLoc, "extdata")
baseLoc
extPath
```

Run the chunk. Your output would look to something like this:

[1] "C:/Users/ptech/Documents/R/win-library/3.3/CreatingPackages"
[1] "C:/Users/ptech/Documents/R/win-library/3.3/CreatingPackages/extdata"

This is important because we will use this technique to get the relative paths to our files under data and under inst/data

Document the data files

Under the data folder we wil have the files thatv were generated by the notebook and the scripts. That is clean or processed data. We document these two files ismb2012.RData and ismb2014.RData by creating two R files under the folder R.

The first script we call it ismb2012-data.R and enter this code:

#' Twiter data for 2012
#'
#' Twiter Data to generate ranking
#'
#' @docType data
#'
#' @usage load("./data/ismb2012.RData")
#'
#' @keywords datasets
#'
#'
"ismb12"

This will take of documenting the data. Do the same thing for the second data file ismb2014.RData.

Tests

  1. Start by installing the package testthat.
  2. Load it with:
library(testthat)
  1. Create the folder tests/testthat.
  2. Test that the initial set up works by running Build, Test Package.

Notes

The man folder doesn't need to be created; it is created by devtools.



AlfonsoRReyes/CreatingPackages documentation built on May 5, 2019, 4:53 a.m.