A style guide for the gdrplatform organization.
if (
over if(
1 == 1
over 1==1
if (1 == 1) {}
over if (1=1){}
[ , subset]
over [, subset]
<-
over =
validated_se <- validate_SE()
over
validate_se <- validate_SE()
function(a = "A")
over function(a="A")
function(big_matrix)
over
function(bigMatrix)
compute_metrics_SE
over metrics_SE
.
get*
, setters should start
with set*
, boolean checkers should start with
is*
# Good
fun <- function(param1,
param2,
param_with_dir_for_st_important = get_st_important_dir()) {
# Code is indented by two spaces.
...
}
# Bad
fun <- function(param1, param2, param_with_dir_for_st_important = file.path(system.file(paste(param1, "SE", "rds", sep = "."), package = "important_package"))) {
...
}
<-
over =
to
differentiate function arguments assignments from function assignments
myFunction <- function()
over
myFunction = function()
assert
tests for their
parametersvapply
over sapply
(or lapply
+ unlist()
if predefining FUN.VALUE is difficult)apply
on data.frame(s) (mapply
is good for row-wise operations)if
and else
statements should be
surrounded by curly braces on the same line## NULL
what_is_going_on <- if (is_check()) {
flog <- "it's getting hot..."
} else if (is_mate()) {
flog <- "Oh noooo..."
} else {
flog <- "there is a hope..."
}
R/
(R/assays
=>
tests/testthat/test-assays.R
)package.R
package.R
checkmate
,
SummarizedExperiment
, etc.expect_equal(obs, exp)
over
expect_equal(exp, obs)
^
over **
for exponentiation like 2 ^ 3
over 2**3
.0
’s in front of decimals like
0.1
over .1
df[, "alias"] <- df[, "celllinename"]
over
df[, 1] <- df[, 2]
df[, fxn_that_returns_idx(x):length(x)] <- NA
over
df[, 2:length(x)] <- NA
usethis::use_package_doc()
#' @note To learn more about functions start with `help(package = "{pkgname}")`
#' @keywords internal
#' @return package help page
"_PACKAGE"
## [1] "_PACKAGE"
Roxygen: list(markdown = TRUE)
@import
or @importFrom
always in one place -
file package.Rnamespace::function_name
gDRstyle::checkPackage()
(use
bioc_check = TRUE
to verify if the requirements for
Bioconductor are also met)<type>: <description>
where type
can be one of:
fix
: for bugfixes;feat
: for new features;docs
: for documentation changes;style
: for formatting changes that do not affect the
meaning of the code;test
: for adding missing tests or correcting existing
tests;refactor
: for code changes that neither fixes a bug nor
adds a featureci
: for changes to CI configurationPATCH
version;MINOR
version.
Exceptions: All public packages - as to-be-released on
Bioconductor have version 0.99.x.MINOR
version regardless of the nature of the changes.## R version 4.4.2 (2024-10-31)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Etc/UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] gDRstyle_1.5.1 BiocStyle_2.35.0
##
## loaded via a namespace (and not attached):
## [1] jsonlite_1.8.9 compiler_4.4.2 BiocManager_1.30.25
## [4] crayon_1.5.3 xml2_1.3.6 callr_3.7.6
## [7] jquerylib_0.1.4 yaml_2.3.10 fastmap_1.2.0
## [10] R6_2.5.1 knitr_1.49 backports_1.5.0
## [13] tibble_3.2.1 lintr_3.1.2 desc_1.4.3
## [16] maketools_1.3.1 cyclocomp_1.1.1 bslib_0.8.0
## [19] pillar_1.9.0 rlang_1.1.4 utf8_1.2.4
## [22] cachem_1.1.0 xfun_0.49 sass_0.4.9
## [25] sys_3.4.3 lazyeval_0.2.2 rex_1.2.1
## [28] cli_3.6.3 withr_3.0.2 magrittr_2.0.3
## [31] ps_1.8.1 digest_0.6.37 processx_3.8.4
## [34] remotes_2.5.0 lifecycle_1.0.4 vctrs_0.6.5
## [37] data.table_1.16.2 evaluate_1.0.1 glue_1.8.0
## [40] buildtools_1.0.0 fansi_1.0.6 rmarkdown_2.29
## [43] pkgconfig_2.0.3 tools_4.4.2 htmltools_0.5.8.1