devtools
: To Develop Packages# Install devtools from CRANinstall.packages("devtools")# Or the development version from GitHub:# install.packages("devtools")devtools::install_github("r-lib/devtools")
library("devtools")
roxygen2
: To Document the Code# Install devtools from CRANinstall.packages("roxygen2")# Or the development version from GitHub:# install.packages("devtools")devtools::install_github("r-lib/roxygen2")
library("roxygen2")
roxygen2
: To Document the Code#' Add to message on top of a call to `print()`#'#' This function print a greeting message on top of#' the regular call to `print()`.#'#' @inheritParams print#' @param msg A string to print as a greeting message#' @export#' @examples#' print_msg(1, "The value is: ")print_msg <- function(x, msg) { message(msg) x}
usethis
: To Setup the Environment# Install devtools from CRANinstall.packages("usethis")# Or the development version from GitHub:# install.packages("devtools")devtools::install_github("r-lib/usethis")
library("usethis")
usethis
: To Setup the EnvironmentGlobal options for usethis
:
options( usethis.full_name = "Firstname Lastname", usethis.protocol = "ssh", usethis.description = list( `Authors@R` = 'person( given = "Firstname", family = "Lastname", role = c("aut", "cre"), email = "Firstname.Lastname@cnrs.fr", comment = c(ORCID = "0000-0000-0000-0000") )', Version = "0.0.0.9000" ))
usethis
: To Setup the EnvironmentSetup Git:
use_git_config( user.name = "Firstname Lastname", user.email = "Firstname.Lastname@cnrs.fr")# git_sitrep() # To check if Git is configured properly
git config --global user.name 'Firstname Lastname'git config --global user.email 'Firstname.Lastname@cnrs.fr'git config --global --list
usethis
: To Setup the EnvironmentFirst an access token from GitHub needs to be created: https://github.com/settings/tokens
browse_github_token() # open the form in a browseredit_r_environ() # open .Renviron file from your home
Edit the .Renviron
and add your token.
GITHUB_PAT=xloltrglmlm9v0wqb4zgnks86z5uwkqgoat29aar
Restart and check if you have access to your token
Sys.getenv("GITHUB_PAT")github_token()
usethis
usethis
: A Tidy Packagelibrary("usethis")create_tidy_package()function (path, name = "RStudio") { path <- create_package(path, rstudio = TRUE, open = FALSE) old_project <- proj_set(path) on.exit(proj_set(old_project), add = TRUE) use_roxygen_md() use_testthat() use_gpl3_license(name) use_tidy_description() use_readme_rmd(open = FALSE) use_lifecycle_badge("experimental") use_cran_badge() use_cran_comments(open = FALSE) use_tidy_github() ui_todo("In the new package, remember to do:") ui_todo("{ui_code('use_git()')}") ui_todo("{ui_code('use_github()')}") ui_todo("{ui_code('use_tidy_ci()')}") ui_todo("{ui_code('use_pkgdown()')}") ui_todo("{ui_code('use_pkgdown_travis()')}") proj_activate(path)}
usethis
: A Tidy PackageCreate the package skeleton.
path <- create_package("mypackage", rstudio = TRUE, open = FALSE)
✔ Creating './'✔ Creating 'R/'✔ Writing 'DESCRIPTION'Package: mypackageTitle: What the Package Does (One Line, Title Case)Version: 0.0.0.9000Authors@R (parsed): * First Last <first.last@example.com> [aut, cre] (<https://orcid.org/YOUR-ORCID-ID>)Description: What the package does (one paragraph).License: What license it usesEncoding: UTF-8LazyData: true✔ Writing 'NAMESPACE'✔ Writing 'mypackage.Rproj'✔ Adding '.Rproj.user' to '.gitignore'✔ Adding '^mypackage\\.Rproj$', '^\\.Rproj\\.user$' to '.Rbuildignore'
usethis
: A Tidy PackageSetup Rstudio project (rstudio = TRUE
from create_package()
).
old_project <- proj_set(path)on.exit(proj_set(old_project), add = TRUE)
usethis
: A Tidy PackageSetup roxygen2 as tool to render documentation.
use_roxygen_md()
✔ Setting Roxygen field in DESCRIPTION to 'list(markdown = TRUE)'✔ Setting RoxygenNote field in DESCRIPTION to '7.0.2'● Run `devtools::document()`
usethis
: A Tidy PackageSetup unit test directory with default scripts.
use_testthat()
✔ Adding 'testthat' to Suggests field in DESCRIPTION✔ Creating 'tests/testthat/'✔ Writing 'tests/testthat.R'● Call `use_test()` to initialize a basic test file and open it for editing.
usethis
: A Tidy PackageSetup licence (several available).
use_gpl3_license("mypackage")
✔ Setting License field in DESCRIPTION to 'GPL-3 + file LICENSE'✔ Writing 'LICENSE.md'✔ Adding '^LICENSE\\.md$' to '.Rbuildignore'✔ Writing 'LICENSE'
usethis
: A Tidy PackageFormat/clean DESCRIPTION
file.
use_tidy_description()
Add version for packages listed in DESCRIPTION
(e.g., Imports
field).
use_tidy_versions()
usethis
: A Tidy PackageAdd an Rmarkdown script to render the README.md
file.
use_readme_rmd(open = FALSE)
✔ Writing 'README.Rmd'✔ Adding '^README\\.Rmd$' to '.Rbuildignore'
usethis
: A Tidy PackageAdd a development status badge following tidyverse convention.
use_lifecycle_badge("experimental")
✔ Adding Lifecycle: experimental badge to 'README.Rmd'● Re-knit 'README.Rmd
usethis
: A Tidy PackageAdd a CRAN badge displaying CRAN version.
use_cran_badge()
✔ Adding CRAN status badge to 'README.Rmd'● Re-knit 'README.Rmd'
usethis
: A Tidy PackageAdd a markdown file (used for the release to CRAN).
use_cran_comments(open = FALSE)
✔ Writing 'cran-comments.md'✔ Adding '^cran-comments\\.md$' to '.Rbuildignore'
usethis
: A Tidy PackageAdd default files to use in GitHub (Check them).
Note: github/SUPPORT.md
must be edited to fix GitHub repository at line 23.
use_tidy_github()
✔ Creating '.github/'✔ Adding '^\\.github$' to '.Rbuildignore'✔ Writing '.github/CONTRIBUTING.md'✔ Creating '.github/ISSUE_TEMPLATE/'✔ Adding '^\\.github/ISSUE_TEMPLATE$' to '.Rbuildignore'✔ Writing '.github/ISSUE_TEMPLATE/issue_template.md'✔ Writing '.github/SUPPORT.md'✔ Writing '.github/CODE_OF_CONDUCT.md'● Don't forget to describe the code of conduct in your README: Please note that the 'mypackage' project is released with a [Contributor Code of Conduct](.github/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms. [Copied to clipboard]
usethis
: A Tidy Packageui_todo("In the new package, remember to do:")ui_todo("{ui_code('use_git()')}")ui_todo("{ui_code('use_github()')}")ui_todo("{ui_code('use_tidy_ci()')}")ui_todo("{ui_code('use_pkgdown()')}")ui_todo("{ui_code('use_pkgdown_travis()')}")
● In the new package, remember to do:● `use_git()`● `use_github()`● `use_tidy_ci()`● `use_pkgdown()`● `use_pkgdown_travis()`
usethis
: A Tidy PackageOpen the newly created package as an Rstudio project.
proj_activate(path)
✔ Opening 'C:/mypackage' in new RStudio session
usethis
: A Tidy PackageSetup the package to use Git.
use_git()
✔ Initialising Git repo✔ Adding '.Rhistory', '.RData' to '.gitignore'There are 11 uncommitted files: '.github/' '.gitignore' '.Rbuildignore' 'cran-comments.md' 'DESCRIPTION' 'LICENSE' 'LICENSE.md' 'mypackage.Rproj' 'NAMESPACE' 'README.Rmd' 'tests/'Is it ok to commit them?1: I agree2: Not now3: No way
usethis
: A Tidy PackageSetup a repository on GitHub for the package.
use_github()
✔ Setting active project to 'C:/mypackage'✔ Checking that current branch is 'master'● Check title and description Name: mypackage Description: What the Package Does (One Line, Title Case)Are title and description ok?1: Negative2: Absolutely not3: Yup
usethis
: A Tidy PackageSetup continuous integration using travis-CI and code coverage.
use_tidy_ci()
✔ Writing '.travis.yml'✔ Adding '^\\.travis\\.yml$' to '.Rbuildignore'✔ Writing 'codecov.yml'✔ Adding '^codecov\\.yml$' to '.Rbuildignore'✔ Adding 'R' to Depends field in DESCRIPTION✔ Adding 'covr' to Suggests field in DESCRIPTION✔ Adding '^\\.covrignore$' to '.Rbuildignore'✔ Adding 'R/deprec-*.R', 'R/compat-*.R' to '.covrignore'✔ Adding Travis build status badge to 'README.Rmd'● Re-knit 'README.Rmd'✔ Adding Codecov test coverage badge to 'README.Rmd'● Re-knit 'README.Rmd'✔ Replacing release environment in 'cran-comments.md'● Turn on travis for your repo at https://travis-ci.org/profile/user
usethis
: A Tidy PackageAdd utils for tidy-evaluation (e.g., .data
pronoun).
use_tidy_eval()
✔ Adding 'roxygen2' to Suggests field in DESCRIPTION✔ Adding 'rlang' to Imports field in DESCRIPTION✔ Writing 'R/utils-tidy-eval.R'● Run `devtools::document()`
usethis
: A Tidy PackageAdd pipe (%>%
).
use_pipe()
✔ Adding 'magrittr' to Imports field in DESCRIPTION✔ Writing 'R/utils-pipe.R'● Run `devtools::document()` to update 'NAMESPACE'
usethis
: A Tidy PackageAdd the package stats
to the package.
use_package("stats")
✔ Adding 'stats' to Imports field in DESCRIPTION● Refer to functions with `stats::fun()`
devtools
devtools
: To Build / Check / TestFrequent development tasks:
load_all()
simulates installing and reloading your package, loading code
in R/
, compiled shared objects in src/
and data files in data/
.
document()
updates generated documentation in man/
, file collation and NAMESPACE
.
test()
reloads your code with load_all()
, then runs all testthat
tests.
test_coverage()
runs test coverage on your package with covr.
devtools
: Build / Check / TestBuilding and installing:
install()
reinstalls the package, detaches the currently loaded version then reloads the new version with library()
.
build()
builds a package file from package sources. You can use it to build a binary version of your package.
devtools
: Build / Check / TestCheck and release:
check()
updates the documentation, then builds and checks the package locally.check_win()
checks a package using
win-builder, and check_rhub()
checks a package using
r-hub. This allows you to easily check
your package on all systems CRAN uses before submission.
release()
makes sure everything is ok with your package (including asking
you a number of questions), then builds and uploads to CRAN.
README.md
Before trying to render the README.Rmd
, set the chunk with library(mypackage)
to eval = FALSE
.
rmarkdown::render('README.Rmd', encoding = 'UTF-8')
document()
Updating mypackage documentationWriting NAMESPACELoading mypackageWriting NAMESPACEWriting pipe.RdWriting tidyeval.Rd
check()
-- R CMD check results ---------------------------------------------------------- mypackage 0.0.0.9000 ----Duration: 19.6s> checking tests ... See below...-- Test failures ---------------------------------------------------------------------------- testthat ----> library(testthat)> library(mypackage)> > test_check("mypackage")Error: No tests found for mypackageExecution halted1 error x | 0 warnings √ | 0 notes √
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 |
o | Tile View: Overview of Slides |
Esc | Back to slideshow |
devtools
: To Develop Packages# Install devtools from CRANinstall.packages("devtools")# Or the development version from GitHub:# install.packages("devtools")devtools::install_github("r-lib/devtools")
library("devtools")
roxygen2
: To Document the Code# Install devtools from CRANinstall.packages("roxygen2")# Or the development version from GitHub:# install.packages("devtools")devtools::install_github("r-lib/roxygen2")
library("roxygen2")
roxygen2
: To Document the Code#' Add to message on top of a call to `print()`#'#' This function print a greeting message on top of#' the regular call to `print()`.#'#' @inheritParams print#' @param msg A string to print as a greeting message#' @export#' @examples#' print_msg(1, "The value is: ")print_msg <- function(x, msg) { message(msg) x}
usethis
: To Setup the Environment# Install devtools from CRANinstall.packages("usethis")# Or the development version from GitHub:# install.packages("devtools")devtools::install_github("r-lib/usethis")
library("usethis")
usethis
: To Setup the EnvironmentGlobal options for usethis
:
options( usethis.full_name = "Firstname Lastname", usethis.protocol = "ssh", usethis.description = list( `Authors@R` = 'person( given = "Firstname", family = "Lastname", role = c("aut", "cre"), email = "Firstname.Lastname@cnrs.fr", comment = c(ORCID = "0000-0000-0000-0000") )', Version = "0.0.0.9000" ))
usethis
: To Setup the EnvironmentSetup Git:
use_git_config( user.name = "Firstname Lastname", user.email = "Firstname.Lastname@cnrs.fr")# git_sitrep() # To check if Git is configured properly
git config --global user.name 'Firstname Lastname'git config --global user.email 'Firstname.Lastname@cnrs.fr'git config --global --list
usethis
: To Setup the EnvironmentFirst an access token from GitHub needs to be created: https://github.com/settings/tokens
browse_github_token() # open the form in a browseredit_r_environ() # open .Renviron file from your home
Edit the .Renviron
and add your token.
GITHUB_PAT=xloltrglmlm9v0wqb4zgnks86z5uwkqgoat29aar
Restart and check if you have access to your token
Sys.getenv("GITHUB_PAT")github_token()
usethis
usethis
: A Tidy Packagelibrary("usethis")create_tidy_package()function (path, name = "RStudio") { path <- create_package(path, rstudio = TRUE, open = FALSE) old_project <- proj_set(path) on.exit(proj_set(old_project), add = TRUE) use_roxygen_md() use_testthat() use_gpl3_license(name) use_tidy_description() use_readme_rmd(open = FALSE) use_lifecycle_badge("experimental") use_cran_badge() use_cran_comments(open = FALSE) use_tidy_github() ui_todo("In the new package, remember to do:") ui_todo("{ui_code('use_git()')}") ui_todo("{ui_code('use_github()')}") ui_todo("{ui_code('use_tidy_ci()')}") ui_todo("{ui_code('use_pkgdown()')}") ui_todo("{ui_code('use_pkgdown_travis()')}") proj_activate(path)}
usethis
: A Tidy PackageCreate the package skeleton.
path <- create_package("mypackage", rstudio = TRUE, open = FALSE)
✔ Creating './'✔ Creating 'R/'✔ Writing 'DESCRIPTION'Package: mypackageTitle: What the Package Does (One Line, Title Case)Version: 0.0.0.9000Authors@R (parsed): * First Last <first.last@example.com> [aut, cre] (<https://orcid.org/YOUR-ORCID-ID>)Description: What the package does (one paragraph).License: What license it usesEncoding: UTF-8LazyData: true✔ Writing 'NAMESPACE'✔ Writing 'mypackage.Rproj'✔ Adding '.Rproj.user' to '.gitignore'✔ Adding '^mypackage\\.Rproj$', '^\\.Rproj\\.user$' to '.Rbuildignore'
usethis
: A Tidy PackageSetup Rstudio project (rstudio = TRUE
from create_package()
).
old_project <- proj_set(path)on.exit(proj_set(old_project), add = TRUE)
usethis
: A Tidy PackageSetup roxygen2 as tool to render documentation.
use_roxygen_md()
✔ Setting Roxygen field in DESCRIPTION to 'list(markdown = TRUE)'✔ Setting RoxygenNote field in DESCRIPTION to '7.0.2'● Run `devtools::document()`
usethis
: A Tidy PackageSetup unit test directory with default scripts.
use_testthat()
✔ Adding 'testthat' to Suggests field in DESCRIPTION✔ Creating 'tests/testthat/'✔ Writing 'tests/testthat.R'● Call `use_test()` to initialize a basic test file and open it for editing.
usethis
: A Tidy PackageSetup licence (several available).
use_gpl3_license("mypackage")
✔ Setting License field in DESCRIPTION to 'GPL-3 + file LICENSE'✔ Writing 'LICENSE.md'✔ Adding '^LICENSE\\.md$' to '.Rbuildignore'✔ Writing 'LICENSE'
usethis
: A Tidy PackageFormat/clean DESCRIPTION
file.
use_tidy_description()
Add version for packages listed in DESCRIPTION
(e.g., Imports
field).
use_tidy_versions()
usethis
: A Tidy PackageAdd an Rmarkdown script to render the README.md
file.
use_readme_rmd(open = FALSE)
✔ Writing 'README.Rmd'✔ Adding '^README\\.Rmd$' to '.Rbuildignore'
usethis
: A Tidy PackageAdd a development status badge following tidyverse convention.
use_lifecycle_badge("experimental")
✔ Adding Lifecycle: experimental badge to 'README.Rmd'● Re-knit 'README.Rmd
usethis
: A Tidy PackageAdd a CRAN badge displaying CRAN version.
use_cran_badge()
✔ Adding CRAN status badge to 'README.Rmd'● Re-knit 'README.Rmd'
usethis
: A Tidy PackageAdd a markdown file (used for the release to CRAN).
use_cran_comments(open = FALSE)
✔ Writing 'cran-comments.md'✔ Adding '^cran-comments\\.md$' to '.Rbuildignore'
usethis
: A Tidy PackageAdd default files to use in GitHub (Check them).
Note: github/SUPPORT.md
must be edited to fix GitHub repository at line 23.
use_tidy_github()
✔ Creating '.github/'✔ Adding '^\\.github$' to '.Rbuildignore'✔ Writing '.github/CONTRIBUTING.md'✔ Creating '.github/ISSUE_TEMPLATE/'✔ Adding '^\\.github/ISSUE_TEMPLATE$' to '.Rbuildignore'✔ Writing '.github/ISSUE_TEMPLATE/issue_template.md'✔ Writing '.github/SUPPORT.md'✔ Writing '.github/CODE_OF_CONDUCT.md'● Don't forget to describe the code of conduct in your README: Please note that the 'mypackage' project is released with a [Contributor Code of Conduct](.github/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms. [Copied to clipboard]
usethis
: A Tidy Packageui_todo("In the new package, remember to do:")ui_todo("{ui_code('use_git()')}")ui_todo("{ui_code('use_github()')}")ui_todo("{ui_code('use_tidy_ci()')}")ui_todo("{ui_code('use_pkgdown()')}")ui_todo("{ui_code('use_pkgdown_travis()')}")
● In the new package, remember to do:● `use_git()`● `use_github()`● `use_tidy_ci()`● `use_pkgdown()`● `use_pkgdown_travis()`
usethis
: A Tidy PackageOpen the newly created package as an Rstudio project.
proj_activate(path)
✔ Opening 'C:/mypackage' in new RStudio session
usethis
: A Tidy PackageSetup the package to use Git.
use_git()
✔ Initialising Git repo✔ Adding '.Rhistory', '.RData' to '.gitignore'There are 11 uncommitted files: '.github/' '.gitignore' '.Rbuildignore' 'cran-comments.md' 'DESCRIPTION' 'LICENSE' 'LICENSE.md' 'mypackage.Rproj' 'NAMESPACE' 'README.Rmd' 'tests/'Is it ok to commit them?1: I agree2: Not now3: No way
usethis
: A Tidy PackageSetup a repository on GitHub for the package.
use_github()
✔ Setting active project to 'C:/mypackage'✔ Checking that current branch is 'master'● Check title and description Name: mypackage Description: What the Package Does (One Line, Title Case)Are title and description ok?1: Negative2: Absolutely not3: Yup
usethis
: A Tidy PackageSetup continuous integration using travis-CI and code coverage.
use_tidy_ci()
✔ Writing '.travis.yml'✔ Adding '^\\.travis\\.yml$' to '.Rbuildignore'✔ Writing 'codecov.yml'✔ Adding '^codecov\\.yml$' to '.Rbuildignore'✔ Adding 'R' to Depends field in DESCRIPTION✔ Adding 'covr' to Suggests field in DESCRIPTION✔ Adding '^\\.covrignore$' to '.Rbuildignore'✔ Adding 'R/deprec-*.R', 'R/compat-*.R' to '.covrignore'✔ Adding Travis build status badge to 'README.Rmd'● Re-knit 'README.Rmd'✔ Adding Codecov test coverage badge to 'README.Rmd'● Re-knit 'README.Rmd'✔ Replacing release environment in 'cran-comments.md'● Turn on travis for your repo at https://travis-ci.org/profile/user
usethis
: A Tidy PackageAdd utils for tidy-evaluation (e.g., .data
pronoun).
use_tidy_eval()
✔ Adding 'roxygen2' to Suggests field in DESCRIPTION✔ Adding 'rlang' to Imports field in DESCRIPTION✔ Writing 'R/utils-tidy-eval.R'● Run `devtools::document()`
usethis
: A Tidy PackageAdd pipe (%>%
).
use_pipe()
✔ Adding 'magrittr' to Imports field in DESCRIPTION✔ Writing 'R/utils-pipe.R'● Run `devtools::document()` to update 'NAMESPACE'
usethis
: A Tidy PackageAdd the package stats
to the package.
use_package("stats")
✔ Adding 'stats' to Imports field in DESCRIPTION● Refer to functions with `stats::fun()`
devtools
devtools
: To Build / Check / TestFrequent development tasks:
load_all()
simulates installing and reloading your package, loading code
in R/
, compiled shared objects in src/
and data files in data/
.
document()
updates generated documentation in man/
, file collation and NAMESPACE
.
test()
reloads your code with load_all()
, then runs all testthat
tests.
test_coverage()
runs test coverage on your package with covr.
devtools
: Build / Check / TestBuilding and installing:
install()
reinstalls the package, detaches the currently loaded version then reloads the new version with library()
.
build()
builds a package file from package sources. You can use it to build a binary version of your package.
devtools
: Build / Check / TestCheck and release:
check()
updates the documentation, then builds and checks the package locally.check_win()
checks a package using
win-builder, and check_rhub()
checks a package using
r-hub. This allows you to easily check
your package on all systems CRAN uses before submission.
release()
makes sure everything is ok with your package (including asking
you a number of questions), then builds and uploads to CRAN.
README.md
Before trying to render the README.Rmd
, set the chunk with library(mypackage)
to eval = FALSE
.
rmarkdown::render('README.Rmd', encoding = 'UTF-8')
document()
Updating mypackage documentationWriting NAMESPACELoading mypackageWriting NAMESPACEWriting pipe.RdWriting tidyeval.Rd
check()
-- R CMD check results ---------------------------------------------------------- mypackage 0.0.0.9000 ----Duration: 19.6s> checking tests ... See below...-- Test failures ---------------------------------------------------------------------------- testthat ----> library(testthat)> library(mypackage)> > test_check("mypackage")Error: No tests found for mypackageExecution halted1 error x | 0 warnings √ | 0 notes √