Skip to content

Commit 8dc6cd4

Browse files
committed
Add a vignette
Fixes #10 #28 #27
1 parent 67a3a8e commit 8dc6cd4

14 files changed

Lines changed: 667 additions & 518 deletions

.gitignore

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
*.Rproj
1+
.DS_Store
22
.Rproj.user
33
.Rhistory
44
.RData
55
.Ruserdata
66
.vscode
7+
*.Rproj
8+
RcppTskit/**/.quarto/
9+
RcppTskit/inst/doc
710
RcppTskit/src/*.o
811
RcppTskit/src/tskit/*.o
912
RcppTskit/src/*.so
1013
RcppTskit/src/*.dll*
1114
RcppTskit/src/Makevars
1215
RcppTskit/src/Makevars.win
16+
RcppTskit/vignettes/*.html
17+
RcppTskit/vignettes/*.R
18+
RcppTskit/vignettes/*_files
1319
test.trees
14-
.DS_Store
15-
*.html

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ Tskit provides Python, C, and Rust APIs. The Python API can be called from R
99
via the `reticulate` R package to seamlessly load and analyse a tree sequence,
1010
as described at https://tskit.dev/tutorials/RcppTskit.html.
1111
`RcppTskit` provides R access to the `tskit` C API for use cases where the
12-
`reticulate` approach is not optimal. For example, for high-performance and
13-
low-level work with tree sequences. Currently, `RcppTskit` provides a very limited
12+
`reticulate` option is not optimal. For example, for high-performance and
13+
low-level work with tree sequences. Currently, `RcppTskit` provides a limited
1414
number of R functions due to the availability of extensive Python API and
15-
the `reticulate` approach.
15+
the `reticulate` option.
1616

17-
See more details on the state of the tree sequence ecosystem and aims for
18-
`RcppTskit` in [RcppTskit/inst/STATE_and_AIMS.md](RcppTskit/inst/STATE_and_AIMS.md),
17+
See more details on the state of the tree sequence ecosystem and aims of
18+
`RcppTskit` in [RcppTskit/vignettes/RcppTskit_intro.qmd](RcppTskit/vignettes/RcppTskit_intro.qmd),
1919
including examples on how to use it on its own or to develop new R packages.
2020

21-
TODO: Think how to best point to use cases. Probably best to point to vignette and pkgdown!?
22-
https://github.com/HighlanderLab/RcppTskit/issues/10
23-
2421
## Status
2522

2623
<!-- badges: start -->
@@ -31,7 +28,7 @@ TODO: Think how to best point to use cases. Probably best to point to vignette a
3128
[![CRAN version](https://www.r-pkg.org/badges/version/RcppTskit)](https://CRAN.R-project.org/package=RcppTskit) <!-- Row 2, Col 1 --> ![GitHub version (main)](https://img.shields.io/github/r-package/v/HighlanderLab/RcppTskit/main?filename=RcppTskit%2FDESCRIPTION&label=Github) <!-- Row 2, Col 2 --> [![Downloads - total](https://cranlogs.r-pkg.org/badges/grand-total/RcppTskit)](https://cranlogs.r-pkg.org/badges/grand-total/RcppTskit) <!-- Row 2, Col 3 -->
3229

3330
<!-- line break 2 -->
34-
[![CRAN R CMD check](https://cranchecks.info/badges/summary/RcppTskit)](https://cran.r-project.org/web/checks/check_results_RcppTskit.html) <!-- Row 3, Col 1 --> ![GitHub R CMD check](https://img.shields.io/github/actions/workflow/status/HighlanderLab/RcppTskit/R-CMD-check.yaml?label=GitHub%20R%20CMD%20check) <!-- Row 3, Col 2 --> [![Codecov test coverage](https://codecov.io/gh/HighlanderLab/RcppTskit/graph/badge.svg)](https://app.codecov.io/gh/HighlanderLab/RcppTskit) <!-- Row 3, Col 3 -->
31+
[![CRAN R CMD check](https://cranchecks.info/badges/summary/RcppTskit)](https://cran.r-project.org/web/checks/check_results_RcppTskit.html) <!-- Row 3, Col 1 --> [![GitHub R CMD check](https://img.shields.io/github/actions/workflow/status/HighlanderLab/RcppTskit/R-CMD-check.yaml?label=GitHub%20R%20CMD%20check)](https://github.com/HighlanderLab/RcppTskit/actions/workflows/R-CMD-check.yaml) <!-- Row 3, Col 2 --> [![Codecov test coverage](https://codecov.io/gh/HighlanderLab/RcppTskit/graph/badge.svg)](https://app.codecov.io/gh/HighlanderLab/RcppTskit) <!-- Row 3, Col 3 -->
3532

3633
<!-- badges: end -->
3734

RcppTskit/.Rbuildignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
^\.clang-format$
1010
^\.covrignore$
1111
^\.github$
12-
^pkg_dev_notes\.md$
1312
^codecov\.yaml$
14-
^notes_pkg_dev\.Rmd$
1513
^inst/examples/create_test\.trees\.R$
1614
^inst/examples/create_test\.trees\.py$
15+
^notes_pkg_dev\.Rmd$
16+
^pkg_dev_notes\.md$
17+
^tests/testthat/_snaps$
18+
^vignettes/\.quarto$
19+
^vignettes/*_files$

RcppTskit/DESCRIPTION

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@ Description: Tskit enables performant storage, manipulation, and analysis
1515
via the `reticulate` R package to seamlessly load and analyse
1616
a tree sequence as described at https://tskit.dev/tutorials/RcppTskit.html.
1717
`RcppTskit` provides R access to the `tskit` C API for use cases where the
18-
`reticulate` approach is not optimal. For example, for high-performance and
19-
low-level work with tree sequences. Currently, `RcppTskit` provides a very
20-
limited number of R functions due to the availability of extensive Python API
21-
and the `reticulate` approach.
18+
`reticulate` option is not optimal. For example, for high-performance and
19+
low-level work with tree sequences. Currently, `RcppTskit` provides a limited
20+
number of R functions due to the availability of extensive Python API and
21+
the `reticulate` option.
2222
URL: https://github.com/highlanderlab/RcppTskit
2323
License: MIT + file LICENSE
2424
Depends: R (>= 4.0.0)
2525
Imports: methods, R6, Rcpp (>= 1.1.0), reticulate
2626
LinkingTo: Rcpp
27-
Suggests: covr, spelling, testthat
27+
Suggests:
28+
covr,
29+
knitr,
30+
quarto,
31+
spelling,
32+
testthat
2833
RoxygenNote: 7.3.3
2934
Encoding: UTF-8
3035
Language: en-GB
36+
VignetteBuilder: quarto

RcppTskit/NEWS.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ This is the first release.
1313
- Initial version of RcppTskit using the tskit C API (version 1.3.0).
1414
- TreeSequence R6 class so R code looks Pythonic.
1515
- `ts_load()` or `TreeSequence$new()` to load a tree sequence from file into R.
16-
- Methods to summarise a tree sequence and its contents `ts$print()`, `ts$num_nodes()`, etc.
16+
- Methods to summarise a tree sequence and its contents `ts$print()`,
17+
`ts$num_nodes()`, etc.
1718
- Method to save a tree sequence to a file `ts$dump()`.
18-
- Method to push tree sequence between R and reticulate Python (TODO).
19-
- Most methods have underlying C++ function that work with a pointer to tree sequence object,
20-
for example, `RcppTskit:::ts_load_ptr()`.
19+
- Method to push tree sequence between R and reticulate Python
20+
`ts$r_to_py()` and `ts_py_to_r()`.
21+
- Most methods have an underlying (unexported) C++ function that works with
22+
a pointer to tree sequence object,for example, `RcppTskit:::ts_load_ptr()`.
23+
- All implemented functionality is documented and demonstrated with a vignette.

RcppTskit/R/RcppTskit-package.R

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#' via the `reticulate` R package to seamlessly load and analyse a tree sequence
99
#' as described at https://tskit.dev/tutorials/tskitr.html.
1010
#' `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
1313
#' limited number of R functions due to the availability of extensive Python API
14-
#' and the `reticulate` approach.
14+
#' and the `reticulate` option.
1515
#' @keywords internal
1616
#'
1717
#' @useDynLib RcppTskit, .registration = TRUE
@@ -21,76 +21,7 @@
2121
#' @importFrom reticulate is_py_object import py_module_available py_require
2222
#'
2323
#' @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")
9425
"_PACKAGE"
9526

9627
#' Providing an inline plugin so we can call tskit C API with functions like

0 commit comments

Comments
 (0)