Rollie Parrish
July 10, 2015
Sharing R code with others (obvious)
Personal functions
Dataset documentation
RMarkdown templates
/R
folder for package functions/data
folder for datasets/man
folder for documentation filesPackage: MyPackage
Version: 0.1
Much easier with devtools
package and RStudio
Roxygen must be configured in RStudio
Tools –> Project Options –> Build Tools –> select “Generate Documentation with Roxygen”
configure: check all the boxes
This will generate .Rd documentation files, NAMESPACE file
RStudio can generate a Roxygen skeleton from a function
Saved in /R
folder
mult <- function(x,y) {
x * y
}
Produces this above the function, which can then be modified
#' Title
#'
#' @param x
#' @param y
#'
#' @return
#' @export
#'
#' @examples
Dataset saved as seperate .rda file in /data
folder
# source: data.seattle.gov
sea_911 <- read.csv(file="Seattle_911.csv")
save(sea_911, file='data/mydata.rda')
#' sea_911 short description.
#'
#' This is a longer description.
#' Can be multiple lines if necessary.
#'
#' @format A data frame with...:
#' \describe{
#' \item{first_variable}{some details}
#' \item{second_variable}{more details}
#' ...
#' }
#' @source \url{http://wherediditcomefrom.org}
"sea_911"
library(MyPackage)
> example("mult", "MyPackage")
mult> mult(2,4)
[1] 8
mult> mult(c(1,3), c(2,4))
[1] 2 12