SlideShare a Scribd company logo
1 of 2
Download to read offline
The contents of a package can be stored on disk as a:
• source - a directory with sub-directories (as above)
• bundle - a single compressed file (.tar.gz)
• binary - a single compressed file optimized for a specific
OS
Or installed into an R library (loaded into memory during an
R session) or archived online in a repository. Use the
functions below to move between these states.
install.packages() CRAN ○
install.packages(type = "source") CRAN ○
○ ○
R CMD install ○ ○
○ ○
devtools::install() ○
devtools::build() ○ ○
devtools::install_github() github ○
devtools::load_all() ○ ○
Build & Reload (RStudio) ○ ○ ○
library() ○ ○
Internet On disk library memory
Repository
Source
Bundle
Binary
Installed
Inmemory
Package Development
with devtools Cheat Sheet
Package Structure
A package is a convention for organizing files into
directories.
This sheet shows how to work with the 7 most common
parts of an R package:
Setup ( " DESCRIPTION)
The " DESCRIPTION file describes your work and sets
up how your package will work with other packages.
# Package
" DESCRIPTION
$ R/
$ tests/
$ man/
$ vignettes/
$ data/
" NAMESPACE
You must have a DESCRIPTION file
Add the packages that yours relies on with
devtools::use_package()
Adds a package to the Imports field (or Suggests
field (if second argument is "Suggests").
%
%
Setup
Write code
Test
Document
Teach
Add data
Organize
devtools::add_build_ignore("file")
Adds file to .Rbuildignore, a list of files that will not be included
when package is built.
%
Setup ( " DESCRIPTION)
The " DESCRIPTION file describes your work and sets
up how your package will work with other packages.
You must have a DESCRIPTION file
Add the packages that yours relies on with
devtools::use_package()
Adds a package to the Imports file (default) or
Suggests field (if second argument is "Suggests").
Package: mypackage
Title: Title of Package
Version: 0.1.0
Authors@R: person("Hadley", "Wickham", email =
"hadley@me.com", role = c("aut", "cre", "cst"))
Description: What the package does (one paragraph)
Depends: R (>= 3.1.0)
License: GPL-2
LazyData: true
Imports:
dplyr (>= 0.4.0),
ggvis (>= 0.2)
Suggests:
knitr (>= 0.1.0)
Import packages that your package
must have to work. R will install
them when it installs your package.
Suggest packages that re not really
essential to yours. Users can install
them manually, or not, as they like.
Imports Suggests
%
Package: mypackage
Title: Title of Package
Version: 0.1.0
Authors@R: person("Hadley", "Wickham", email =
"hadley@me.com", role = c("aut", "cre"))
Description: What the package does (one paragraph)
Depends: R (>= 3.1.0)
License: GPL-2
LazyData: true
Imports:
dplyr (>= 0.4.0),
ggvis (>= 0.2)
Suggests:
knitr (>= 0.1.0)
MIT license applies to
your code if re-shared.
MIT
Visit r-pkgs.had.co.nz for more
%
Use $ tests/ to store unit tests that will inform you if
your code ever breaks.
Test ( $ tests/)
Add a tests/ directory and import testthat with
devtools::use_testthat()
Sets up package to use automated tests with
testthat
Write tests with context(), test(), and expectations
Save your tests as .R files in tests/testthat/
1. Modify your code or tests.
2. Test your code with one of
devtools::test()
Runs all tests saved in
$ tests/.
Ctrl/Cmd + Shift + T
(keyboard shortcut)
3. Repeat until all tests pass
Workflow
%
%
expect_equal() is equal within small numerical tolerance?
expect_identical() is exactly equal?
expect_match() matches specified string or regular expression?
expect_output() prints specified output?
expect_message() displays specified message?
expect_warning() displays specified warning?
expect_error() throws specified error?
expect_is() output inherits from certain class?
expect_false() returns FALSE?
expect_true() returns TRUE?
context("Arithmetic")
test_that("Math works", {
expect_equal(1 + 1, 2)
expect_equal(1 + 2, 3)
expect_equal(1 + 3, 4)
})
Example test
Learn more at http://r-pkgs.had.co.nz • devtools 1.6.1 • Updated: 1/15
Write code ( $ R/)
All of the R code in your package goes in $ R/. A package
with just an R/ directory is still a very useful package.
Create a new package project with
devtools::create("path/to/name")
Create a template to develop into a package.
Save your code in $ R/ as scripts (extension .R)
1. Edit your code.
2. Load your code with one of
devtools::load_all()
Re-loads all saved files in $ R/ into memory.
Ctrl/Cmd + Shift + L (keyboard shortcut)
Saves all open files then calls load_all().
3. Experiment in the console.
4. Repeat.
%
%
Workflow
• Use consistent style with r-pkgs.had.co.nz/r.html#style
• Click on a function and press F2 to open its definition
• Search for a function with Ctrl + .
RStudio® is a trademark of RStudio, Inc. • All rights reserved
info@rstudio.com • 844-448-1212 • rstudio.com
Suggest packages that are not very
essential to yours. Users can install
them manually, or not, as they like.
Import packages that your package
must have to work. R will install
them when it installs your package.
GPL-2 license applies to your
code, and all code anyone
bundles with it, if re-shared.
GPL-2
No strings attached.
CC0
RStudio® is a trademark of RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212 • rstudio.com Learn more at http://r-pkgs.had.co.nz • devtools 1.6.1 • Updated: 1/15
email{name@@foo.com}
href{url}{display}
url{url}
link[=dest]{display}
linkS4class{class}
code{link{function}}
code{link[package]{function}}
tabular{lcr}{
left tab centered tab right cr
cell tab cell tab cell cr
}
emph{italic text}
strong{bold text}
code{function(args)}
pkg{package}
dontrun{code}
dontshow{code}
donttest{code}
deqn{a + b (block)}
eqn{a + b (inline)}
Document ( $ man/)
RStudio® is a trademark of RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212 • rstudio.com Learn more at http://r-pkgs.had.co.nz • devtools 1.6.1 • Updated: 1/15
Organize ( " NAMESPACE)
The " NAMESPACE file helps you make your package
self-contained: it won’t interfere with other packages,
and other packages won’t interfere with it.
Export functions for users by placing @export in their
roxygen comments
Import objects from other packages with
package::object (recommended) or @import,
@importFrom, @importClassesFrom,
@importMethodsFrom (not always recommended)
%
%
Teach ( $ vignettes/)
$ man/ contains the documentation for your functions, the help pages in your package.
Add data ( $ data/)
The $ data/ directory allows you to include data with
your package.
Store data in one of data/, R/Sysdata.rda, inst/
extdata
Always use LazyData: true in your DESCRIPTION file.
Save data as .Rdata files (suggested)
%
%
devtools::use_data()
Adds a data object to data/
(R/Sysdata.rda if internal = TRUE)
devtools::use_data_raw()
Adds an R Script used to clean a data set to data-
raw/. Includes data-raw/ on .Rbuildignore.
%
Store data in
• data/ to make data available to package users
• R/sysdata.rda to keep data internal for use by your
functions.
• inst/extdata to make raw data available for loading and
parsing examples. Access this data with system.file()
1. Modify your code or tests.
2. Document your package (devtools::document())
3. Check NAMESPACE
4. Repeat until NAMESPACE is correct
Workflow
---
title: "Vignette Title"
author: "Vignette Author"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%VignetteIndexEntry{Vignette Title}
%VignetteEngine{knitr::rmarkdown}
usepackage[utf8]{inputenc}
---
$ vignettes/ holds documents that teach your users how
to solve real problems with your tools.
Create a $ vignettes/ directory and a template vignette with
devtools::use_vignette()
Adds template vignette as vignettes/my-vignette.Rmd.
Append YAML headers to your vignettes (like right)
Write the body of your vignettes in R Markdown
(rmarkdown.rstudio.com)
%
%
%
1. Add roxygen comments in your .R files
2. Convert roxygen comments into documentation
with one of
devtools::document()
Converts roxygen comments to .Rd files and
places them in $ man/. Builds NAMESPACE.
Ctrl/Cmd + Shift + D (Keyboard Shortcut)
3. Open help pages with ? to preview documentation
4. Repeat
Workflow
Use roxygen comments to document each
function beside its definition
Document the name of each exported data set
Include helpful examples for each function
%
%
%
The roxygen package
roxygen lets you write documentation inline in your .R files
with a shorthand syntax.
• Add roxygen documentation as comment lines that begin
with #’.
• Place comment lines directly above the code that defines
the object documented.
• Place a roxygen @ tag (right) after #’ to supply a specific
section of documentation.
• Untagged lines will be used to generate a title, description,
and details section (in that order)
#' Add together two numbers.
#'
#' @param x A number.
#' @param y A number.
#' @return The sum of code{x} and code{y}.
#' @examples
#' add(1, 1)
#' @export
add <- function(x, y) {
x + y
}
.Rd formatting tags
@aliases
@concepts
@describeIn
@examples
@export
@family
@inheritParams
@keywords
@param
@rdname
@return
@section
@seealso
@format
@source
@include
@slot
@field
Common roxygen tags
data
S4
RC
Submit your package
r-pkgs.had.co.nz/release.html

More Related Content

What's hot

Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programmingizahn
 
R data-import, data-export
R data-import, data-exportR data-import, data-export
R data-import, data-exportFAO
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Laura Hughes
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programmingAlberto Labarga
 
Java Data Migration with Data Pipeline
Java Data Migration with Data PipelineJava Data Migration with Data Pipeline
Java Data Migration with Data PipelineNorth Concepts
 
Distributed Queries in IDS: New features.
Distributed Queries in IDS: New features.Distributed Queries in IDS: New features.
Distributed Queries in IDS: New features.Keshav Murthy
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factorskrishna singh
 
Writing Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingWriting Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingToni Cebrián
 
Writing MapReduce Programs using Java | Big Data Hadoop Spark Tutorial | Clou...
Writing MapReduce Programs using Java | Big Data Hadoop Spark Tutorial | Clou...Writing MapReduce Programs using Java | Big Data Hadoop Spark Tutorial | Clou...
Writing MapReduce Programs using Java | Big Data Hadoop Spark Tutorial | Clou...CloudxLab
 
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...CloudxLab
 
Session 19 - MapReduce
Session 19  - MapReduce Session 19  - MapReduce
Session 19 - MapReduce AnandMHadoop
 
Spark Dataframe - Mr. Jyotiska
Spark Dataframe - Mr. JyotiskaSpark Dataframe - Mr. Jyotiska
Spark Dataframe - Mr. JyotiskaSigmoid
 

What's hot (20)

DataBase Management System Lab File
DataBase Management System Lab FileDataBase Management System Lab File
DataBase Management System Lab File
 
Big Data Analytics Lab File
Big Data Analytics Lab FileBig Data Analytics Lab File
Big Data Analytics Lab File
 
Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programming
 
R data-import, data-export
R data-import, data-exportR data-import, data-export
R data-import, data-export
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)
 
dbms lab manual
dbms lab manualdbms lab manual
dbms lab manual
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
R programming language
R programming languageR programming language
R programming language
 
Java Data Migration with Data Pipeline
Java Data Migration with Data PipelineJava Data Migration with Data Pipeline
Java Data Migration with Data Pipeline
 
Distributed Queries in IDS: New features.
Distributed Queries in IDS: New features.Distributed Queries in IDS: New features.
Distributed Queries in IDS: New features.
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
 
Writing Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingWriting Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using Scalding
 
Data Management in Python
Data Management in PythonData Management in Python
Data Management in Python
 
Writing MapReduce Programs using Java | Big Data Hadoop Spark Tutorial | Clou...
Writing MapReduce Programs using Java | Big Data Hadoop Spark Tutorial | Clou...Writing MapReduce Programs using Java | Big Data Hadoop Spark Tutorial | Clou...
Writing MapReduce Programs using Java | Big Data Hadoop Spark Tutorial | Clou...
 
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
 
Session 19 - MapReduce
Session 19  - MapReduce Session 19  - MapReduce
Session 19 - MapReduce
 
R Introduction
R IntroductionR Introduction
R Introduction
 
Programming in R
Programming in RProgramming in R
Programming in R
 
Spark Dataframe - Mr. Jyotiska
Spark Dataframe - Mr. JyotiskaSpark Dataframe - Mr. Jyotiska
Spark Dataframe - Mr. Jyotiska
 
Sql
SqlSql
Sql
 

Similar to Devtools cheatsheet

R Introduction
R IntroductionR Introduction
R Introductionschamber
 
R Programming: Introduction To R Packages
R Programming: Introduction To R PackagesR Programming: Introduction To R Packages
R Programming: Introduction To R PackagesRsquared Academy
 
Reproducibility with R
Reproducibility with RReproducibility with R
Reproducibility with RMartin Jung
 
DevTools Package Development
 DevTools Package Development DevTools Package Development
DevTools Package DevelopmentSagar Deogirkar
 
1 Installing & getting started with R
1 Installing & getting started with R1 Installing & getting started with R
1 Installing & getting started with Rnaroranisha
 
1 installing & Getting Started with R
1 installing & Getting Started with R1 installing & Getting Started with R
1 installing & Getting Started with RDr Nisha Arora
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in RSamuel Bosch
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manualSami Said
 
Workshop presentation hands on r programming
Workshop presentation hands on r programmingWorkshop presentation hands on r programming
Workshop presentation hands on r programmingNimrita Koul
 
R package development, create package documentation isabella gollini
R package development, create package documentation   isabella golliniR package development, create package documentation   isabella gollini
R package development, create package documentation isabella golliniDataFest Tbilisi
 
Assignment 1 MapReduce With Hadoop
Assignment 1  MapReduce With HadoopAssignment 1  MapReduce With Hadoop
Assignment 1 MapReduce With HadoopAllison Thompson
 
BUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIASTBUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIASTHaritikaChhatwal1
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packagesAjay Ohri
 
Reading Data into R REVISED
Reading Data into R REVISEDReading Data into R REVISED
Reading Data into R REVISEDKazuki Yoshida
 
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...Docker, Inc.
 
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 researchAndrew Lowe
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using SwiftDiego Freniche Brito
 

Similar to Devtools cheatsheet (20)

R Introduction
R IntroductionR Introduction
R Introduction
 
R Programming: Introduction To R Packages
R Programming: Introduction To R PackagesR Programming: Introduction To R Packages
R Programming: Introduction To R Packages
 
Reproducibility with R
Reproducibility with RReproducibility with R
Reproducibility with R
 
DevTools Package Development
 DevTools Package Development DevTools Package Development
DevTools Package Development
 
1 Installing & getting started with R
1 Installing & getting started with R1 Installing & getting started with R
1 Installing & getting started with R
 
1 installing & Getting Started with R
1 installing & Getting Started with R1 installing & Getting Started with R
1 installing & Getting Started with R
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in R
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
R sharing 101
R sharing 101R sharing 101
R sharing 101
 
Workshop presentation hands on r programming
Workshop presentation hands on r programmingWorkshop presentation hands on r programming
Workshop presentation hands on r programming
 
R package development, create package documentation isabella gollini
R package development, create package documentation   isabella golliniR package development, create package documentation   isabella gollini
R package development, create package documentation isabella gollini
 
Readme
ReadmeReadme
Readme
 
Assignment 1 MapReduce With Hadoop
Assignment 1  MapReduce With HadoopAssignment 1  MapReduce With Hadoop
Assignment 1 MapReduce With Hadoop
 
BUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIASTBUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIAST
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
 
Reading Data into R REVISED
Reading Data into R REVISEDReading Data into R REVISED
Reading Data into R REVISED
 
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...
DockerCon EU 2015: Shipping Manifests, Bill of Lading and Docker Metadata and...
 
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
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 

More from Dieudonne Nahigombeye (9)

Rstudio ide-cheatsheet
Rstudio ide-cheatsheetRstudio ide-cheatsheet
Rstudio ide-cheatsheet
 
Reg ex cheatsheet
Reg ex cheatsheetReg ex cheatsheet
Reg ex cheatsheet
 
How big-is-your-graph
How big-is-your-graphHow big-is-your-graph
How big-is-your-graph
 
Ggplot2 cheatsheet-2.1
Ggplot2 cheatsheet-2.1Ggplot2 cheatsheet-2.1
Ggplot2 cheatsheet-2.1
 
Eurostat cheatsheet
Eurostat cheatsheetEurostat cheatsheet
Eurostat cheatsheet
 
Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheet
 
Data import-cheatsheet
Data import-cheatsheetData import-cheatsheet
Data import-cheatsheet
 
Base r
Base rBase r
Base r
 
Advanced r
Advanced rAdvanced r
Advanced r
 

Recently uploaded

Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfBoston Institute of Analytics
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...GQ Research
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfchwongval
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Cantervoginip
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Jack DiGiovanna
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...limedy534
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in collegessuser7a7cd61
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 217djon017
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhijennyeacort
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 

Recently uploaded (20)

Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
Call Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort ServiceCall Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort Service
 
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdf
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Canter
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in college
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 

Devtools cheatsheet

  • 1. The contents of a package can be stored on disk as a: • source - a directory with sub-directories (as above) • bundle - a single compressed file (.tar.gz) • binary - a single compressed file optimized for a specific OS Or installed into an R library (loaded into memory during an R session) or archived online in a repository. Use the functions below to move between these states. install.packages() CRAN ○ install.packages(type = "source") CRAN ○ ○ ○ R CMD install ○ ○ ○ ○ devtools::install() ○ devtools::build() ○ ○ devtools::install_github() github ○ devtools::load_all() ○ ○ Build & Reload (RStudio) ○ ○ ○ library() ○ ○ Internet On disk library memory Repository Source Bundle Binary Installed Inmemory Package Development with devtools Cheat Sheet Package Structure A package is a convention for organizing files into directories. This sheet shows how to work with the 7 most common parts of an R package: Setup ( " DESCRIPTION) The " DESCRIPTION file describes your work and sets up how your package will work with other packages. # Package " DESCRIPTION $ R/ $ tests/ $ man/ $ vignettes/ $ data/ " NAMESPACE You must have a DESCRIPTION file Add the packages that yours relies on with devtools::use_package() Adds a package to the Imports field (or Suggests field (if second argument is "Suggests"). % % Setup Write code Test Document Teach Add data Organize devtools::add_build_ignore("file") Adds file to .Rbuildignore, a list of files that will not be included when package is built. % Setup ( " DESCRIPTION) The " DESCRIPTION file describes your work and sets up how your package will work with other packages. You must have a DESCRIPTION file Add the packages that yours relies on with devtools::use_package() Adds a package to the Imports file (default) or Suggests field (if second argument is "Suggests"). Package: mypackage Title: Title of Package Version: 0.1.0 Authors@R: person("Hadley", "Wickham", email = "hadley@me.com", role = c("aut", "cre", "cst")) Description: What the package does (one paragraph) Depends: R (>= 3.1.0) License: GPL-2 LazyData: true Imports: dplyr (>= 0.4.0), ggvis (>= 0.2) Suggests: knitr (>= 0.1.0) Import packages that your package must have to work. R will install them when it installs your package. Suggest packages that re not really essential to yours. Users can install them manually, or not, as they like. Imports Suggests % Package: mypackage Title: Title of Package Version: 0.1.0 Authors@R: person("Hadley", "Wickham", email = "hadley@me.com", role = c("aut", "cre")) Description: What the package does (one paragraph) Depends: R (>= 3.1.0) License: GPL-2 LazyData: true Imports: dplyr (>= 0.4.0), ggvis (>= 0.2) Suggests: knitr (>= 0.1.0) MIT license applies to your code if re-shared. MIT Visit r-pkgs.had.co.nz for more % Use $ tests/ to store unit tests that will inform you if your code ever breaks. Test ( $ tests/) Add a tests/ directory and import testthat with devtools::use_testthat() Sets up package to use automated tests with testthat Write tests with context(), test(), and expectations Save your tests as .R files in tests/testthat/ 1. Modify your code or tests. 2. Test your code with one of devtools::test() Runs all tests saved in $ tests/. Ctrl/Cmd + Shift + T (keyboard shortcut) 3. Repeat until all tests pass Workflow % % expect_equal() is equal within small numerical tolerance? expect_identical() is exactly equal? expect_match() matches specified string or regular expression? expect_output() prints specified output? expect_message() displays specified message? expect_warning() displays specified warning? expect_error() throws specified error? expect_is() output inherits from certain class? expect_false() returns FALSE? expect_true() returns TRUE? context("Arithmetic") test_that("Math works", { expect_equal(1 + 1, 2) expect_equal(1 + 2, 3) expect_equal(1 + 3, 4) }) Example test Learn more at http://r-pkgs.had.co.nz • devtools 1.6.1 • Updated: 1/15 Write code ( $ R/) All of the R code in your package goes in $ R/. A package with just an R/ directory is still a very useful package. Create a new package project with devtools::create("path/to/name") Create a template to develop into a package. Save your code in $ R/ as scripts (extension .R) 1. Edit your code. 2. Load your code with one of devtools::load_all() Re-loads all saved files in $ R/ into memory. Ctrl/Cmd + Shift + L (keyboard shortcut) Saves all open files then calls load_all(). 3. Experiment in the console. 4. Repeat. % % Workflow • Use consistent style with r-pkgs.had.co.nz/r.html#style • Click on a function and press F2 to open its definition • Search for a function with Ctrl + . RStudio® is a trademark of RStudio, Inc. • All rights reserved info@rstudio.com • 844-448-1212 • rstudio.com Suggest packages that are not very essential to yours. Users can install them manually, or not, as they like. Import packages that your package must have to work. R will install them when it installs your package. GPL-2 license applies to your code, and all code anyone bundles with it, if re-shared. GPL-2 No strings attached. CC0 RStudio® is a trademark of RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212 • rstudio.com Learn more at http://r-pkgs.had.co.nz • devtools 1.6.1 • Updated: 1/15
  • 2. email{name@@foo.com} href{url}{display} url{url} link[=dest]{display} linkS4class{class} code{link{function}} code{link[package]{function}} tabular{lcr}{ left tab centered tab right cr cell tab cell tab cell cr } emph{italic text} strong{bold text} code{function(args)} pkg{package} dontrun{code} dontshow{code} donttest{code} deqn{a + b (block)} eqn{a + b (inline)} Document ( $ man/) RStudio® is a trademark of RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212 • rstudio.com Learn more at http://r-pkgs.had.co.nz • devtools 1.6.1 • Updated: 1/15 Organize ( " NAMESPACE) The " NAMESPACE file helps you make your package self-contained: it won’t interfere with other packages, and other packages won’t interfere with it. Export functions for users by placing @export in their roxygen comments Import objects from other packages with package::object (recommended) or @import, @importFrom, @importClassesFrom, @importMethodsFrom (not always recommended) % % Teach ( $ vignettes/) $ man/ contains the documentation for your functions, the help pages in your package. Add data ( $ data/) The $ data/ directory allows you to include data with your package. Store data in one of data/, R/Sysdata.rda, inst/ extdata Always use LazyData: true in your DESCRIPTION file. Save data as .Rdata files (suggested) % % devtools::use_data() Adds a data object to data/ (R/Sysdata.rda if internal = TRUE) devtools::use_data_raw() Adds an R Script used to clean a data set to data- raw/. Includes data-raw/ on .Rbuildignore. % Store data in • data/ to make data available to package users • R/sysdata.rda to keep data internal for use by your functions. • inst/extdata to make raw data available for loading and parsing examples. Access this data with system.file() 1. Modify your code or tests. 2. Document your package (devtools::document()) 3. Check NAMESPACE 4. Repeat until NAMESPACE is correct Workflow --- title: "Vignette Title" author: "Vignette Author" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %VignetteIndexEntry{Vignette Title} %VignetteEngine{knitr::rmarkdown} usepackage[utf8]{inputenc} --- $ vignettes/ holds documents that teach your users how to solve real problems with your tools. Create a $ vignettes/ directory and a template vignette with devtools::use_vignette() Adds template vignette as vignettes/my-vignette.Rmd. Append YAML headers to your vignettes (like right) Write the body of your vignettes in R Markdown (rmarkdown.rstudio.com) % % % 1. Add roxygen comments in your .R files 2. Convert roxygen comments into documentation with one of devtools::document() Converts roxygen comments to .Rd files and places them in $ man/. Builds NAMESPACE. Ctrl/Cmd + Shift + D (Keyboard Shortcut) 3. Open help pages with ? to preview documentation 4. Repeat Workflow Use roxygen comments to document each function beside its definition Document the name of each exported data set Include helpful examples for each function % % % The roxygen package roxygen lets you write documentation inline in your .R files with a shorthand syntax. • Add roxygen documentation as comment lines that begin with #’. • Place comment lines directly above the code that defines the object documented. • Place a roxygen @ tag (right) after #’ to supply a specific section of documentation. • Untagged lines will be used to generate a title, description, and details section (in that order) #' Add together two numbers. #' #' @param x A number. #' @param y A number. #' @return The sum of code{x} and code{y}. #' @examples #' add(1, 1) #' @export add <- function(x, y) { x + y } .Rd formatting tags @aliases @concepts @describeIn @examples @export @family @inheritParams @keywords @param @rdname @return @section @seealso @format @source @include @slot @field Common roxygen tags data S4 RC Submit your package r-pkgs.had.co.nz/release.html