Skip to content

Commit 47b2a7d

Browse files
author
Quarto GHA Workflow Runner
committed
Built site for gh-pages
1 parent 75b3042 commit 47b2a7d

5 files changed

Lines changed: 376 additions & 75 deletions

File tree

.nojekyll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9c9187e2
1+
c6733768

modules.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ <h1 class="title">Modules</h1>
390390
</thead>
391391
<tbody class="list">
392392

393-
<tr data-index="0" data-listing-file-modified-sort="1749813127315" data-listing-reading-time-sort="1" data-listing-word-count-sort="50" data-listing-title-sort="Package foundations" data-listing-filename-sort="index.qmd">
393+
<tr data-index="0" data-listing-file-modified-sort="1749821333585" data-listing-reading-time-sort="1" data-listing-word-count-sort="50" data-listing-title-sort="Package foundations" data-listing-filename-sort="index.qmd">
394394
<td>
395395
<a href="./modules/01-package-foundations/index.html" class="title listing-title">Package foundations</a>
396396
</td>
@@ -400,7 +400,7 @@ <h1 class="title">Modules</h1>
400400

401401
</tr>
402402

403-
<tr data-index="1" data-listing-file-modified-sort="1749813127315" data-listing-reading-time-sort="1" data-listing-word-count-sort="65" data-listing-title-sort="Function documentation and dependencies" data-listing-filename-sort="index.qmd">
403+
<tr data-index="1" data-listing-file-modified-sort="1749821333585" data-listing-reading-time-sort="1" data-listing-word-count-sort="65" data-listing-title-sort="Function documentation and dependencies" data-listing-filename-sort="index.qmd">
404404
<td>
405405
<a href="./modules/02-documentation/index.html" class="title listing-title">Function documentation and dependencies</a>
406406
</td>
@@ -410,7 +410,7 @@ <h1 class="title">Modules</h1>
410410

411411
</tr>
412412

413-
<tr data-index="2" data-listing-file-modified-sort="1749813127315" data-listing-reading-time-sort="1" data-listing-word-count-sort="53" data-listing-title-sort="Testing" data-listing-filename-sort="index.qmd">
413+
<tr data-index="2" data-listing-file-modified-sort="1749821333585" data-listing-reading-time-sort="1" data-listing-word-count-sort="53" data-listing-title-sort="Testing" data-listing-filename-sort="index.qmd">
414414
<td>
415415
<a href="./modules/03-testing/index.html" class="title listing-title">Testing</a>
416416
</td>
@@ -420,7 +420,7 @@ <h1 class="title">Modules</h1>
420420

421421
</tr>
422422

423-
<tr data-index="3" data-listing-file-modified-sort="1749813127315" data-listing-reading-time-sort="1" data-listing-word-count-sort="53" data-listing-title-sort="Package check and documentation" data-listing-filename-sort="index.qmd">
423+
<tr data-index="3" data-listing-file-modified-sort="1749821333585" data-listing-reading-time-sort="1" data-listing-word-count-sort="53" data-listing-title-sort="Package check and documentation" data-listing-filename-sort="index.qmd">
424424
<td>
425425
<a href="./modules/04-check-package-documentation/index.html" class="title listing-title">Package check and documentation</a>
426426
</td>
@@ -430,7 +430,7 @@ <h1 class="title">Modules</h1>
430430

431431
</tr>
432432

433-
<tr data-index="4" data-listing-file-modified-sort="1749813127315" data-listing-reading-time-sort="1" data-listing-word-count-sort="50" data-listing-title-sort="Packaging data; Publication and maintenance" data-listing-filename-sort="index.qmd">
433+
<tr data-index="4" data-listing-file-modified-sort="1749821333585" data-listing-reading-time-sort="1" data-listing-word-count-sort="50" data-listing-title-sort="Packaging data; Publication and maintenance" data-listing-filename-sort="index.qmd">
434434
<td>
435435
<a href="./modules/05-data-publication-maintenance/index.html" class="title listing-title">Packaging data; Publication and maintenance</a>
436436
</td>

search.json

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,21 +781,28 @@
781781
"href": "slides/02-documentation/index.html#you-might-get-tired-of-using-all-the-time",
782782
"title": "Function documentation and dependencies",
783783
"section": "You might get tired of using :: all the time",
784-
"text": "You might get tired of using :: all the time\nOr you might want to use an infix function\n\n`%&gt;%` &lt;- magittr::`%&gt;%`\n\ncol_summary &lt;- function(df, fun) {\n stopifnot(is.data.frame(df))\n\n df %&gt;%\n purrr::keep(is.numeric) %&gt;%\n purrr::modify(fun)\n}"
784+
"text": "You might get tired of using :: all the time\nOr you might want to use an infix function\n\n`%+%` &lt;- roperators::`%+%`\n\nwelcome &lt;- function(name, place){\n message(\"Welcome \" %+% name %+% \" from \" %+% place %+% \"!\")\n}"
785+
},
786+
{
787+
"objectID": "slides/02-documentation/index.html#aside-vs",
788+
"href": "slides/02-documentation/index.html#aside-vs",
789+
"title": "Function documentation and dependencies",
790+
"section": "Aside: %>% vs |>",
791+
"text": "Aside: %&gt;% vs |&gt;\nThe native pipe, |&gt;, has been available in R since 4.1.0, and we now prefer this to importing the %&gt;% pipe from magrittr.\nThere are then two options:\n\nDepend on R &gt;= 4.1.0, with this in DESCRIPTION:\n\nDepends:\n R (&gt;= 4.1.0)\n\nUse the methods outlined in this tidyverse blog post to ensure the package can still work with older versions of R."
785792
},
786793
{
787794
"objectID": "slides/02-documentation/index.html#you-can-import-functions-into-the-package",
788795
"href": "slides/02-documentation/index.html#you-can-import-functions-into-the-package",
789796
"title": "Function documentation and dependencies",
790797
"section": "You can import functions into the package",
791-
"text": "You can import functions into the package\n\n#' @importFrom purrr keep modify\n#' @importFrom magrittr %&gt;%\ncol_summary &lt;- function(df, fun) {\n stopifnot(is.data.frame(df))\n\n df %&gt;%\n keep(is.numeric) %&gt;%\n modify(fun)\n}\n\ndevtools::document() will add corresponding import() statements to the NAMESPACE, e.g. import(purr, keep, modify).\nAdding formal imports is slightly more efficient than using ::.\nHere, the @importFrom tag is placed above the function in which the imported function is used."
798+
"text": "You can import functions into the package\n\n#' @importFrom purrr keep modify\n\ncol_summary &lt;- function(df, fun) {\n stopifnot(is.data.frame(df))\n\n df |&gt;\n keep(is.numeric) |&gt;\n modify(fun)\n}\n\ndevtools::document() will add corresponding import() statements to the NAMESPACE, e.g. import(purr, keep, modify).\nAdding formal imports is slightly more efficient than using ::.\nHere, the @importFrom tag is placed above the function in which the imported function is used."
792799
},
793800
{
794801
"objectID": "slides/02-documentation/index.html#package-level-import-file",
795802
"href": "slides/02-documentation/index.html#package-level-import-file",
796803
"title": "Function documentation and dependencies",
797804
"section": "Package-level import file",
798-
"text": "Package-level import file\nImports belong to the package, not to individual functions, so alternatively you can recognise this by storing them in a central location, e.g. R/animalsounds-package.R\n#' @importFrom purrr keep modify\n#' @importFrom magrittr %&gt;%\nNULL\n\nThis removes the possibility of multiple (redundant) imports of the same function. But harder to remember to remove import if function changes! It’s a matter of personal taste."
805+
"text": "Package-level import file\nImports belong to the package, not to individual functions, so alternatively you can recognise this by storing them in a central location, e.g. R/animalsounds-package.R\n#' @importFrom purrr keep modify\n#' @importFrom roperators %+%\nNULL\n\nThis removes the possibility of multiple (redundant) imports of the same function. But harder to remember to remove import if function changes! It’s a matter of personal taste."
799806
},
800807
{
801808
"objectID": "slides/02-documentation/index.html#usethisuse_import_from",
@@ -809,7 +816,7 @@
809816
"href": "slides/02-documentation/index.html#it-may-be-tempting-to-import-a-whole-package",
810817
"title": "Function documentation and dependencies",
811818
"section": "It may be tempting to import a whole package…",
812-
"text": "It may be tempting to import a whole package…\n#' @import purrr\ncol_summary &lt;- function(df, fun) {\n stopifnot(is.data.frame(df))\n\n df %&gt;%\n keep(is.numeric) %&gt;%\n map_dfc(fun)\n}"
819+
"text": "It may be tempting to import a whole package…\n#' @import purrr\ncol_summary &lt;- function(df, fun) {\n stopifnot(is.data.frame(df))\n\n df |&gt;\n keep(is.numeric) |&gt;\n map_dfc(fun)\n}"
813820
},
814821
{
815822
"objectID": "slides/02-documentation/index.html#but-it-is-dangerous",
@@ -853,6 +860,83 @@
853860
"section": "Your turn",
854861
"text": "Your turn\n\nUse use_package() to add rlang and cli to Imports.\nUpdate animal_sounds() to use is_character() to check the arguments and cli_abort to throw an informative error if necessary, using :: to fully qualify the function calls.\nLoad all and try giving animal_sounds() invalid inputs for animal and/or sound.\nCommit your changes to git.\nPush your commits for this session."
855862
},
863+
{
864+
"objectID": "slides/02-documentation/index.html#you-might-get-tired-of-using-all-the-time-1",
865+
"href": "slides/02-documentation/index.html#you-might-get-tired-of-using-all-the-time-1",
866+
"title": "Function documentation and dependencies",
867+
"section": "You might get tired of using :: all the time",
868+
"text": "You might get tired of using :: all the time\nOr you might want to use an infix function\n\n`%&gt;%` &lt;- magittr::`%&gt;%`\n\ncol_summary &lt;- function(df, fun) {\n stopifnot(is.data.frame(df))\n\n df %&gt;%\n purrr::keep(is.numeric) %&gt;%\n purrr::modify(fun)\n}"
869+
},
870+
{
871+
"objectID": "slides/02-documentation/index.html#you-can-import-functions-into-the-package-1",
872+
"href": "slides/02-documentation/index.html#you-can-import-functions-into-the-package-1",
873+
"title": "Function documentation and dependencies",
874+
"section": "You can import functions into the package",
875+
"text": "You can import functions into the package\n\n#' @importFrom purrr keep modify\n#' @importFrom magrittr %&gt;%\ncol_summary &lt;- function(df, fun) {\n stopifnot(is.data.frame(df))\n\n df %&gt;%\n keep(is.numeric) %&gt;%\n modify(fun)\n}\n\ndevtools::document() will add corresponding import() statements to the NAMESPACE, e.g. import(purr, keep, modify).\nAdding formal imports is slightly more efficient than using ::.\nHere, the @importFrom tag is placed above the function in which the imported function is used."
876+
},
877+
{
878+
"objectID": "slides/02-documentation/index.html#package-level-import-file-1",
879+
"href": "slides/02-documentation/index.html#package-level-import-file-1",
880+
"title": "Function documentation and dependencies",
881+
"section": "Package-level import file",
882+
"text": "Package-level import file\nImports belong to the package, not to individual functions, so alternatively you can recognise this by storing them in a central location, e.g. R/animalsounds-package.R\n#' @importFrom purrr keep modify\n#' @importFrom magrittr %&gt;%\nNULL\n\nThis removes the possibility of multiple (redundant) imports of the same function. But harder to remember to remove import if function changes! It’s a matter of personal taste."
883+
},
884+
{
885+
"objectID": "slides/02-documentation/index.html#usethisuse_import_from-1",
886+
"href": "slides/02-documentation/index.html#usethisuse_import_from-1",
887+
"title": "Function documentation and dependencies",
888+
"section": "usethis::use_import_from()",
889+
"text": "usethis::use_import_from()\nThere can be several steps to importing a function. usethis::use_import_from() takes care of all of them.\nIt will first create the package documentation file R/animalsounds-package.R (if it doesn’t already exist – you will also need to agree to this).\n\nusethis::use_import_from(\"purrr\", c(\"keep\", \"modify\"))\n\n✔ Adding 'purrr' to Imports field in DESCRIPTION\n✔ Adding '@importFrom purrr keep', '@importFrom purrr modify' to 'R/animalsounds-package.R'\n✔ Writing 'NAMESPACE'\n✔ Loading animalsounds\n\nuse_import_from() is opinionated in implementing package-level import (rather than above the function in which they are used).\nMay need to close and reopen R/animalsounds-package.R to see the changes."
890+
},
891+
{
892+
"objectID": "slides/02-documentation/index.html#it-may-be-tempting-to-import-a-whole-package-1",
893+
"href": "slides/02-documentation/index.html#it-may-be-tempting-to-import-a-whole-package-1",
894+
"title": "Function documentation and dependencies",
895+
"section": "It may be tempting to import a whole package…",
896+
"text": "It may be tempting to import a whole package…\n#' @import purrr\ncol_summary &lt;- function(df, fun) {\n stopifnot(is.data.frame(df))\n\n df %&gt;%\n keep(is.numeric) %&gt;%\n map_dfc(fun)\n}"
897+
},
898+
{
899+
"objectID": "slides/02-documentation/index.html#but-it-is-dangerous-1",
900+
"href": "slides/02-documentation/index.html#but-it-is-dangerous-1",
901+
"title": "Function documentation and dependencies",
902+
"section": "…but it is dangerous",
903+
"text": "…but it is dangerous\n#' @import pkg1\n#' @import pkg2\nfun &lt;- function(x) {\n fun1(x) + fun2(x)\n}\nWorks today…\n… but next year, what if pkg2 adds a fun1 function?"
904+
},
905+
{
906+
"objectID": "slides/02-documentation/index.html#metapackages-1",
907+
"href": "slides/02-documentation/index.html#metapackages-1",
908+
"title": "Function documentation and dependencies",
909+
"section": "Metapackages",
910+
"text": "Metapackages\nIt is bad practice to import “metapackages” (i.e. packages that are collections of packages), such as tidyverse.\nSee the blog post https://www.tidyverse.org/blog/2018/06/tidyverse-not-for-packages/ for more details."
911+
},
912+
{
913+
"objectID": "slides/02-documentation/index.html#documenting-dependencies-1",
914+
"href": "slides/02-documentation/index.html#documenting-dependencies-1",
915+
"title": "Function documentation and dependencies",
916+
"section": "Documenting dependencies",
917+
"text": "Documenting dependencies\n\n\n\n\nDESCRIPTION\nNAMESPACE\n\n\n\n\nMakes package available\nMakes function available\n\n\nMandatory\nOptional (can use :: instead)\n\n\nuse_package()\nuse_import_from()"
918+
},
919+
{
920+
"objectID": "slides/02-documentation/index.html#example-rlang-and-cli-1",
921+
"href": "slides/02-documentation/index.html#example-rlang-and-cli-1",
922+
"title": "Function documentation and dependencies",
923+
"section": "Example: rlang and cli",
924+
"text": "Example: rlang and cli\nCurrently we are using stopifnot() for argument validation\n\nstopifnot(is.character(animal) & length(animal) == 1)\nstopifnot(is.character(sound) & length(sound) == 1)\n\nWe might instead use rlang::is_character() with cli::cli_abort()\n\nsound &lt;- c(\"woof\", \"bark\")\n\nif (!rlang::is_character(sound, n = 1)) {\n cli::cli_abort(\"`sound` must be a single string!\")\n}\n\nError:\n! `sound` must be a single string!\n\n\n\nin is_character, n tests for length of the vector.\ncli::cli_abort() has some really nice capability - glue interpolation (next slide) - inline classes (next slide) - features that make it easier to write tests (covered later in this course)\nhttps://cli.r-lib.org/reference/inline-markup.html"
925+
},
926+
{
927+
"objectID": "slides/02-documentation/index.html#aside-informative-messages-with-cli-1",
928+
"href": "slides/02-documentation/index.html#aside-informative-messages-with-cli-1",
929+
"title": "Function documentation and dependencies",
930+
"section": "Aside: informative messages with cli",
931+
"text": "Aside: informative messages with cli\ncli functions can combine glue interpolation and inline classes to produce informative, nicely-formatted error messages.\nIn animal_sounds() we can use\n\ncli::cli_abort(\n c(\"{.var animal} must be a single string!\",\n \"i\" = \"It was {.type {animal}} of length {length(animal)} instead.\")\n)\n\nThis gives the error message\n\nanimal_sounds(c(\"dog\", \"cat\"), c(\"woof\", \"miaow\"))\n\nError in `animal_sounds()`:\n! `animal` must be a single string!\nℹ It was a character vector of length 2 instead.\n\n\n\nInformative error messages will make using your package a much nicer experience for you and others."
932+
},
933+
{
934+
"objectID": "slides/02-documentation/index.html#your-turn-3",
935+
"href": "slides/02-documentation/index.html#your-turn-3",
936+
"title": "Function documentation and dependencies",
937+
"section": "Your turn",
938+
"text": "Your turn\n\nUse use_package() to add rlang and cli to Imports.\nUpdate animal_sounds() to use is_character() to check the arguments and cli_abort to throw an informative error if necessary, using :: to fully qualify the function calls.\nLoad all and try giving animal_sounds() invalid inputs for animal and/or sound.\nCommit your changes to git.\nPush your commits for this session."
939+
},
856940
{
857941
"objectID": "slides/02-documentation/index.html#references",
858942
"href": "slides/02-documentation/index.html#references",

0 commit comments

Comments
 (0)