Install these packages: devtools, roxygen2,
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
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.
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
README file can be added at the project root folder by creating a notebook README.Rmd and choosing to keep the .md 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.
testthat.library(testthat)
tests/testthat.Build, Test Package.Notes
The man folder doesn't need to be created; it is created by devtools.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.