creating packages. step by step. collected from different sources.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
R
data
inst
tests/testthat
vignettes
.Rbuildignore
.directory
.gitignore
CreatingPackages.Rproj
DESCRIPTION
README.Rmd
README.md

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.

  • Commit and push these changes.

Main folder structure:


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


  • Copy these two files ismbTweetAnalysis-package.r and ismb_analysis.Rmd to the R and vignettes folders respectively. These files are almost ready to work. We will make couple of changes. Commit and push these two files.

  • We will run another BaR (build and reload) to check all is working ok. There shouldn't be any errors. Take a look at the output:

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

  • We will chose to ignore the files under man until the end since this process will happen many time automatically. The same we will do with NAMESPACE. Otherwise, we will require to commit these files after BaR. Do this from the Git tab panel.

  • Commit the .gitignore and NAMESPACE.

  • Run Build and Reload and since there is no change in the sources there shouldn't be any notifications ion the Git tab panel.

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

  • A README file can be added at the project root folder by creating a notebook README.Rmd and choosing to keep the .md files.

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.