Skip to content

Celda Development Robust and Efficient Code

Zhe Wang edited this page May 24, 2019 · 7 revisions

Robust and Efficient Code

See http://bioconductor.org/developers/how-to/efficient-code/

  • Use TRUE and FALSE. Do not use T or F.
  • Use isTRUE and isFALSE. From the documentation of logical operators in R: "isTRUE(x) is the same as {is.logical(x) && length(x) == 1 && !is.na(x) && x}. isFALSE() is defined analogously. Consequently, if (isTRUE(cond)) may be preferable to if (cond) because of NAs."
  • Use vapply(). Do not use sapply(). If possible, do not use unlist(lapply()).
  • Use seq(5), seq_len(5), and seq_along(a). Do not use 1:5 or 1:length(a).
  • Do not use paste within message, stop, or warning functions. These functions paste the texts for you.
  • Use paste(rep("-", 50), collapse = ""). Do not use "--------------------------------------------------------------------".