## nolint start
suppressPackageStartupMessages({
    library(syntactic)
})
## nolint end
data(syntactic, package = "AcidTest")
object <- syntactic[["character"]]

Introduction

The syntactic package returns syntactically valid names from user-defined sample and other biological metadata. The package improves upon the make.names function defined in base R, specifically by adding smart handling of mixed case acronyms (e.g. mRNA, RNAi), decimals, and other coventions commonly used in the life sciences.

The package is intended to work in two modes: string mode (default) and file rename mode.

There are five primary naming functions:

Recommended naming conventions

Unsure how to name variables and/or functions in R? Here are my current recommendations, for scientists and bioinformaticians:

String mode

In general, stick with snakeCase or camelCase when sanitizing character strings in R.

print(object)

Use snake case formatting inside of scripts.

snakeCase(object)

We recommend using camel case inside of packages. The syntactic package offers two variants: relaxed (default) or strict mode. We prefer relaxed mode for function names, which generally returns acronyms (e.g. ID) more legibly.

camelCase(object, strict = FALSE)

If you're more old school and prefer using strict camel conventions, that's also an option.

camelCase(object, strict = TRUE)

Here's the default convention in R, for comparison:

make.names(object)

Additionally, the package exports these string functions:

File rename mode

The package also supports file name sanitization, using the syntacticRename function. This currently includes support for kebabCase (recommended), snakeCase, and camelCase, via the fun argument.

Here's an example of how to quickly rename files on disk into kebab case:

input <- c(
    "mRNA Extraction.pdf",
    "inDrops v3 Library Prep.pdf"
)
invisible(file.create(input))
output <- syntacticRename(input, fun = "kebabCase")
print(output)
invisible(file.remove(output[["to"]]))

File names containing a prefix that is considered illegal in R can be allowed, which is often useful for sequencing data:

input <- paste0(seq(4L), "_sample_", LETTERS[seq(4L)], ".fastq.gz")
print(input)
invisible(file.create(input))
output <- syntacticRename(input, fun = "kebabCase")
print(output)
invisible(file.remove(output[["to"]]))

Recursion inside of directories is supported using the recursive = TRUE argument.

Our koopa shell bootloader uses these functions internally for quick interactive file renaming. In that package, refer to kebab-case, snake-case, and/or camel-case documentation for details.

Additional methods

The syntactic package only contains S4 methods defined for character vectors, to keep the package lightweight with few dependencies. Additional S4 methods for Bioconductor classes, including DataFrame, GenomicRanges, and SummarizedExperiment, are defined in the basejump package.

Related packages

If syntactic doesn't work quite right for your workflow, these popular packages also provide excellent sanitization support:

R session information

utils::sessionInfo()


acidgenomics/syntactic documentation built on Oct. 28, 2023, 7:12 a.m.