Skip to content

Commit 5e62773

Browse files
committed
Mentioning that we have a number of rtsk_* R/C++ functions but only export some to R users
Fixes #125
1 parent f9dd246 commit 5e62773

5 files changed

Lines changed: 65 additions & 33 deletions

File tree

RcppTskit/DESCRIPTION

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ Description: 'Tskit' enables efficient storage, manipulation, and analysis
2323
'reticulate' option is not optimal; for example, high-performance or
2424
low-level work with tree sequences. Currently, 'RcppTskit' provides a
2525
limited set of functions because the 'Python' API and 'reticulate'
26-
already cover most needs. The provided `RcppTskit R` API mirrors the
27-
`tskit Python` API, while the `RcppTskit C++` API mirrors the `tskit
28-
C` API.
26+
already cover most needs. The provided 'RcppTskit R' API mirrors the
27+
'tskit Python' API, while the 'RcppTskit C++' API mirrors the 'tskit
28+
C' API. Users should explore the 'RcppTskit' help pages of 'R'
29+
functions, while developers should explore the 'RcppTskit:::rtsk_*'
30+
low-level 'R' and 'C++'' functions.
2931
License: MIT + file LICENSE
3032
URL: https://github.com/HighlanderLab/RcppTskit
3133
BugReports: https://github.com/HighlanderLab/RcppTskit/issues

RcppTskit/R/RcppTskit-package.R

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66
#' The tree sequence encoding of an ARG is described in Wong et al. (2024)
77
#' <doi:10.1093/genetics/iyae100>, while \code{tskit} project is
88
#' described in Jeffrey et al. (2026) <doi:10.48550/arXiv.2602.09649>.
9-
#' See also https://tskit.dev for project news, documentation, and tutorials.
10-
#' \code{Tskit} provides Python, C, and Rust application programming interfaces (APIs).
11-
#' The Python API can be called from R via the \code{reticulate} package to
12-
#' load and analyse tree sequences as described at
13-
#' https://tskit.dev/tutorials/tskitr.html.
14-
#' \code{RcppTskit} provides R access to the \code{tskit} C API for cases where the
15-
#' \code{reticulate} option is not optimal; for example; high-performance or low-level
16-
#' work with tree sequences. Currently, \code{RcppTskit} provides a limited set of
17-
#' R functions because the Python API and \code{reticulate} already covers most needs.
18-
#' The provided \code{RcppTskit R} API mirrors the \code{tskit Python} API,
19-
#' while the \code{RcppTskit C++} API mirrors the \code{tskit C} API.
9+
#' See also \url{https://tskit.dev} for project news, documentation, and tutorials.
10+
#' \code{Tskit} provides \code{Python}, \code{C}, and \code{Rust} application
11+
#' programming interfaces (APIs). The \code{Python} API can be called from
12+
#' \code{R} via the \code{reticulate} package to load and analyse tree sequences
13+
#' as described at \url{https://tskit.dev/tutorials/tskitr.html}.
14+
#' \code{RcppTskit} provides \code{R} access to the \code{tskit C} API for cases
15+
#' where the \code{reticulate} option is not optimal; for example; high-performance
16+
#' or low-level work with tree sequences. Currently, \code{RcppTskit} provides a
17+
#' limited set of \code{R} functions because the \code{Python} API and
18+
#' \code{reticulate} already covers most needs. The provided \code{RcppTskit R}
19+
#' API mirrors the \code{tskit Python} API, while the \code{RcppTskit C++} API
20+
#' mirrors the \code{tskit C} API. Users should explore the \code{RcppTskit}
21+
#' help pages of \code{R} functions, while developers should explore the provided
22+
#' \code{RcppTskit:::rtsk_*} low-level \code{R} and \code{C++} functions.
2023
#' @keywords internal
2124
#'
2225
#' @useDynLib RcppTskit, .registration = TRUE

RcppTskit/inst/WORDLIST

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ finaliser
1313
iyae
1414
kastore
1515
msprime
16+
num
17+
rtsk
1618
tc
1719
ts
1820
tskit

RcppTskit/man/RcppTskit-package.Rd

Lines changed: 14 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RcppTskit/vignettes/RcppTskit_intro.qmd

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ As the name suggests, `RcppTskit` leverages the `R` package `Rcpp`
5656
which significantly lowers the barrier to using `C++` with `R`.
5757
However, we still need to write `C++` wrappers and expose them to `R`,
5858
so we recommend using `reticulate` first.
59+
To understand which functions are implemented,
60+
users should explore the `RcppTskit` help pages of `R` functions,
61+
while developers should explore the underlying
62+
`RcppTskit:::rtsk_*` low-level `R` and `C++` functions.
5963

6064
## State of the tree sequence ecosystem
6165

@@ -201,18 +205,15 @@ so all editing should happen in `C/C++` or `Python`.
201205

202206
## API mirroring across the languages
203207

204-
The provided `RcppTskit R` API mirrors the `tskit Python` API,
205-
while .
206-
207208
`RcppTskit` aims to keep naming, arguments, defaults, and behaviour aligned
208209
with upstream `tskit` APIs whenever practical.
209210
Specifically,
210-
the provided `RcppTskit R` API mirrors the `tskit Python` API,
211-
that is the functions and `R6` classes (with their methods) aim to mirror
211+
the `RcppTskit R` API mirrors the `tskit Python` API;
212+
the `R` functions and `R6` classes (with their methods) aim to mirror
212213
`tskit Python` functions and classes (with their methods).
213214
Note that the `RcppTskit R` API is far more limited than the `tskit Python` API.
214215
The `RcppTskit C++` API aims to mirror the `tskit C` API functions and semantics,
215-
but is deliberately `R` oriented
216+
but is deliberately `R` oriented.
216217
When we intentionally deviate (for example, to support `R` idioms or safety),
217218
we document the rationale and test the chosen behaviour.
218219

@@ -223,7 +224,8 @@ First install `RcppTskit` from CRAN and load it.
223224
```{r}
224225
#| label: pre-setup
225226
#| include: false
226-
# Had issues on Windows (R reported that RcppTskit is not installed, which is odd).
227+
# Had issues on GitHub Windows
228+
# (R reported that RcppTskit is not installed, which is odd).
227229
# This tries to "restore" the library path.
228230
lib_env <- Sys.getenv("R_LIBS")
229231
if (nzchar(lib_env)) {
@@ -264,10 +266,30 @@ tc$print()
264266
# Convert the table collection to tree sequence
265267
ts2 <- tc$tree_sequence()
266268
267-
# Explore the help pages
269+
# Users should explore the help pages
268270
help(package = "RcppTskit")
269271
```
270272

273+
Developers should also explore the low-level `R` and `C++` functions.
274+
Their names all start with `rtsk_` and are accessible via `RcppTskit:::`.
275+
For example, the above `R` function `ts_load()` effectively calls:
276+
277+
```{r}
278+
#| label: use_case_1_dev_funcs
279+
# Low-level R function, which further calls the C++ function
280+
RcppTskit:::rtsk_treeseq_load
281+
282+
# C++ function (see also the C++ source code)
283+
RcppTskit:::`_RcppTskit_rtsk_treeseq_load`
284+
285+
# The same as the ts_load() example, but exposing the external pointer
286+
xptr <- RcppTskit:::rtsk_treeseq_load(ts_file)
287+
methods::is(xptr)
288+
289+
# We pass the external pointer to other low-level functions
290+
RcppTskit:::rtsk_treeseq_get_num_individuals(xptr)
291+
```
292+
271293
### 2) Pass a tree sequence between `R` and reticulate or standard `Python`
272294

273295
```{r}

0 commit comments

Comments
 (0)