diff --git a/_freeze/html/package-development/execute-results/html.json b/_freeze/html/package-development/execute-results/html.json index 3d38bbec..2ce3aeb8 100644 --- a/_freeze/html/package-development/execute-results/html.json +++ b/_freeze/html/package-development/execute-results/html.json @@ -1,7 +1,8 @@ { "hash": "b15197621750832fa4024e374c7dc303", "result": { - "markdown": "---\ntitle: \"Package Development :: Cheatsheet\"\ndescription: \" \"\nimage-alt: \"\"\nexecute:\n eval: true\n output: false\n warning: true\n---\n\n::: {.cell .column-margin}\n\"Hex\n

\n

Download PDF

\n\"\"/\n
\n

Translations (PDF)

\n* Dutch\n* German\n* Italian\n* Korean\n* Spanish\n* Vietnamese\n:::\n\n```{=html}\n\n```\n\nVisit [r-pkgs.org](https://r-pkgs.org) to learn more about writing and publishing packages for R.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(devtools)\nlibrary(testthat)\nlibrary(roxygen2)\n```\n:::\n\n\n## Package Structure\n\nA package is a convention for organizing files into directories, and creates a shareable, installable collection of functions, sample data, and documentation.\nThis cheatsheet shows you how to work with the 7 most common parts of an R package:\n\n- R/: Write R code for your package\n- DESCRIPTION: Set up metadata and organize package functions\n- NAMESPACE\n- tests/: Verify your code is correct\n- man/\n- vignettes/: Document your code and write tutorials and how-tos\n- data/: Include data sets in your package\n\nThere are multiple packages useful to package development, including `usethis` which handily automates many of the more repetitive tasks.\nLoad and install `devtools` which wraps together several of these packages to access everything in one step.\n\n## Getting Started\n\nOnce per machine:\n\n- Get set up with `use_devtools()` so devtools is always loaded in interactive R sessions.\n\n\n ::: {.cell}\n \n ```{.r .cell-code}\n if (interactive()) {\n require(\"devtools\", quietly = TRUE)\n # automatically attaches usethis\n }\n ```\n :::\n\n\n- `create_github_token()`: Set up GitHub credentials.\n\n- `git_vaccinate()`: Ignores common special files.\n\nOnce per package:\n\n- `create_package()`: Create a project with package scaffolding.\n\n- `use_git()`: Activate git.\n\n- `use_github()`: Connect to GitHub.\n\n- `use_github_action()`: Set up automated package checks.\n\nHaving problems with git?\nGet a situation report with `git_sitrep()`.\n\n## Workflow\n\n\n```{=html}\n\n\n
\n
\n

\n\n

\nLong description of flowchart.\n
\n
\n```\n\n### Key steps in the workflow (with keyboard shortcuts)\n\n- **`load_all()`** (Ctrl/Cmd + Shift + L): Load code\n- **`test()`** (Ctrl/Cmd + Shift + T): Run tests\n- **`document()`** (Ctrl/Cmd + Shift + D): Rebuild docs and NAMESPACE\n- **`check()`** (Ctrl/Cmd + Shift + E): Check complete package\n\n## R/\n\nAll of the R code in your package goes in `R/`.\nA package with just an `R/` directory is still a very useful package.\n\n- Create a new package project with `create_package(\"path/to/name\")`.\n\n- Create R files with `use_r(\"file-name\")`.\n\n- Follow the tidyverse style guide at [style.tidyverse.org](style.tidyverse.org \"Tidyverse style guide\")\n\n- Put your cursor on a function and press `F2` to go to its definition\n\n- Find a function or file with the keyboard shortcut `Ctrl+.`\n\n## DESCRIPTION\n\nThe DESCRIPTION file describes your package, sets up how your package will work with other packages, and applies a license.\n\n- Pick a license with `use_mit_license()`, `use_gpl3_license()`, `use_proprietary_license()`.\n\n- Add packages that you need with `use_package()`.\n\n**Import** packages that your package requires to work.\nR will install them when it installs your package.\nAdd with `use_package(pkgname, type = \"imports\")`\n\n**Suggest** packages that developers of your package need.\nUsers can install or not, as they like.\nAdd with `use_package(pkgname, type = \"suggests\")`\n\n## NAMESPACE\n\nThe `NAMESPACE` file helps you make your packages self-contained: it won't interfere with other packages, and other packages won't interfere with it.\n\n- Export functions for users by placing `@export` in their roxygen comments.\n\n- Use objects from other packages with `package::object` or `@importFrom package object` (recommended) or `@import package` (use with caution).\n\n- Call `document()` to generate `NAMESPACE` and `load_all()` to reload.\n\n| DESCRIPTION | NAMESPACE |\n|------------------------------|---------------------------------|\n| Makes **packages** available | Makes **functions** available |\n| Mandatory | Optional (can use `::` instead) |\n| `use_package()` | `use_import_from()` |\n\n: Table comparing features/purpose of DESCRIPTION (left column) vs NAMESPACE (right column)\n\n\n\n## man/\n\nThe documentation will become the help pages in your package.\n\n- Document each function with a roxygen block above its definition in R/.\n In RStudio, **Code \\> Insert Roxygen Skeleton** (Keyboard shortcut: Mac `Shift+Option+Cmd+R`, Windows/Linux `Shift+Alt+Ctrl+R`) helps.\n\n- Document each data set with an roxygen block above the name of the data set in quotes.\n\n- Document the package with `use_package_doc()`.\n\n- Build documentation in man/ from Roxygen blocks with `document()`.\n\n### roxygen2\n\nThe **roxygen2** package lets you write documentation inline in your .R files with shorthand syntax.\n\n- Add roxygen documentation as comments beginning with `#'`.\n\n- Place an roxygen `@` tag (right) after `#'` to supply a specific section of documentation.\n\n- Untagged paragraphs will be used to generate a title, description, and details section (in that order).\n\n\n::: {.cell}\n\n```{.r .cell-code}\n#' Add together two numbers\n#' \n#' @param x A number.\n#' @param y A number.\n#' @returns The sum of `x` and `y`\n#' @export\n#' @examples\n#' add(1, 1)\nadd <- function(x, y) {\n x + y\n}\n```\n:::\n\n\n#### Common roxygen Tags:\n\n- `@examples`\n- `@export`\n- `@param`\n- `@returns`\n\nAlso:\n\n- `@description`\n- `@examplesif`\n- `@family`\n- `@inheritParams`\n- `@rdname`\n- `@seealso`\n\n## vignettes/\n\n- Create a vignette that is included with your package with `use_vignette()`.\n- Create an article that only appears on the website with `use_article()`.\n- Write the body of your vignettes in R Markdown.\n\n## Websites with pkgdown\n\n- Use GitHub and `use_pkgdown_github_pages()` to set up pkgdown and configure an automated workflow using GitHub Actions and Pages.\n- If you're not using GitHub, call `use_pkgdown()` to configure pkgdown. Then build locally with `pkgdown::build_site()`.\n\n## README.Rmd + NEWS.md\n\n- Create a README and NEWS markdown files with `use_readme_rmd()` and `use_news_md()`.\n\n## tests/\n\n- Create a test file with `use_test()`.\n- Write tests with `test_that()` and `expect_()`.\n- Run all tests with `test()` and run tests for current file with `test_active_file()`.\n- See coverage of all files with `test_coverage()` and see coverage of current file with `test_coverage_active_file()`.\n\n| Expect statement | Tests |\n|---------------------|----------------------------------------|\n| `expect_equal()` | Is equal? (within numerical tolerance) |\n| `expect_error()` | Throws specified error? |\n| `expect_snapshot()` | Output is unchanged? |\n\n: Table of expect functions and what each one tests\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntest_that(\"Math works\", {\n expect_equal(1 + 1, 2)\n expect_equal(1 + 2, 3)\n expect_equal(1 + 3, 4)\n})\n```\n:::\n\n\n## data/\n\n- Record how a data set was prepared as an R script and save that script to `data-raw/` with `use_data_raw()`.\n- Save a prepared data object to `data/` with `use_data()`.\n\n## Package States\n\nThe contents of a package can be stored on disk as a:\n\n- **source** - a directory with sub-directories (as shown in Package Structure)\n- **bundle** - a single compressed file (.tar.gz)\n- **binary** - a single compressed file optimized for a specific OS\n\nPackages exist in those states locally or remotely, e.g. on CRAN or on GitHub.\n\nFrom those states, a package can be installed into an R **library** and then loaded into **memory** for use during an R session.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![](images/install-load.png){fig-alt='A diagram describing the functions that move a package between different states. The description below describes this in detail.\n'}\n:::\n:::\n\n\n\n\nUse the functions below to move between these states:\n\n- `library()`: Installed in Library to loaded in Memory.\n- `install.packages()`: Binary from CRAN repository to installed in Library.\n- `install.packages(type = \"source\")`: Source code from CRAN repository to Bundle, to installed in Library.\n- `install_github()`: Source code from GitHub repository to Bundle to installed in Library.\n- `install()`: Local source code to bundle to installed in Library.\n- `build()`: Local source to Bundle.\n- `build(binary = TRUE)`: Local source to Binary.\n- `load_all()`: Local source to loaded in Memory.\n\n------------------------------------------------------------------------\n\nCC BY SA Posit Software, PBC • [info\\@posit.co](mailto:info@posit.co) • [posit.co](https://posit.co)\n\nLearn more at [r-pkgs.org](https://r-pkgs.org).\n\nUpdated: 2023-07.\n\n\n::: {.cell}\n\n```{.r .cell-code}\npackageVersion(\"devtools\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] '2.4.5'\n```\n:::\n\n```{.r .cell-code}\npackageVersion(\"usethis\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] '2.2.2'\n```\n:::\n\n```{.r .cell-code}\npackageVersion(\"testthat\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] '3.1.10'\n```\n:::\n\n```{.r .cell-code}\npackageVersion(\"roxygen2\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] '7.2.3'\n```\n:::\n:::\n\n\n------------------------------------------------------------------------\n", + "engine": "knitr", + "markdown": "---\ntitle: \"Package Development :: Cheatsheet\"\ndescription: \" \"\nimage-alt: \"\"\nexecute:\n eval: true\n output: false\n warning: true\n---\n\n::: {.cell .column-margin}\n\"Hex\n

\n

Download PDF

\n\"\"/\n
\n

Translations (PDF)

\n* Dutch\n* German\n* Italian\n* Korean\n* Spanish\n* Vietnamese\n:::\n\n```{=html}\n\n```\n\n\nVisit [r-pkgs.org](https://r-pkgs.org) to learn more about writing and publishing packages for R.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(devtools)\nlibrary(testthat)\nlibrary(roxygen2)\n```\n:::\n\n\n\n## Package Structure\n\nA package is a convention for organizing files into directories, and creates a shareable, installable collection of functions, sample data, and documentation.\nThis cheatsheet shows you how to work with the 7 most common parts of an R package:\n\n- R/: Write R code for your package\n- DESCRIPTION: Set up metadata and organize package functions\n- NAMESPACE\n- tests/: Verify your code is correct\n- man/\n- vignettes/: Document your code and write tutorials and how-tos\n- data/: Include data sets in your package\n\nThere are multiple packages useful to package development, including `usethis` which handily automates many of the more repetitive tasks.\nLoad and install `devtools` which wraps together several of these packages to access everything in one step.\n\n## Getting Started\n\nOnce per machine:\n\n- Get set up with `use_devtools()` so devtools is always loaded in interactive R sessions.\n\n\n\n ::: {.cell}\n \n ```{.r .cell-code}\n if (interactive()) {\n require(\"devtools\", quietly = TRUE)\n # automatically attaches usethis\n }\n ```\n :::\n\n\n\n- `create_github_token()`: Set up GitHub credentials.\n\n- `git_vaccinate()`: Ignores common special files.\n\nOnce per package:\n\n- `create_package()`: Create a project with package scaffolding.\n\n- `use_git()`: Activate git.\n\n- `use_github()`: Connect to GitHub.\n\n- `use_github_action()`: Set up automated package checks.\n\nHaving problems with git?\nGet a situation report with `git_sitrep()`.\n\n## Workflow\n\n\n\n```{=html}\n\n\n
\n
\n

\n\n

\nLong description of flowchart.\n
\n
\n```\n\n\n### Key steps in the workflow (with keyboard shortcuts)\n\n- **`load_all()`** (Ctrl/Cmd + Shift + L): Load code\n- **`test()`** (Ctrl/Cmd + Shift + T): Run tests\n- **`document()`** (Ctrl/Cmd + Shift + D): Rebuild docs and NAMESPACE\n- **`check()`** (Ctrl/Cmd + Shift + E): Check complete package\n\n## R/\n\nAll of the R code in your package goes in `R/`.\nA package with just an `R/` directory is still a very useful package.\n\n- Create a new package project with `create_package(\"path/to/name\")`.\n\n- Create R files with `use_r(\"file-name\")`.\n\n- Follow the tidyverse style guide at [style.tidyverse.org](style.tidyverse.org \"Tidyverse style guide\")\n\n- Put your cursor on a function and press `F2` to go to its definition\n\n- Find a function or file with the keyboard shortcut `Ctrl+.`\n\n## DESCRIPTION\n\nThe DESCRIPTION file describes your package, sets up how your package will work with other packages, and applies a license.\n\n- Pick a license with `use_mit_license()`, `use_gpl3_license()`, `use_proprietary_license()`.\n\n- Add packages that you need with `use_package()`.\n\n**Import** packages that your package requires to work.\nR will install them when it installs your package.\nAdd with `use_package(pkgname, type = \"imports\")`\n\n**Suggest** packages that developers of your package need.\nUsers can install or not, as they like.\nAdd with `use_package(pkgname, type = \"suggests\")`\n\n## NAMESPACE\n\nThe `NAMESPACE` file helps you make your packages self-contained: it won't interfere with other packages, and other packages won't interfere with it.\n\n- Export functions for users by placing `@export` in their roxygen comments.\n\n- Use objects from other packages with `package::object` or `@importFrom package object` (recommended) or `@import package` (use with caution).\n\n- Call `document()` to generate `NAMESPACE` and `load_all()` to reload.\n\n| DESCRIPTION | NAMESPACE |\n|------------------------------|---------------------------------|\n| Makes **packages** available | Makes **functions** available |\n| Mandatory | Optional (can use `::` instead) |\n| `use_package()` | `use_import_from()` |\n\n: Table comparing features/purpose of DESCRIPTION (left column) vs NAMESPACE (right column)\n\n\n\n## man/\n\nThe documentation will become the help pages in your package.\n\n- Document each function with a roxygen block above its definition in R/.\n In RStudio, **Code \\> Insert Roxygen Skeleton** (Keyboard shortcut: Mac `Shift+Option+Cmd+R`, Windows/Linux `Shift+Alt+Ctrl+R`) helps.\n\n- Document each data set with an roxygen block above the name of the data set in quotes.\n\n- Document the package with `use_package_doc()`.\n\n- Build documentation in man/ from Roxygen blocks with `document()`.\n\n### roxygen2\n\nThe **roxygen2** package lets you write documentation inline in your .R files with shorthand syntax.\n\n- Add roxygen documentation as comments beginning with `#'`.\n\n- Place an roxygen `@` tag (right) after `#'` to supply a specific section of documentation.\n\n- Untagged paragraphs will be used to generate a title, description, and details section (in that order).\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n#' Add together two numbers\n#' \n#' @param x A number.\n#' @param y A number.\n#' @returns The sum of `x` and `y`\n#' @export\n#' @examples\n#' add(1, 1)\nadd <- function(x, y) {\n x + y\n}\n```\n:::\n\n\n\n#### Common roxygen Tags:\n\n- `@examples`\n- `@export`\n- `@param`\n- `@returns`\n\nAlso:\n\n- `@description`\n- `@examplesif`\n- `@family`\n- `@inheritParams`\n- `@rdname`\n- `@seealso`\n\n## vignettes/\n\n- Create a vignette that is included with your package with `use_vignette()`.\n- Create an article that only appears on the website with `use_article()`.\n- Write the body of your vignettes in R Markdown.\n\n## Websites with pkgdown\n\n- Use GitHub and `use_pkgdown_github_pages()` to set up pkgdown and configure an automated workflow using GitHub Actions and Pages.\n- If you're not using GitHub, call `use_pkgdown()` to configure pkgdown. Then build locally with `pkgdown::build_site()`.\n\n## README.Rmd + NEWS.md\n\n- Create a README and NEWS markdown files with `use_readme_rmd()` and `use_news_md()`.\n\n## tests/\n\n- Create a test file with `use_test()`.\n- Write tests with `test_that()` and `expect_()`.\n- Run all tests with `test()` and run tests for current file with `test_active_file()`.\n- See coverage of all files with `test_coverage()` and see coverage of current file with `test_coverage_active_file()`.\n\n| Expect statement | Tests |\n|---------------------|----------------------------------------|\n| `expect_equal()` | Is equal? (within numerical tolerance) |\n| `expect_error()` | Throws specified error? |\n| `expect_snapshot()` | Output is unchanged? |\n\n: Table of expect functions and what each one tests\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntest_that(\"Math works\", {\n expect_equal(1 + 1, 2)\n expect_equal(1 + 2, 3)\n expect_equal(1 + 3, 4)\n})\n```\n:::\n\n\n\n## data/\n\n- Record how a data set was prepared as an R script and save that script to `data-raw/` with `use_data_raw()`.\n- Save a prepared data object to `data/` with `use_data()`.\n\n## Package States\n\nThe contents of a package can be stored on disk as a:\n\n- **source** - a directory with sub-directories (as shown in Package Structure)\n- **bundle** - a single compressed file (.tar.gz)\n- **binary** - a single compressed file optimized for a specific OS\n\nPackages exist in those states locally or remotely, e.g. on CRAN or on GitHub.\n\nFrom those states, a package can be installed into an R **library** and then loaded into **memory** for use during an R session.\n\n\n\n::: {.cell}\n::: {.cell-output-display}\n![](images/install-load.png){fig-alt='A diagram describing the functions that move a package between different states. The description below describes this in detail.\n' width=1013}\n:::\n:::\n\n\n\n\n\nUse the functions below to move between these states:\n\n- `library()`: Installed in Library to loaded in Memory.\n- `install.packages()`: Binary from CRAN repository to installed in Library.\n- `install.packages(type = \"source\")`: Source code from CRAN repository to Bundle, to installed in Library.\n- `install_github()`: Source code from GitHub repository to Bundle to installed in Library.\n- `install()`: Local source code to bundle to installed in Library.\n- `build()`: Local source to Bundle.\n- `build(binary = TRUE)`: Local source to Binary.\n- `load_all()`: Local source to loaded in Memory.\n\n------------------------------------------------------------------------\n\nCC BY SA Posit Software, PBC • [info\\@posit.co](mailto:info@posit.co) • [posit.co](https://posit.co)\n\nLearn more at [r-pkgs.org](https://r-pkgs.org).\n\nUpdated: 2024-05.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\npackageVersion(\"devtools\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] '2.4.5'\n```\n\n\n:::\n\n```{.r .cell-code}\npackageVersion(\"usethis\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] '2.2.3'\n```\n\n\n:::\n\n```{.r .cell-code}\npackageVersion(\"testthat\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] '3.2.1.1'\n```\n\n\n:::\n\n```{.r .cell-code}\npackageVersion(\"roxygen2\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] '7.3.1'\n```\n\n\n:::\n:::\n\n\n\n------------------------------------------------------------------------\n", "supporting": [], "filters": [ "rmarkdown/pagebreak.lua" diff --git a/html/images/logo-devtools.png b/html/images/logo-devtools.png index 0b74bab8..f6aeff10 100644 Binary files a/html/images/logo-devtools.png and b/html/images/logo-devtools.png differ diff --git a/keynotes/package-development.key b/keynotes/package-development.key index 40ce6b8b..c4340ef4 100755 Binary files a/keynotes/package-development.key and b/keynotes/package-development.key differ diff --git a/package-development.pdf b/package-development.pdf index c5918205..9908b9f8 100644 Binary files a/package-development.pdf and b/package-development.pdf differ diff --git a/pngs/package-development.png b/pngs/package-development.png index 97bf7cf2..7fe3337e 100644 Binary files a/pngs/package-development.png and b/pngs/package-development.png differ