-
Notifications
You must be signed in to change notification settings - Fork 3
Style Guide
chainsawriot edited this page Apr 13, 2023
·
4 revisions
It would be good if our contributors can follow the following style.
-
If possible, please use an editor that respects
.editorconfig
. But unfortunately, RStudio is not among them. But it boils down to just one rule: use 4 spaces for indentation. Why? "Mickey Mouse has four fingers, not two." -
Use the GNU style aka Tidyverse style of parentheses, add spaces around infix operators, add a space after comma
.query_mirror_validity <- function(mirror) {
if (mirror == "https://cran.r-project.org/") {
return(TRUE)
}
all_mirrors <- utils::getCRANmirrors()$URL
mirror %in% all_mirrors
}
.insert_materials_dir <- function(dockerfile_content) {
dockerfile_content$COPY <- append(dockerfile_content$COPY, "COPY materials/ ./materials/")
dockerfile_content
}
Why? Your code needs to breath (Actually, no. It's because the editor used by the maintainer uses flycheck and lintr will mark code without those spaces).
- All functions are verbs see #44 For helper functions, use these verbs as suggestions
-
.query_
(get information online) -
.extract_
(get information locally) -
.group_
(a special type of .extract_ that groups information locally) -
.is_
(predicate function for local information, always returns TRUE/FALSE) -
.resolve_
(kind-of special function for vectorization of resolve) -
.generate_
(generate something) -
.insert_
(insert things into Dockerfile) -
.cache_
(cache) -
.normalize_
(normalize / coerce) -
.write_
(write content as a file)
Why? One reason: auto-completion; also it reduces our cognitive load to name things, one of the only two hard things in computer science.
- Several nouns are created:
rang
,ranglet
,pkgrefs
,pkgs
,source
,handle
,dep_df
; most of them are documented inpkgref.R
. Repeat here:
## we follow:
## https://r-lib.github.io/pkgdepends/reference/pkg_refs.html
## syntax of a ref: source::handle
## source can be: "cran", "github" (as of now)
## a `handle` indicates how the `package` is sourced from the `source`:
## if source == "cran", handle <- package name as per DESCRIPTION, e.g. "rtoot"
## if source == "github", handle <- username/reponame, e.g. "schochastics/rtoot"
## Similar to pak::pak()
## `pkgs` parameter of resolve() can either be shorthands (e.g. "rtoot", "schochastics/rtoot")
## or pkgrefs (e.g. "cran::rtoot", "github::schochastics/rtoot")
## For `dep_df`
## compulsory columns
## `x`, `x_version`, `x_pubdate` are the information as per DESCRIPTION
## `x_pkgref` is x in pkgref, for internal storage, we don't use @ to indicate version / uid
## optional columns
## 1. if there are dependecies: `y`, `y_raw_version`, `type`, `y_pkgref`: as per DESCRIPTION; `y_raw_version` is not useful
## 2. for "github" (and possible "local" in the future)
## `x_uid` and `y_uid` are extra unique identifier for pinning down the package, if `?_version` isn't sufficient for this purpose
## if `source` == "github", `?_uid` <- "sha"
## `installation_order` should be an ordered data.frame
## not using snake case in column names for backward compatibility in containers, and not needed
## columns: x, version, source, handle, uid