Skip to content

Commit

Permalink
Update contrib guide on functions
Browse files Browse the repository at this point in the history
  • Loading branch information
florianm committed Mar 31, 2024
1 parent 4eba32c commit cbce233
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 43 deletions.
30 changes: 30 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,36 @@ revealing sensitive information. Never include credentials in your reprex.
Some changes have intricate internal and external dependencies, which are easy
to miss and break. These checklists aim to avoid these pitfalls.

#### Adding a function
Discuss and agree on function naming with the `pyODK` developers.

In the function documentation, include the following components:

* Title
* Lifecycle badge
* Documentation from the official ODK Central API docs
* Additional paragraphs (see e.g. `entity_detail.R`): Factor out commonly used
text fragments into `man-roxygen` fragments.
* Link the relevant ODK Central API docs and surround the link with `# nolint start / end` mufflers for linter warnings about the line length.
* Link to the correct reference family topic. If adding a new topic,
update `pkgdown.yml`.
* List all parameters and export the function as usual.
* Add examples showing basic usage inside a `\dontrun{}` block. Examples have
no access to the test server and will only work for internal helpers which
do not access the ODK Central API.

Inside the function:

* Gatecheck for missing parameters via `yell_if_missing`.
* Gatecheck for the minimum ODK Central version.
* Prepare lengthy components of the `httr` call if it improves legibility.
* Use the native R pipe where possible. `ruODK` still re-exports the magrittr pipe.
* Parse response content as `utf-8`.
* Clean column names with `janitor::clean_names()`.

Link to tests:
* Add a commented out `# usethis::use_test("entity_detail") # nolint` to functions and a commented out `# usethis::use_r("entity_detail") # nolint` to tests. This serves both to create the correct files and as a convenient shortcut between both.

#### Adding a dependency
* Update DESCRIPTION
* Update GH Actions install workflows - do R package deps have system deps?
Expand Down
21 changes: 4 additions & 17 deletions R/entity_detail.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,10 @@
#' After that, the conflict field will be null until a new conflicting version
#' is received.
#'
#' ## Structure
#' The response from ODK Central from this endpoint is irregular and dynamic.
#' `ruODK` preserves the original structure as not to introduce additional
#' complexity. If a use case exists to decompose the original structure further
#' please create a GitHub issue.
#'
#' ## Names
#' Names are cleaned at the top level only. List columns contain original
#' `camelCase` names.
#'
#' ## Authentication
#' `entity_detail()` will fail with incorrect or missing authentication.
#'
#' ## Compatibility
#' This function is supported from ODK Central v2022.3 and will warn if the
#' given `odkc_version` is lower.
#'
#' @template tpl-structure-nested
#' @template tpl-names-cleaned-top-level
#' @template tpl-auth-missing
#' @template tpl-compat-2022-3
#' @template param-pid
#' @template param-did
#' @template param-eid
Expand Down
3 changes: 3 additions & 0 deletions man-roxygen/tpl-auth-missing.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#' ## Authentication
#' This function will fail with incorrect or missing authentication.
#'
4 changes: 4 additions & 0 deletions man-roxygen/tpl-compat-2022-3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#' ## Compatibility
#' This function is supported from ODK Central v2022.3 and will warn if the
#' given `odkc_version` is lower.
#'
4 changes: 4 additions & 0 deletions man-roxygen/tpl-names-cleaned-top-level.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#' ## Names
#' Names are cleaned at the top level only. List columns contain original
#' `camelCase` names.
#'
2 changes: 1 addition & 1 deletion man-roxygen/tpl-rusetup.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#' # See vignette("setup") for setup and authentication options
#' # ruODK::ru_setup(svc = "....svc", un = "[email protected]", pw = "...")
#' # ruODK::ru_setup(svc = "... .svc", un = "...", pw = "...")
8 changes: 8 additions & 0 deletions man-roxygen/tpl-structure-nested.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#' ## Structure
#' The response from ODK Central from this endpoint is irregular and dynamic.
#' Depending on the life history of records in ODK Central, some parts may be
#' populated with deeply nested structures, empty, or missing.
#' `ruODK` preserves the original structure as not to introduce additional
#' complexity. If a use case exists to decompose the original structure further
#' please create a GitHub issue.
#'
25 changes: 0 additions & 25 deletions man/entity_detail.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cbce233

Please sign in to comment.