R Integration

Author:

Rohit Goswami

1 Integrating with R analysis pipelines

rsx output files (TSV) can be loaded directly by R analysis pipelines that consume RADSex-format data.

1.1 Drop-in replacement

rsx-rs produces byte-identical output to C++ RADSex when groups are specified explicitly (-G M,F). The existing your R pipeline R functions (load_radsex_distribution, load_radsex_alignment, extract_signif_markers) work without any changes.

1.2 Adding to your R pipeline pixi.toml

The build-rsx task in your R pipeline’s pixi.toml builds rsx-rs from source:

build-rsx = """bash -c 'if ! command -v rsx >/dev/null 2>&1; then \
  cd /tmp && git clone https://github.com/HaoZeke/rsx-rs.git && \
  cd rsx-rs && cargo build --release -j4 && \
  cp target/release/rsx ~/.local/bin/rsx; fi'"""

1.3 Running from your R pipeline

Use system() or processx::run() to call radsex from R:

system2("rsx", c(
  "distrib",
  "-t", "data/radsex/BT/markers_table.tsv",
  "-p", "data/popmaps/popmap_BT_sex_hestvatn.tsv",
  "-o", "data/radsex/BT/hestvatn_BT_distribution.tsv",
  "-d", "5", "-G", "M,F"
))

1.4 Future: direct R FFI

The C API (librsx_core.so) will enable direct .Call() from R, eliminating intermediate file I/O. See the issue tracker for progress.