├── DESCRIPTION <<<--- This is the only file needed to have an R package!
├── NAMESPACE
├── R
│ └── hello.R
...
└── man
└── hello.Rd
BiocManager::install(c('devtools', 'usethis'))
- http://r-pkgs.had.co.nz/
- https://usethis.r-lib.org/
- https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/
- https://devtools.r-lib.org/
-
Create package skeleton (RStudio-->
New Project
-->Package
) -
Modify
DESCRIPTION
file [http://r-pkgs.had.co.nz/description.html] -
Add data (
usethis::use_data()
) [http://r-pkgs.had.co.nz/data.html] -
Add functions (create R code files in the
R
directory) [http://r-pkgs.had.co.nz/r.html] -
Add workflows or reports to
vignettes
directory (devtools::use_vignette("my-vignette")
) [http://r-pkgs.had.co.nz/vignettes.html] -
devtools::load_all()
-
devtools::document()
-
devtools::build()
--> a tarfile that you can share with others
brfss = read.csv('https://seandavi.github.io/ITR/BRFSS-subset.csv')
#' Plot height vs weight in BRFSS
#'
#' @examples
#' plotHeightVsWeightBRFSS()
#'
#' @export
plotHeightVsWeightBRFSS = function() {
data(brfss)
plot(brfss$Height, brfss$Weight)
}
#' The Behavioral Risk Factor Surveillance System (BRFSS)
#'
#'The Behavioral Risk Factor Surveillance System (BRFSS) is
#'the nation’s premier system of health-related telephone surveys
#'that collect state data about U.S. residents regarding their
#'health-related risk behaviors, chronic health conditions, and
#'use of preventive services. Established in 1984 with 15 states,
#'BRFSS now collects data in all 50 states as well as the District
#'of Columbia and three U.S. territories. BRFSS completes more than
#'400,000 adult interviews each year, making it the largest
#'continuously conducted health survey system in the world.
#'
#' @format A data frame with 20000 rows and 5 variables:
#' \describe{
#' \item{Age}{age in years}
#' \item{Weight}{weight in kg}
#' \item{Sex}{Gender, Female or Male}
#' \item{Height}{height in cm}
#' \item{Year}{Year in which person studied}
#' }
#' @source \url{https://www.cdc.gov/brfss/about/index.htm}
"brfss"