Question: What is more important?
man/*.Rd
files\name{cat_function}\alias{cat_function}\title{A Cat Function}\usage{cat_function(love.cats = TRUE)}\arguments{\item{love.cats}{Do you love cats? Defaults to TRUE.}}\description{This function allows you to express your love of cats.}\examples{cat_function()}\keyword{cats}
roxygen2
greatly simplifies documentationKeywords defining pieces of documentation start with @
@param
- parameter description@return
- what the function returns@export
- must be to make the function available@examples
- how-to use the functionCan (must) use LaTeX syntax in special cases
\code{ <R code here> }
- code highlight\url{ http:// ... }
- URL\email{name@...}
- e-mailhttps://CRAN.R-project.org/package=roxygen2
roxygen2
greatly simplifies documentation#' A Cat Function#'#' This function allows you to express your love of cats.#' @param love.cats Do you love cats? Defaults to TRUE.#' @keywords cats#' @export#' @examples#' cat_function()
Run roxygen2::roxygenise()
or devtools::document()
to convert roxygen-formatted help to .Rd
files understood by R
Check Generate documentation with Roxygen
to auto-generate .Rd
files, NAMESPACE file. The menu "Tools -> Project Options -> Build Tools"
NAMESPACE
file: a collection of objects to be exported and imported# Generated by roxygen2: do not edit by handS3method(t,test2)export(TCGA_corr)export(Venn2)export(Venn3)export(Venn4)export(Venn5)export(gene_enrichment)
NAMESPACE
file specifies which functions are available to the user, and which are hidden (helper functions, minimize naming conflicts)export(function_name)
NAMESPACE
file# Export all namesexportPattern(".")
NAMESPACE
is auto generated using @export
, @import
, @importFrom
Roxygen tags; never directly modify your NAMESPACE
filepackage::object
import(randomForest)importFrom(ModelMetrics,mcc)importFrom(PRROC,pr.curve)
NAMESPACE
is auto generated using @export
, @import
, importFrom
Roxygen tags; never directly modify your NAMESPACE
fileRoxygen tags from function's help sections get converted to the NAMESPACE entries
In preciseTAD.R
function:
#' @export#'#' @import randomForest e1071preciseTAD <- function(...)
In NAMESPACE, after running roxygen2::roxygenise()
or devtools::document()
export(preciseTAD)import(randomForest)import(e1071)
Vignette – an instructive tutorial demonstrating practical uses of the software with discussion of the interpretation of the results (vignette = tutorial). Critical to get a user started with your package
A short introduction that explains
https://github.com/hadley/dplyr/tree/master/vignettes
vignettes/*.Rmd
files---title: "Vignette title"date: "2023-09-17"output: rmarkdown::html_vignettevignette: > %\VignetteIndexEntry{Vignette title} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8}---
devtools::build_vignettes()
command*.html
files will be in the inst/doc
folderlibrary(devtools)create(“cats”) # Create package skeletondocument(“cats”) # Create function's helpbuild_vignettes("cats") # Build vignettesbuild("cats") # Build packageinstall("cats") # Install packagecheck("cats") # Build and check a source package, using all known best practices
README.Rmd
with the standard RMarkdown text and code, as you would do for the vignettedevtools::build_readme()
function that will compile the README.md
fileREADME.md
file shouldn't have R code. devtools::build_readme()
function will execute code you put in the README.Rmd
file and format the code and its output properlyR CMD build cats
– will create a tarball of the package, with its version number encoded in the file name
R CMD install cats_0.0.0.9000.tar.gz
R CMD check --as-cran cats_0.0.0.9000.tar.gz
Create data
folder
Save your data in R binary format, using save(cats, file = “data/mydata.rda”)
(or, use .RData
extension)
Can include .txt
of .csv
files
Add LazyData: true
in the DESCRIPTION
file – your data will be immediately available (after data("mydata")
, cats
data will be available on the first use).
If the data is large, also add LazyDataCompression: xz
R/mydata-data.R
fileroxygen2
syntax#' My data brief info#'#' Longer description of my data#'#' @docType data#' @usage data(mydata)#' @format An object of class \code{"data.frame"}#' @keywords datasets#' @references Put reference here#' @source \href{http://....org}{Link}#' @examples#' data(mydata)"mydata" # No extension
USDA Nutrients - an R package containing all data from the USDA National Nutrient Database, "Composition of Foods Raw, Processed, Prepared"
Use devtools::install_github("hadley/usdanutrients")
function to install a package from GitHub
https://github.com/hadley/usdanutrients
installr::updateR()
- update R and the corresponding packages on Windows
updateR
- update R on Mac
testthat is a H.W. package to write unit tests
rm(list=ls(all=TRUE))
removes everything in the global environment
detach("package:vegan", unload=TRUE)
pkgdown is a H.W. package that can autogenerate a website for your package build_site()
blogdown - Creating Websites with R Markdown, Yihui Xie et al.
bookdown - Write HTML, PDF, ePub, and Kindle books with R Markdown, by Yihui Xie et al.
Writing R packages lecture slides by Daniel Sjoberg. GitHub source
How to create an R package lecture slides by Irene Steves, Mitchell Maier. GitHub source
R packages book by Hadley Wickham, GitHub
Question: What is more important?
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |