|
8 | 8 | #' via the `reticulate` R package to seamlessly load and analyse a tree sequence |
9 | 9 | #' as described at https://tskit.dev/tutorials/tskitr.html. |
10 | 10 | #' `RcppTskit` provides R access to the `tskit` C API for use cases where the |
11 | | -#' `reticulate` approach is not optimal. For example, for high-performance |
12 | | -#' and low-level work with tree sequences. Currently, `RcppTskit` provides a very |
| 11 | +#' `reticulate` option is not optimal. For example, for high-performance |
| 12 | +#' and low-level work with tree sequences. Currently, `RcppTskit` provides a |
13 | 13 | #' limited number of R functions due to the availability of extensive Python API |
14 | | -#' and the `reticulate` approach. |
| 14 | +#' and the `reticulate` option. |
15 | 15 | #' @keywords internal |
16 | 16 | #' |
17 | 17 | #' @useDynLib RcppTskit, .registration = TRUE |
|
21 | 21 | #' @importFrom reticulate is_py_object import py_module_available py_require |
22 | 22 | #' |
23 | 23 | #' @examples |
24 | | -#' \dontshow{# Providing the examples here so we test them via R CMD check} |
25 | | -#' # Here are examples showcasing what you can do with RcppTskit |
26 | | -#' |
27 | | -#' # 1) Load a tree sequence into R and summarise it |
28 | | -#' # Load a tree sequence |
29 | | -#' ts_file <- system.file("examples/test.trees", package = "RcppTskit") |
30 | | -#' ts <- ts_load(ts_file) |
31 | | -#' |
32 | | -#' # Print summary of the tree sequence |
33 | | -#' ts$num_individuals() |
34 | | -#' ts |
35 | | -#' |
36 | | -#' # 2) Pass tree sequence between R and reticulate or standard Python |
37 | | -#' |
38 | | -#' # Tree sequence in R |
39 | | -#' ts_file <- system.file("examples/test.trees", package = "RcppTskit") |
40 | | -#' ts <- ts_load(ts_file) |
41 | | -#' |
42 | | -#' # If you have a tree sequence in R and want to use tskit Python API, use |
43 | | -#' ts_py <- ts$r_to_py() |
44 | | -#' # ... continue in reticulate Python ... |
45 | | -#' ts_py$num_individuals # 80 |
46 | | -#' ts2_py = ts_py$simplify(samples = c(0L, 1L, 2L, 3L)) |
47 | | -#' ts2_py$num_individuals # 2 |
48 | | -#' # ... and to bring it back to R use ... |
49 | | -#' ts2 <- ts_py_to_r(ts2_py) |
50 | | -#' ts2$num_individuals() # 2 |
51 | | -#' |
52 | | -#' # If you prefer standard (non-reticulate) Python, use |
53 | | -#' ts_file <- tempfile() |
54 | | -#' print(ts_file) |
55 | | -#' ts$dump(file = ts_file) |
56 | | -#' # ... continue in standard Python ... |
57 | | -#' # import tskit |
58 | | -#' # ts = tskit.load("insert_ts_file_path_here") |
59 | | -#' # ts.num_individuals # 80 |
60 | | -#' # ts2 = ts.simplify(samples = [0, 1, 2, 3]) |
61 | | -#' # ts2.num_individuals # 2 |
62 | | -#' # ts2.dump("insert_ts_file_path_here") |
63 | | -#' # ... and to bring it back to R use ... |
64 | | -#' ts2 <- ts_load(ts_file) |
65 | | -#' ts$num_individuals() # 2 (if you have ran the above Python code) |
66 | | -#' |
67 | | -#' # 3) Call tskit C API in C++ code in R session or script |
68 | | -#' library(Rcpp) |
69 | | -#' # Write and compile a C++ function |
70 | | -#' codeString <- ' |
71 | | -#' #include <tskit.h> |
72 | | -#' int ts_num_individuals(SEXP ts) { |
73 | | -#' Rcpp::XPtr<tsk_treeseq_t> ts_xptr(ts); |
74 | | -#' return (int) tsk_treeseq_get_num_individuals(ts_xptr); |
75 | | -#' }' |
76 | | -#' ts_num_individuals2 <- Rcpp::cppFunction(code=codeString, |
77 | | -#' depends="RcppTskit", |
78 | | -#' plugins="RcppTskit") |
79 | | -#' # We must specify both the `depends` and `plugins` arguments! |
80 | | -#' |
81 | | -#' # Load a tree sequence |
82 | | -#' ts_file <- system.file("examples/test.trees", package="RcppTskit") |
83 | | -#' ts <- ts_load(ts_file) |
84 | | -#' |
85 | | -#' # Apply the compiled function |
86 | | -#' ts_num_individuals2(ts$pointer) |
87 | | -#' |
88 | | -#' # An identical RcppTskit implementation |
89 | | -#' ts$num_individuals() |
90 | | -#' |
91 | | -#' # 4) Call `tskit` C API in C++ code in another R package |
92 | | -#' # TODO: Show vignette here |
93 | | -#' # https://github.com/HighlanderLab/RcppTskit/issues/10 |
| 24 | +#' vignette(package="RcppTskit") |
94 | 25 | "_PACKAGE" |
95 | 26 |
|
96 | 27 | #' Providing an inline plugin so we can call tskit C API with functions like |
|
0 commit comments