SlideShare una empresa de Scribd logo
1 de 39
Descargar para leer sin conexión
Isabella Gollini
Isabella.Gollini@ucd.ie
@IsabellaGollini
R Package Development
Create Package Documentation
DataFest Tbilisi
November 2018
https://github.com/forwards/workshops/
https://forwards.github.io
.R
.Rd
.Rmd
.md
.html .pdf
Function-level with
roxygen2
Package-level with
rmarkdown
.html
Markdown
I assume you are already familiar with it
# This is a top level heading
This is some text. Make text _italic_ with single underscores
(or stars). Make it **bold** with double stars (or underscores).
Here is a [link to a markdown guide](http://bit.ly/19fAexE).
* This is a list
* This is another item
```R
# Some R code
f <- function() x + 1
```
## This is a secondary heading
You can also do `inline code`, numbered lists and quotes and
more.
Basic markdown formatting
Function documentation
with roxygen2
Roxygen2
http://r-pkgs.had.co.nz/man.html
R comments Rd files HTML
Rroxygen2
#' Add a Column to a Data Frame
#'
#' Allows you to specify the position. Will replace existing variable
#' with the same name if present.
#'
#' @param x A data frame
#' @param name Name of variable to create. If a variable of that name
#' already exists it will be replaced
#' @param value Values to insert.
#' @param where Position to insert. Use 1 to insert on LHS, or -1 to
insert on
#' RHS.
#' @examples
#' df <- data.frame(x = 1:5)
#' add_col(df, "y", runif(5))
#' add_col(df, "y", runif(5), where = 1)
#'
#' add_col(df, "x", 5:1)
You write specially formatted comments in .R
#' Add a Column to a Data Frame
#'
#' Allows you to specify the position. Will replace existing variable
#' with the same name if present.
#'
#' @param x A data frame
#' @param name Name of variable to create. If a variable of that name
#' already exists it will be replaced
#' @param value Values to insert.
#' @param where Position to insert. Use 1 to insert on LHS, or -1 to
insert on
#' RHS.
#' @examples
#' df <- data.frame(x = 1:5)
#' add_col(df, "y", runif(5))
#' add_col(df, "y", runif(5), where = 1)
#'
#' add_col(df, "x", 5:1)
You write specially formatted comments in .R
Roxygen comment
Roxygen tag
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add_col.R
name{add_col}
alias{add_col}
title{Add a Column to a Data Frame}
usage{
add_col(x, name, value, where = -1)
}
arguments{
item{x}{A data frame}
item{name}{Name of variable to create. If a variable of that name
already exists it will be replaced}
item{value}{Values to insert.}
item{where}{Position to insert. Use 1 to insert on LHS, or -1 to insert on
RHS.}
}
description{
Allows you to specify the position. Will replace existing variable
with the same name if present.
}
Roxygen translates to .Rd In almost all cases youcan ignore these files
R translates to
.html for viewing
Documentation workflow
Modify R
comment
Update Rd files
Preview html
Cmd/Ctrl + Shift + D
devtools::document()
?topicname
Two caveats
1. You must have loaded the package with
load_all() at least once.
Check for message "Using development documentation..."
2. This technique only builds individual files
so links do not work.
Documentation workflow
Modify R
comment
Update Rd files
Preview html
Cmd/Ctrl + Shift + D
devtools::document()
NB: You must have loaded the package
with load_all() at least once
?topicname
Only shows single file,
so links do not work
[hadcol]
Change working directory/project to:
https://github.com/forwards/hadcol
Your turn
• Fix the typos in the documentation for add_col.
• Run the documentation workflow to check your work
Modify R
comment
Update Rd files
Preview html
Cmd/Ctrl + Shift + D
devtools::document()
NB: You must have loaded the package
with load_all() at least once
?topicname
Only shows single file,
so links do not work
First sentence is the title
Next paragraph is
the description
Everything else is the details
#' Sum of vector elements
#'
#' code{sum} returns the sum of all the values present in its arguments.
#'
#' This is a generic function: methods can be defined for it directly or via the
#' code{link{Summary}} group generic. For this to work properly, the arguments
#' code{...} should be unnamed, and dispatch is on the first argument.
The description block
First sentence is the title
Next paragraph is the description
Everything else is the details
There are five tags you’ll use for most functions
Tag Purpose
@param arg Describe inputs
@examples Show how the function works.
(Usual RStudio shortcuts work)
@seealso Pointers to related functions
@return Describe outputs (value)
@export Is this a user-visible function?
Your turn
Document add_cols().
(See next slide for hint)
RStudio helps you remember
#' Title
#'
#' @param x
#' @param y
#' @param z
#'
#' @return
#' @export
#'
#' @examples
fun <- function(x, y, z) {
}
# Activate by running
# use_roxygen_md()
**bold**, _italic_, `code`
* [func()]
* [pkg::func()]
* [link text][func()]
* [link text][pkg::func()]
Use markdown for formatting
Documentation workflow 2
Modify R
comment
Update Rd files
Preview
Install package &
restart R
Cmd/Ctrl + Shift + D
devtools::document()
Cmd/Ctrl + Shift + B
This is slower than the
previous workflow, but
there are fewer caveats
?topicname
Your turn
• Make real link to cbind()
• Add a see also section (@seealso) to add_col()
and add_cols() that links them together.
• What happens if you add @family xyz to both?
# Document multiple functions in the same file
#' @rdname add_col
# Inherit the parameter descriptions from
# another function
#' @inheritParams add_col
# Inherit everything from another topic
#' @inherit add_col
# Inherit selectively
#' @inherit add_col parameters return references
#' title description details
#' sections seealso
roxygen2 comes with other tools to reduce duplication
Read online about how to document other objects
http://r-pkgs.had.co.nz/data.html#documenting-data
http://r-pkgs.had.co.nz/man.html#man-classes
http://r-pkgs.had.co.nz/man.html#man-packages
Data
Classes & methods
Packages
Package documentation with
rmarkdown
Vignettes
http://r-pkgs.had.co.nz/vignettes.html
Rmd html
pdf
R
md
rmarkdown
knitr pandoc
Lets you combine prose
and code to explain your
how you package works.
The hard part is the
writing, not the
technology!
usethis::use_vignette("name")
# Adds to DESCRIPTION
Suggests: knitr
VignetteBuilder: knitr
# Creates vignettes/
# Drafts vignettes/name.Rmd
Easiest way to get started is with use_vignette()
---
title: "Vignette Title"
author: "Vignette author"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%VignetteIndexEntry{Vignette Title}
%VignetteEngine{knitr::rmarkdown}
%VignetteEncoding{UTF-8}
---
Vignettes are long form documentation commonly included in packages. Because
they are part of the distribution of the package, they need to be as compact
as possible. The `html_vignette` output type provides a custom style sheet
(and tweaks some options) to ensure that the resulting html is as small as
possible. The `html_vignette` format:
...
Vignette = Rmarkdown + special metadata
Special metadata needed by R
Special output format for vignettes
Vignette workflow
Modify
Rmarkdown file
Preview file
Preview whole
package
Cmd/Ctrl + Shift + K
Build entire
package &
Restart R
Cmd/Ctrl + Shift + B
Modify R code
devtools::install(build_vignettes = TRUE)
browseVignettes()
Your turn
Create a vignette that shows how to use add_col() for
adding and removing.
Fix the "vignette title"
README
# Your choice: but often useful to include
# results of running code
usethis::use_readme_md()
usethis::use_readme_rmd()
# For public projects this should include a
# brief overview, instructions on how to
# install, and a few examples. For private
# projects, this is a great place to jot down
# notes
If sharing with others, include a readme
NEWS
usethis::use_news_md()
Also good idea to track changes
Package website with pkgdown
pkgdown::build_site()
Home page with “home” icon:
• automatically generated from one of the following four files: index.Rmd; README.Rmd; index.md;
README.md
Reference:
• The function reference generates one page for each .Rd file in man/, by default generate an overall index,
which is an alphabetically ordered list of functions.
If the files are available in the package:
Articles:
• automatically build the .Rmd vignettes
News:
• if NEWS.md is present
Get Started
• if you have an article with the same name as the package.
A link to your your github repo (if listed in the DESCRIPTION url field).
Build a Website http://pkgdown.r-lib.org/
More options areavailable!
This work is licensed under the
Creative Commons Attribution-Noncommercial 3.0
United States License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc/3.0/us/

Más contenido relacionado

La actualidad más candente

chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01
tabish
 
Abapprogrammingoverview 090715081305-phpapp02
Abapprogrammingoverview 090715081305-phpapp02Abapprogrammingoverview 090715081305-phpapp02
Abapprogrammingoverview 090715081305-phpapp02
tabish
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
kelleyc3
 

La actualidad más candente (20)

C++ functions
C++ functionsC++ functions
C++ functions
 
C functions
C functionsC functions
C functions
 
GraphQL with Sangria
GraphQL with SangriaGraphQL with Sangria
GraphQL with Sangria
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVA
 
C++ theory
C++ theoryC++ theory
C++ theory
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01
 
Introduction to ABAP
Introduction to ABAPIntroduction to ABAP
Introduction to ABAP
 
Abapprogrammingoverview 090715081305-phpapp02
Abapprogrammingoverview 090715081305-phpapp02Abapprogrammingoverview 090715081305-phpapp02
Abapprogrammingoverview 090715081305-phpapp02
 
Chapter 1 Abap Programming Overview
Chapter 1 Abap Programming OverviewChapter 1 Abap Programming Overview
Chapter 1 Abap Programming Overview
 
Haskell Jumpstart
Haskell JumpstartHaskell Jumpstart
Haskell Jumpstart
 
F# Eye 4 the C# Guy
F# Eye 4 the C# GuyF# Eye 4 the C# Guy
F# Eye 4 the C# Guy
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
C++ language
C++ languageC++ language
C++ language
 
C++ functions
C++ functionsC++ functions
C++ functions
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 
Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_
 

Similar a R package development, create package documentation isabella gollini

RStudio_s_R_Markdown_documentation_Cheat_Cheet__1677232908.pdf
RStudio_s_R_Markdown_documentation_Cheat_Cheet__1677232908.pdfRStudio_s_R_Markdown_documentation_Cheat_Cheet__1677232908.pdf
RStudio_s_R_Markdown_documentation_Cheat_Cheet__1677232908.pdf
Akshay Sahatpure
 
R Introduction
R IntroductionR Introduction
R Introduction
schamber
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#
Robert Pickering
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
Ajay Ohri
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
Raghu nath
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
Suite Solutions
 

Similar a R package development, create package documentation isabella gollini (20)

Rmarkdown cheatsheet-2.0
Rmarkdown cheatsheet-2.0Rmarkdown cheatsheet-2.0
Rmarkdown cheatsheet-2.0
 
Reproducibility with R
Reproducibility with RReproducibility with R
Reproducibility with R
 
Devtools cheatsheet
Devtools cheatsheetDevtools cheatsheet
Devtools cheatsheet
 
Devtools cheatsheet
Devtools cheatsheetDevtools cheatsheet
Devtools cheatsheet
 
AD215 - Practical Magic with DXL
AD215 - Practical Magic with DXLAD215 - Practical Magic with DXL
AD215 - Practical Magic with DXL
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in R
 
RStudio_s_R_Markdown_documentation_Cheat_Cheet__1677232908.pdf
RStudio_s_R_Markdown_documentation_Cheat_Cheet__1677232908.pdfRStudio_s_R_Markdown_documentation_Cheat_Cheet__1677232908.pdf
RStudio_s_R_Markdown_documentation_Cheat_Cheet__1677232908.pdf
 
R Introduction
R IntroductionR Introduction
R Introduction
 
Aspect-oriented programming in Perl
Aspect-oriented programming in PerlAspect-oriented programming in Perl
Aspect-oriented programming in Perl
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
 
rmarkdown.pdf
rmarkdown.pdfrmarkdown.pdf
rmarkdown.pdf
 
Lecture1
Lecture1Lecture1
Lecture1
 
Lecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_jsLecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_js
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible research
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 

Más de DataFest Tbilisi

Más de DataFest Tbilisi (20)

Blockchain technology-in-fin tech - Anton Sitnikov
Blockchain technology-in-fin tech - Anton SitnikovBlockchain technology-in-fin tech - Anton Sitnikov
Blockchain technology-in-fin tech - Anton Sitnikov
 
Who are the 36 thousands employees of the russian defence ministry (in rus) ...
Who are the 36 thousands employees of the russian defence ministry (in rus)  ...Who are the 36 thousands employees of the russian defence ministry (in rus)  ...
Who are the 36 thousands employees of the russian defence ministry (in rus) ...
 
Using frictionless data to improve data quality - Jo Barratt
Using frictionless data to improve data quality -  Jo BarrattUsing frictionless data to improve data quality -  Jo Barratt
Using frictionless data to improve data quality - Jo Barratt
 
Using datawrapper mirko lorenz
Using datawrapper   mirko lorenzUsing datawrapper   mirko lorenz
Using datawrapper mirko lorenz
 
Securing your digital life - Jason Addie
Securing your digital life -  Jason AddieSecuring your digital life -  Jason Addie
Securing your digital life - Jason Addie
 
R package development, create your own package isabella gollini
R package development, create your own package   isabella golliniR package development, create your own package   isabella gollini
R package development, create your own package isabella gollini
 
Open data for social impact and better decision making - Denis Gursky
Open data for social impact and better decision making - Denis GurskyOpen data for social impact and better decision making - Denis Gursky
Open data for social impact and better decision making - Denis Gursky
 
Learning for sequences - Adam Mathias
Learning for sequences  - Adam MathiasLearning for sequences  - Adam Mathias
Learning for sequences - Adam Mathias
 
How to win a machine learning competition pavel pleskov
How to win a machine learning competition   pavel pleskovHow to win a machine learning competition   pavel pleskov
How to win a machine learning competition pavel pleskov
 
Defects mining in exchanges - medvedev, klimakov, yamkovi
Defects mining in exchanges - medvedev, klimakov, yamkoviDefects mining in exchanges - medvedev, klimakov, yamkovi
Defects mining in exchanges - medvedev, klimakov, yamkovi
 
Data analysis in life science vincenzo lagani
Data analysis in life science   vincenzo laganiData analysis in life science   vincenzo lagani
Data analysis in life science vincenzo lagani
 
Oddityviz: Visualizing Bowie by Miriam Quick
Oddityviz: Visualizing Bowie by Miriam QuickOddityviz: Visualizing Bowie by Miriam Quick
Oddityviz: Visualizing Bowie by Miriam Quick
 
Can data journalism save us from fake news? by Rayna Breuer
Can data journalism save us from fake news? by Rayna BreuerCan data journalism save us from fake news? by Rayna Breuer
Can data journalism save us from fake news? by Rayna Breuer
 
Losing my favourite game: how journalists are not catching up with open data ...
Losing my favourite game: how journalists are not catching up with open data ...Losing my favourite game: how journalists are not catching up with open data ...
Losing my favourite game: how journalists are not catching up with open data ...
 
What design adds to data by Mariam Kobuladze
What design adds to data by Mariam KobuladzeWhat design adds to data by Mariam Kobuladze
What design adds to data by Mariam Kobuladze
 
Feeling the data: how to build stories that people care about by Thomas burns
Feeling the data: how to build stories that people care about by Thomas burnsFeeling the data: how to build stories that people care about by Thomas burns
Feeling the data: how to build stories that people care about by Thomas burns
 
Stories vs Narratives. Using data for good. by Jakub Gornicki
Stories vs Narratives. Using data for good. by Jakub GornickiStories vs Narratives. Using data for good. by Jakub Gornicki
Stories vs Narratives. Using data for good. by Jakub Gornicki
 
The Power of Open Source Investigation by Christiaan triebert
The Power of Open Source Investigation by Christiaan triebertThe Power of Open Source Investigation by Christiaan triebert
The Power of Open Source Investigation by Christiaan triebert
 
Open data: for eveyone by everyone by Jason addie
Open data: for eveyone by everyone by Jason addieOpen data: for eveyone by everyone by Jason addie
Open data: for eveyone by everyone by Jason addie
 
Open Data Science: beyond traditional scientific communities by Alexey natekin
Open Data Science: beyond traditional scientific communities by Alexey natekinOpen Data Science: beyond traditional scientific communities by Alexey natekin
Open Data Science: beyond traditional scientific communities by Alexey natekin
 

Último

CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
AroojKhan71
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
amitlee9823
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 

Último (20)

CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
ELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptxELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptx
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 

R package development, create package documentation isabella gollini

  • 1. Isabella Gollini Isabella.Gollini@ucd.ie @IsabellaGollini R Package Development Create Package Documentation DataFest Tbilisi November 2018 https://github.com/forwards/workshops/ https://forwards.github.io
  • 3. Markdown I assume you are already familiar with it
  • 4. # This is a top level heading This is some text. Make text _italic_ with single underscores (or stars). Make it **bold** with double stars (or underscores). Here is a [link to a markdown guide](http://bit.ly/19fAexE). * This is a list * This is another item ```R # Some R code f <- function() x + 1 ``` ## This is a secondary heading You can also do `inline code`, numbered lists and quotes and more. Basic markdown formatting
  • 5.
  • 8. #' Add a Column to a Data Frame #' #' Allows you to specify the position. Will replace existing variable #' with the same name if present. #' #' @param x A data frame #' @param name Name of variable to create. If a variable of that name #' already exists it will be replaced #' @param value Values to insert. #' @param where Position to insert. Use 1 to insert on LHS, or -1 to insert on #' RHS. #' @examples #' df <- data.frame(x = 1:5) #' add_col(df, "y", runif(5)) #' add_col(df, "y", runif(5), where = 1) #' #' add_col(df, "x", 5:1) You write specially formatted comments in .R
  • 9. #' Add a Column to a Data Frame #' #' Allows you to specify the position. Will replace existing variable #' with the same name if present. #' #' @param x A data frame #' @param name Name of variable to create. If a variable of that name #' already exists it will be replaced #' @param value Values to insert. #' @param where Position to insert. Use 1 to insert on LHS, or -1 to insert on #' RHS. #' @examples #' df <- data.frame(x = 1:5) #' add_col(df, "y", runif(5)) #' add_col(df, "y", runif(5), where = 1) #' #' add_col(df, "x", 5:1) You write specially formatted comments in .R Roxygen comment Roxygen tag
  • 10. % Generated by roxygen2: do not edit by hand % Please edit documentation in R/add_col.R name{add_col} alias{add_col} title{Add a Column to a Data Frame} usage{ add_col(x, name, value, where = -1) } arguments{ item{x}{A data frame} item{name}{Name of variable to create. If a variable of that name already exists it will be replaced} item{value}{Values to insert.} item{where}{Position to insert. Use 1 to insert on LHS, or -1 to insert on RHS.} } description{ Allows you to specify the position. Will replace existing variable with the same name if present. } Roxygen translates to .Rd In almost all cases youcan ignore these files
  • 11. R translates to .html for viewing
  • 12. Documentation workflow Modify R comment Update Rd files Preview html Cmd/Ctrl + Shift + D devtools::document() ?topicname
  • 13. Two caveats 1. You must have loaded the package with load_all() at least once. Check for message "Using development documentation..." 2. This technique only builds individual files so links do not work.
  • 14. Documentation workflow Modify R comment Update Rd files Preview html Cmd/Ctrl + Shift + D devtools::document() NB: You must have loaded the package with load_all() at least once ?topicname Only shows single file, so links do not work
  • 15. [hadcol] Change working directory/project to: https://github.com/forwards/hadcol
  • 16. Your turn • Fix the typos in the documentation for add_col. • Run the documentation workflow to check your work Modify R comment Update Rd files Preview html Cmd/Ctrl + Shift + D devtools::document() NB: You must have loaded the package with load_all() at least once ?topicname Only shows single file, so links do not work
  • 17. First sentence is the title Next paragraph is the description Everything else is the details
  • 18. #' Sum of vector elements #' #' code{sum} returns the sum of all the values present in its arguments. #' #' This is a generic function: methods can be defined for it directly or via the #' code{link{Summary}} group generic. For this to work properly, the arguments #' code{...} should be unnamed, and dispatch is on the first argument. The description block First sentence is the title Next paragraph is the description Everything else is the details
  • 19. There are five tags you’ll use for most functions Tag Purpose @param arg Describe inputs @examples Show how the function works. (Usual RStudio shortcuts work) @seealso Pointers to related functions @return Describe outputs (value) @export Is this a user-visible function?
  • 20. Your turn Document add_cols(). (See next slide for hint)
  • 21. RStudio helps you remember #' Title #' #' @param x #' @param y #' @param z #' #' @return #' @export #' #' @examples fun <- function(x, y, z) { }
  • 22. # Activate by running # use_roxygen_md() **bold**, _italic_, `code` * [func()] * [pkg::func()] * [link text][func()] * [link text][pkg::func()] Use markdown for formatting
  • 23. Documentation workflow 2 Modify R comment Update Rd files Preview Install package & restart R Cmd/Ctrl + Shift + D devtools::document() Cmd/Ctrl + Shift + B This is slower than the previous workflow, but there are fewer caveats ?topicname
  • 24. Your turn • Make real link to cbind() • Add a see also section (@seealso) to add_col() and add_cols() that links them together. • What happens if you add @family xyz to both?
  • 25. # Document multiple functions in the same file #' @rdname add_col # Inherit the parameter descriptions from # another function #' @inheritParams add_col # Inherit everything from another topic #' @inherit add_col # Inherit selectively #' @inherit add_col parameters return references #' title description details #' sections seealso roxygen2 comes with other tools to reduce duplication
  • 26. Read online about how to document other objects http://r-pkgs.had.co.nz/data.html#documenting-data http://r-pkgs.had.co.nz/man.html#man-classes http://r-pkgs.had.co.nz/man.html#man-packages Data Classes & methods Packages
  • 28. Vignettes http://r-pkgs.had.co.nz/vignettes.html Rmd html pdf R md rmarkdown knitr pandoc Lets you combine prose and code to explain your how you package works. The hard part is the writing, not the technology!
  • 29. usethis::use_vignette("name") # Adds to DESCRIPTION Suggests: knitr VignetteBuilder: knitr # Creates vignettes/ # Drafts vignettes/name.Rmd Easiest way to get started is with use_vignette()
  • 30. --- title: "Vignette Title" author: "Vignette author" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %VignetteIndexEntry{Vignette Title} %VignetteEngine{knitr::rmarkdown} %VignetteEncoding{UTF-8} --- Vignettes are long form documentation commonly included in packages. Because they are part of the distribution of the package, they need to be as compact as possible. The `html_vignette` output type provides a custom style sheet (and tweaks some options) to ensure that the resulting html is as small as possible. The `html_vignette` format: ... Vignette = Rmarkdown + special metadata Special metadata needed by R Special output format for vignettes
  • 31. Vignette workflow Modify Rmarkdown file Preview file Preview whole package Cmd/Ctrl + Shift + K Build entire package & Restart R Cmd/Ctrl + Shift + B Modify R code devtools::install(build_vignettes = TRUE) browseVignettes()
  • 32. Your turn Create a vignette that shows how to use add_col() for adding and removing. Fix the "vignette title"
  • 34. # Your choice: but often useful to include # results of running code usethis::use_readme_md() usethis::use_readme_rmd() # For public projects this should include a # brief overview, instructions on how to # install, and a few examples. For private # projects, this is a great place to jot down # notes If sharing with others, include a readme
  • 35. NEWS
  • 38. pkgdown::build_site() Home page with “home” icon: • automatically generated from one of the following four files: index.Rmd; README.Rmd; index.md; README.md Reference: • The function reference generates one page for each .Rd file in man/, by default generate an overall index, which is an alphabetically ordered list of functions. If the files are available in the package: Articles: • automatically build the .Rmd vignettes News: • if NEWS.md is present Get Started • if you have an article with the same name as the package. A link to your your github repo (if listed in the DESCRIPTION url field). Build a Website http://pkgdown.r-lib.org/ More options areavailable!
  • 39. This work is licensed under the Creative Commons Attribution-Noncommercial 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/us/