@@ -157,16 +157,20 @@ after we describe the implemented data and class model.
157157
158158## Data and class model
159159
160- ` RcppTskit ` represents a tree sequence as a lightweight R object of R6 class ` TreeSequence ` .
161- R6 class was partially chosen so the R code calls resemble Python code.
162- ` TreeSequence ` wraps an external pointer (` externalptr ` ) to the ` tskit `
163- C data structure (` tsk_treeseq_t ` ).
164- Most methods (for example, ` ts$num_individuals() ` , ` ts$dump() ` , etc.)
160+ ` RcppTskit ` represents a tree sequence as a lightweight R6 object of class ` TreeSequence ` .
161+ The R6 class was chosen in part so that ` TreeSequence ` method calls in R
162+ resemble the tskit Python API.
163+ ` TreeSequence ` wraps an external pointer (` externalptr ` ) to
164+ the ` tskit ` C object structure ` tsk_treeseq_t ` .
165+ Most methods (for example, ` ts$num_individuals() ` and ` ts$dump() ` )
165166call the ` tskit ` C API via ` Rcpp ` ,
166- so the calls are fast and the object is not copied
167- unless you explicitly write/read or change it.
167+ so calls are fast and the object is not copied
168+ unless you explicitly modify it.
168169The underlying pointer is exposed as ` TreeSequence$pointer `
169- for developers and advanced users that can write C++ code.
170+ for developers and advanced users who work with C++.
171+ In C++, the pointer has type ` RcppTskit_treeseq_xptr ` ,
172+ and the tree sequence memory is released by the ` Rcpp::XPtr `
173+ finaliser when the pointer is garbage-collected in R.
170174
171175## For typical use cases
172176
@@ -256,9 +260,9 @@ ts$num_individuals() # 2 (if you have ran the above Python code)
256260#| label: use_case_3
257261# Write a C++ function as multi-line character string
258262codeString <- '
259- #include <tskit.h >
263+ #include <RcppTskit.hpp >
260264 int ts_num_individuals(SEXP ts) {
261- Rcpp::XPtr<tsk_treeseq_t> ts_xptr(ts);
265+ RcppTskit_treeseq_xptr ts_xptr(ts);
262266 return (int) tsk_treeseq_get_num_individuals(ts_xptr);
263267 }'
264268
@@ -285,28 +289,33 @@ ts$num_individuals()
285289
286290### 4) Call ` tskit ` C API in C++ code in another R package
287291
288- To call the ` tskit ` C API in your own R package via ` Rcpp ` you can leverage ` RcppTskit ` .
289- Just follow the steps below and check how these were implemented in
290- the test R package ` RcppTskitTestPkgLinkingTo ` at TODO.
292+ To call the ` tskit ` C API in your own R package via ` Rcpp `
293+ you can leverage ` RcppTskit ` , which will simplify your installation
294+ and enable you to quickly call
295+ To do this, follow the steps below and check how these were implemented in
296+ the test R package ` RcppTskitTestLinkingTo ` at https://github.com/HighlanderLab/RcppTskitTestLinking .
291297
292- a) Open ` DESCRIPTION ` file and add ` RcppTskit ` to the ` LinkingTo: ` field,
293- TODO: likely also ` Imports: ` field.
298+ a) Open ` DESCRIPTION ` file and
299+ add ` RcppTskit ` to the ` Imports: ` and ` LinkingTo: ` field, and further
300+ add ` Rcpp ` to ` LinkingTo: ` field as a minimum.
294301
295- TODO: And Rcpp too?
302+ b) Create ` R/YourPackage-package.R ` file and add to it at a minimum:
303+ ` #' @import RcppTskit ` in one line and ` "_PACKAGE" ` in another line,
304+ so that ` devtools ` will manage your package ` NAMESPACE ` imports.
296305
297- b ) Add ` #include <tskit.h > ` as needed to your C++ header files in ` src ` directory.
306+ c ) Add ` #include <RcppTskit.hpp > ` as needed to your C++ header files in ` src ` directory.
298307
299- c ) Add ` // [[Rcpp::depends(RcppTskit)]] ` to your C++ files in ` src ` directory.
308+ d ) Add ` // [[Rcpp::depends(RcppTskit)]] ` to your C++ files in ` src ` directory.
300309
301- d ) Add ` // [[Rcpp::plugins(RcppTskit)]] ` to your C++ files in ` src ` directory.
310+ e ) Add ` // [[Rcpp::plugins(RcppTskit)]] ` to your C++ files in ` src ` directory.
302311
303- e ) Call ` tskit ` C API as needed in your C++ code in ` src ` directory.
312+ f ) Call ` RcppTskit ` C++ API and ` tskit ` C API as needed in your C++ files in ` src ` directory.
304313
305- f ) Configure your package build to use the ` RcppTskit ` library file
314+ g ) Configure your package build to use the ` RcppTskit ` library file
306315 with the following steps:
307316
308317 - Add ` src/Makevars.in ` and ` src/Makevars.win.in ` files with
309- ` PKG_LIB = @RCPPTSKIT_LIB@` flag, in addition to other flags.
318+ ` PKG_LIBS = @RCPPTSKIT_LIB@` flag, in addition to other flags.
310319
311320 - Add ` tools/configure.R ` file,
312321 which will replace ` @RCPPTSKIT_LIB@ ` in ` src/Makevars.in ` and ` src/Makevars.win.in `
@@ -319,7 +328,7 @@ f) Configure your package build to use the `RcppTskit` library file
319328 - Add ` cleanup ` and ` cleanup.win ` scripts (and make them executable)
320329 to remove ` src/Makevars ` and ` src/Makevars.win ` as well as compilation files.
321330
322- g ) You should now be ready to build, check, and install your package using
331+ h ) You should now be ready to build, check, and install your package using
323332 ` devtools::build() ` , ` devtools::check() ` , and ` devtools::install() `
324333 or their ` R CMD ` equivalents.
325334
0 commit comments