rgbio provides performant reading and writing operations for GenBank (.gb/.gbk/.gbff) files in R via an interface to the high-performance gb-io Rust crate. It is designed to be fast and memory-efficient while providing R-friendly data structures.
rgbio?gb-io Rust crateThe rgbio package is not available on CRAN (for now), because it depends on a Rust crate.
You can install it from the R-universe repository without having installed Rust or any Rust toolchain, as there are binary versions available for Windows, macOS, and Linux.
install.packages("rgbio",
repos = c("https://richardstoeckl.r-universe.dev",
"https://cloud.r-project.org"))
If there is no pre-built binary available for your system, or you want the current development snapshot, you can install rgbio from GitHub, provided you have the Rust toolchain installed.
You can find information on how to install Rust at https://github.com/r-rust/hellorust.
# install.packages("remotes")
remotes::install_github("richardstoeckl/rgbio")
Reading files is as simple as providing the path (and optionally chosing the output type):
library(rgbio)
# to get an object in base format
base <- read_gbk("path/to/some.gbk", format = "base")
# to get an object with tidy dataframes
tidy <- read_gbk("path/to/some.gbk", format = "tidy")
# to get an object with bioconductor sequence infrastructure
bioc <- read_gbk("path/to/some.gbk", format = "bioconductor")
Minimum required inputs:
file: output file pathsequences: non-empty named character vector or DNAStringSet
Optional inputs:
features = NULLmetadata = NULLappend = FALSEvalidate = TRUEline_width = 80If metadata is omitted, rgbio fills defaults per record:
name, definition, accession from the sequence namemolecule_type = "DNA"append = TRUE requires that the target file already exists and is a valid GenBank file.
library(rgbio)
out <- tempfile(fileext = ".gb")
write_gbk(
file = out,
sequences = c(min1 = "ATGC")
)
library(rgbio)
out <- tempfile(fileext = ".gb")
seqs <- Biostrings::DNAStringSet(c(min2 = "ATGCGG"))
write_gbk(
file = out,
sequences = seqs
)
The main vignette is available online or via:
vignette("rgbio-introduction")
Performance comparison reading 17 real-world GenBank files (rgbio v0.4.0):
| Parser | Relative Speed | Median Time (ms) |
|---|---|---|
| rgbio::read_gbk(format = 'tidy') | 45.3x | 42.2 |
| rgbio::read_gbk(format = 'bioconductor') | 38.2x | 50.1 |
| rgbio::read_gbk(format = 'base') | 45.4x | 42.1 |
| geneviewer::read_gbk() | 1.5x | 1261.0 |
| genbankr::readGenBank() | baseline | 1912.1 |

Full benchmark details and methodology available in the benchmarks article.
Important note: This was/is a project for me to play around with agentic coding, and was written primarily by LLMs ("AI") under my direction.
Nevertheless, it provides real value as it is one of the only ways to write GenBank files in R, and is one of the most performant ways to read Genbank files to R. It uses the very robust Rust gb-io crate and is tested against ~50 diverse GenBank files with many edge cases.