diff --git a/RcppTskit/DESCRIPTION b/RcppTskit/DESCRIPTION index d2c174f..93583f8 100644 --- a/RcppTskit/DESCRIPTION +++ b/RcppTskit/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: RcppTskit Title: 'R' Access to the 'tskit C' API -Version: 0.2.0.9000 +Version: 0.3.0 Date: 2026-01-27 Authors@R: c( person("Gregor", "Gorjanc", , "gregor.gorjanc@gmail.com", role = c("aut", "cre", "cph"), diff --git a/RcppTskit/NEWS.md b/RcppTskit/NEWS.md index 1aab60d..f2786b3 100644 --- a/RcppTskit/NEWS.md +++ b/RcppTskit/NEWS.md @@ -1,10 +1,10 @@ # RcppTskit news -All notable changes to RcppTskit are documented in this file. +All notable changes to `RcppTskit` are documented in this file. The file format is based on [Keep a Changelog](https://keepachangelog.com), and releases adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [0.3.0] 2026-MM-DD ### Added (new features) @@ -23,7 +23,15 @@ and releases adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html - `TableCollection$sequence_length()` to query the sequence length. - `TableCollection$time_units()` to query the time units. - `TableCollection$has_index()` to query whether edge indexes are present. - - TODO +- Added a public header and defaults for downstream use of `C++` functions in + `inst/include/RcppTskit_public.hpp`, included by `inst/include/RcppTskit.hpp`. +- TODO + +### Changed + +- Renamed low-level external-pointer API names from `*_ptr_*` to `*_xptr_*` + (for example, `ts_ptr_load()` to `ts_xptr_load()`) to make external-pointer + vs standard/raw-pointer semantics explicit. ## [0.2.0] - 2026-02-22 diff --git a/RcppTskit/R/Class-TableCollection.R b/RcppTskit/R/Class-TableCollection.R index 7c7b726..c8ea710 100644 --- a/RcppTskit/R/Class-TableCollection.R +++ b/RcppTskit/R/Class-TableCollection.R @@ -44,7 +44,7 @@ TableCollection <- R6Class( skip_tables = skip_tables, skip_reference_sequence = skip_reference_sequence ) - self$pointer <- tc_ptr_load(file = file, options = options) + self$pointer <- tc_xptr_load(file = file, options = options) } else { if (!is.null(pointer) && !is(pointer, "externalptr")) { stop("pointer must be an object of externalptr class!") @@ -67,7 +67,7 @@ TableCollection <- R6Class( #' tc$write(dump_file) # alias #' \dontshow{file.remove(dump_file)} dump = function(file) { - tc_ptr_dump(self$pointer, file = file, options = 0L) + tc_xptr_dump(self$pointer, file = file, options = 0L) }, #' @description Alias for \code{\link[=TableCollection]{TableCollection$dump}}. @@ -91,8 +91,8 @@ TableCollection <- R6Class( # TODO: Should we also use TSK_TS_INIT_COMPUTE_MUTATION_PARENTS in TableCollection$tree_sequence()? #65 # https://github.com/HighlanderLab/RcppTskit/issues/65 init_options <- bitwShiftL(1L, 0) - ts_ptr <- tc_ptr_to_ts_ptr(self$pointer, options = init_options) - TreeSequence$new(pointer = ts_ptr) + ts_xptr <- tc_xptr_to_ts_xptr(self$pointer, options = init_options) + TreeSequence$new(pointer = ts_xptr) }, #' @description Get the sequence length. @@ -101,7 +101,7 @@ TableCollection <- R6Class( #' tc <- tc_load(tc_file) #' tc$sequence_length() sequence_length = function() { - tc_ptr_sequence_length(self$pointer) + tc_xptr_sequence_length(self$pointer) }, #' @description Get the time units string. @@ -110,7 +110,7 @@ TableCollection <- R6Class( #' tc <- tc_load(tc_file) #' tc$time_units() time_units = function() { - tc_ptr_time_units(self$pointer) + tc_xptr_time_units(self$pointer) }, #' @description Get whether the table collection has edge indexes. @@ -119,7 +119,7 @@ TableCollection <- R6Class( #' tc <- tc_load(tc_file) #' tc$has_index() has_index = function() { - tc_ptr_has_index(self$pointer) + tc_xptr_has_index(self$pointer) }, #' @description Get whether the table collection has a reference genome sequence. @@ -131,7 +131,7 @@ TableCollection <- R6Class( #' tc2 <- tc_load(tc_file2) #' tc2$has_reference_sequence() has_reference_sequence = function() { - tc_ptr_has_reference_sequence(self$pointer) + tc_xptr_has_reference_sequence(self$pointer) }, #' @description Get the file UUID string. @@ -142,7 +142,7 @@ TableCollection <- R6Class( #' tc <- tc_load(tc_file) #' tc$file_uuid() file_uuid = function() { - tc_ptr_file_uuid(self$pointer) + tc_xptr_file_uuid(self$pointer) }, #' @description This function saves a table collection from R to disk and @@ -175,7 +175,7 @@ TableCollection <- R6Class( #' } #' } r_to_py = function(tskit_module = get_tskit_py(), cleanup = TRUE) { - tc_ptr_r_to_py( + tc_xptr_r_to_py( self$pointer, tskit_module = tskit_module, cleanup = cleanup @@ -192,7 +192,7 @@ TableCollection <- R6Class( #' tc$print() #' tc print = function() { - ret <- tc_ptr_print(self$pointer) + ret <- tc_xptr_print(self$pointer) # These are not hit since testing is not interactive # nocov start if (interactive()) { diff --git a/RcppTskit/R/Class-TreeSequence.R b/RcppTskit/R/Class-TreeSequence.R index b090636..eb5de99 100644 --- a/RcppTskit/R/Class-TreeSequence.R +++ b/RcppTskit/R/Class-TreeSequence.R @@ -50,7 +50,7 @@ TreeSequence <- R6Class( skip_tables = skip_tables, skip_reference_sequence = skip_reference_sequence ) - self$pointer <- ts_ptr_load(file = file, options = options) + self$pointer <- ts_xptr_load(file = file, options = options) } else { if (!is.null(pointer) && !is(pointer, "externalptr")) { stop("pointer must be an object of externalptr class!") @@ -73,7 +73,7 @@ TreeSequence <- R6Class( #' ts$write(dump_file) # alias #' \dontshow{file.remove(dump_file)} dump = function(file) { - ts_ptr_dump(self$pointer, file = file, options = 0L) + ts_xptr_dump(self$pointer, file = file, options = 0L) }, #' @description Alias for \code{\link[=TreeSequence]{TreeSequence$dump}}. @@ -92,8 +92,8 @@ TreeSequence <- R6Class( #' tc <- ts$dump_tables() #' is(tc) dump_tables = function() { - tc_ptr <- ts_ptr_to_tc_ptr(self$pointer) - TableCollection$new(pointer = tc_ptr) + tc_xptr <- ts_xptr_to_tc_xptr(self$pointer) + TableCollection$new(pointer = tc_xptr) }, #' @description Print a summary of a tree sequence and its contents. @@ -106,7 +106,7 @@ TreeSequence <- R6Class( #' ts$print() #' ts print = function() { - ret <- ts_ptr_print(self$pointer) + ret <- ts_xptr_print(self$pointer) # These are not hit since testing is not interactive # nocov start if (interactive()) { @@ -146,7 +146,7 @@ TreeSequence <- R6Class( #' } #' } r_to_py = function(tskit_module = get_tskit_py(), cleanup = TRUE) { - ts_ptr_r_to_py( + ts_xptr_r_to_py( self$pointer, tskit_module = tskit_module, cleanup = cleanup @@ -159,7 +159,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$num_provenances() num_provenances = function() { - ts_ptr_num_provenances(self$pointer) + ts_xptr_num_provenances(self$pointer) }, #' @description Get the number of populations in a tree sequence. @@ -168,7 +168,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$num_populations() num_populations = function() { - ts_ptr_num_populations(self$pointer) + ts_xptr_num_populations(self$pointer) }, #' @description Get the number of migrations in a tree sequence. @@ -177,7 +177,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$num_migrations() num_migrations = function() { - ts_ptr_num_migrations(self$pointer) + ts_xptr_num_migrations(self$pointer) }, #' @description Get the number of individuals in a tree sequence. @@ -186,7 +186,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$num_individuals() num_individuals = function() { - ts_ptr_num_individuals(self$pointer) + ts_xptr_num_individuals(self$pointer) }, #' @description Get the number of samples (of nodes) in a tree sequence. @@ -195,7 +195,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$num_samples() num_samples = function() { - ts_ptr_num_samples(self$pointer) + ts_xptr_num_samples(self$pointer) }, #' @description Get the number of nodes in a tree sequence. @@ -204,7 +204,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$num_nodes() num_nodes = function() { - ts_ptr_num_nodes(self$pointer) + ts_xptr_num_nodes(self$pointer) }, #' @description Get the number of edges in a tree sequence. @@ -213,7 +213,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$num_edges() num_edges = function() { - ts_ptr_num_edges(self$pointer) + ts_xptr_num_edges(self$pointer) }, #' @description Get the number of trees in a tree sequence. @@ -222,7 +222,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$num_trees() num_trees = function() { - ts_ptr_num_trees(self$pointer) + ts_xptr_num_trees(self$pointer) }, #' @description Get the number of sites in a tree sequence. @@ -231,7 +231,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$num_sites() num_sites = function() { - ts_ptr_num_sites(self$pointer) + ts_xptr_num_sites(self$pointer) }, #' @description Get the number of mutations in a tree sequence. @@ -240,7 +240,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$num_mutations() num_mutations = function() { - ts_ptr_num_mutations(self$pointer) + ts_xptr_num_mutations(self$pointer) }, #' @description Get the sequence length. @@ -249,7 +249,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$sequence_length() sequence_length = function() { - ts_ptr_sequence_length(self$pointer) + ts_xptr_sequence_length(self$pointer) }, #' @description Get the discrete genome status. @@ -263,7 +263,7 @@ TreeSequence <- R6Class( #' ts2 <- ts_load(ts_file2) #' ts2$discrete_genome() discrete_genome = function() { - ts_ptr_discrete_genome(self$pointer) + ts_xptr_discrete_genome(self$pointer) }, #' @description Get whether the tree sequence has a reference genome sequence. @@ -275,7 +275,7 @@ TreeSequence <- R6Class( #' ts2 <- ts_load(ts_file2) #' ts2$has_reference_sequence() has_reference_sequence = function() { - ts_ptr_has_reference_sequence(self$pointer) + ts_xptr_has_reference_sequence(self$pointer) }, #' @description Get the time units string. @@ -284,7 +284,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$time_units() time_units = function() { - ts_ptr_time_units(self$pointer) + ts_xptr_time_units(self$pointer) }, #' @description Get the discrete time status. @@ -298,7 +298,7 @@ TreeSequence <- R6Class( #' ts2 <- ts_load(ts_file2) #' ts2$discrete_time() discrete_time = function() { - ts_ptr_discrete_time(self$pointer) + ts_xptr_discrete_time(self$pointer) }, #' @description Get the min time in node table and mutation table. @@ -307,7 +307,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$min_time() min_time = function() { - ts_ptr_min_time(self$pointer) + ts_xptr_min_time(self$pointer) }, #' @description Get the max time in node table and mutation table. @@ -316,7 +316,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$max_time() max_time = function() { - ts_ptr_max_time(self$pointer) + ts_xptr_max_time(self$pointer) }, #' @description Get the length of metadata in a tree sequence and its tables. @@ -326,7 +326,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$metadata_length() metadata_length = function() { - ts_ptr_metadata_length(self$pointer) + ts_xptr_metadata_length(self$pointer) }, #' @description Get the file UUID string. @@ -337,7 +337,7 @@ TreeSequence <- R6Class( #' ts <- ts_load(ts_file) #' ts$file_uuid() file_uuid = function() { - ts_ptr_file_uuid(self$pointer) + ts_xptr_file_uuid(self$pointer) } ) ) diff --git a/RcppTskit/R/RcppExports.R b/RcppTskit/R/RcppExports.R index b194571..9ce813d 100644 --- a/RcppTskit/R/RcppExports.R +++ b/RcppTskit/R/RcppExports.R @@ -23,136 +23,136 @@ tskit_version <- function() { .Call(`_RcppTskit_tskit_version`) } -ts_ptr_load <- function(file, options = 0L) { - .Call(`_RcppTskit_ts_ptr_load`, file, options) +ts_xptr_load <- function(file, options = 0L) { + .Call(`_RcppTskit_ts_xptr_load`, file, options) } -tc_ptr_load <- function(file, options = 0L) { - .Call(`_RcppTskit_tc_ptr_load`, file, options) +tc_xptr_load <- function(file, options = 0L) { + .Call(`_RcppTskit_tc_xptr_load`, file, options) } -ts_ptr_dump <- function(ts, file, options = 0L) { - invisible(.Call(`_RcppTskit_ts_ptr_dump`, ts, file, options)) +ts_xptr_dump <- function(ts, file, options = 0L) { + invisible(.Call(`_RcppTskit_ts_xptr_dump`, ts, file, options)) } -tc_ptr_dump <- function(tc, file, options = 0L) { - invisible(.Call(`_RcppTskit_tc_ptr_dump`, tc, file, options)) +tc_xptr_dump <- function(tc, file, options = 0L) { + invisible(.Call(`_RcppTskit_tc_xptr_dump`, tc, file, options)) } -ts_ptr_to_tc_ptr <- function(ts, options = 0L) { - .Call(`_RcppTskit_ts_ptr_to_tc_ptr`, ts, options) +ts_xptr_to_tc_xptr <- function(ts, options = 0L) { + .Call(`_RcppTskit_ts_xptr_to_tc_xptr`, ts, options) } -tc_ptr_to_ts_ptr <- function(tc, options = 0L) { - .Call(`_RcppTskit_tc_ptr_to_ts_ptr`, tc, options) +tc_xptr_to_ts_xptr <- function(tc, options = 0L) { + .Call(`_RcppTskit_tc_xptr_to_ts_xptr`, tc, options) } -ts_ptr_num_provenances <- function(ts) { - .Call(`_RcppTskit_ts_ptr_num_provenances`, ts) +ts_xptr_num_provenances <- function(ts) { + .Call(`_RcppTskit_ts_xptr_num_provenances`, ts) } -ts_ptr_num_populations <- function(ts) { - .Call(`_RcppTskit_ts_ptr_num_populations`, ts) +ts_xptr_num_populations <- function(ts) { + .Call(`_RcppTskit_ts_xptr_num_populations`, ts) } -ts_ptr_num_migrations <- function(ts) { - .Call(`_RcppTskit_ts_ptr_num_migrations`, ts) +ts_xptr_num_migrations <- function(ts) { + .Call(`_RcppTskit_ts_xptr_num_migrations`, ts) } -ts_ptr_num_individuals <- function(ts) { - .Call(`_RcppTskit_ts_ptr_num_individuals`, ts) +ts_xptr_num_individuals <- function(ts) { + .Call(`_RcppTskit_ts_xptr_num_individuals`, ts) } -ts_ptr_num_samples <- function(ts) { - .Call(`_RcppTskit_ts_ptr_num_samples`, ts) +ts_xptr_num_samples <- function(ts) { + .Call(`_RcppTskit_ts_xptr_num_samples`, ts) } -ts_ptr_num_nodes <- function(ts) { - .Call(`_RcppTskit_ts_ptr_num_nodes`, ts) +ts_xptr_num_nodes <- function(ts) { + .Call(`_RcppTskit_ts_xptr_num_nodes`, ts) } -ts_ptr_num_edges <- function(ts) { - .Call(`_RcppTskit_ts_ptr_num_edges`, ts) +ts_xptr_num_edges <- function(ts) { + .Call(`_RcppTskit_ts_xptr_num_edges`, ts) } -ts_ptr_num_trees <- function(ts) { - .Call(`_RcppTskit_ts_ptr_num_trees`, ts) +ts_xptr_num_trees <- function(ts) { + .Call(`_RcppTskit_ts_xptr_num_trees`, ts) } -ts_ptr_num_sites <- function(ts) { - .Call(`_RcppTskit_ts_ptr_num_sites`, ts) +ts_xptr_num_sites <- function(ts) { + .Call(`_RcppTskit_ts_xptr_num_sites`, ts) } -ts_ptr_num_mutations <- function(ts) { - .Call(`_RcppTskit_ts_ptr_num_mutations`, ts) +ts_xptr_num_mutations <- function(ts) { + .Call(`_RcppTskit_ts_xptr_num_mutations`, ts) } -ts_ptr_sequence_length <- function(ts) { - .Call(`_RcppTskit_ts_ptr_sequence_length`, ts) +ts_xptr_sequence_length <- function(ts) { + .Call(`_RcppTskit_ts_xptr_sequence_length`, ts) } -ts_ptr_discrete_genome <- function(ts) { - .Call(`_RcppTskit_ts_ptr_discrete_genome`, ts) +ts_xptr_discrete_genome <- function(ts) { + .Call(`_RcppTskit_ts_xptr_discrete_genome`, ts) } -ts_ptr_has_reference_sequence <- function(ts) { - .Call(`_RcppTskit_ts_ptr_has_reference_sequence`, ts) +ts_xptr_has_reference_sequence <- function(ts) { + .Call(`_RcppTskit_ts_xptr_has_reference_sequence`, ts) } -ts_ptr_time_units <- function(ts) { - .Call(`_RcppTskit_ts_ptr_time_units`, ts) +ts_xptr_time_units <- function(ts) { + .Call(`_RcppTskit_ts_xptr_time_units`, ts) } -ts_ptr_discrete_time <- function(ts) { - .Call(`_RcppTskit_ts_ptr_discrete_time`, ts) +ts_xptr_discrete_time <- function(ts) { + .Call(`_RcppTskit_ts_xptr_discrete_time`, ts) } -ts_ptr_min_time <- function(ts) { - .Call(`_RcppTskit_ts_ptr_min_time`, ts) +ts_xptr_min_time <- function(ts) { + .Call(`_RcppTskit_ts_xptr_min_time`, ts) } -ts_ptr_max_time <- function(ts) { - .Call(`_RcppTskit_ts_ptr_max_time`, ts) +ts_xptr_max_time <- function(ts) { + .Call(`_RcppTskit_ts_xptr_max_time`, ts) } -ts_ptr_file_uuid <- function(ts) { - .Call(`_RcppTskit_ts_ptr_file_uuid`, ts) +ts_xptr_file_uuid <- function(ts) { + .Call(`_RcppTskit_ts_xptr_file_uuid`, ts) } -ts_ptr_summary <- function(ts) { - .Call(`_RcppTskit_ts_ptr_summary`, ts) +ts_xptr_summary <- function(ts) { + .Call(`_RcppTskit_ts_xptr_summary`, ts) } -ts_ptr_metadata_length <- function(ts) { - .Call(`_RcppTskit_ts_ptr_metadata_length`, ts) +ts_xptr_metadata_length <- function(ts) { + .Call(`_RcppTskit_ts_xptr_metadata_length`, ts) } -tc_ptr_sequence_length <- function(tc) { - .Call(`_RcppTskit_tc_ptr_sequence_length`, tc) +tc_xptr_sequence_length <- function(tc) { + .Call(`_RcppTskit_tc_xptr_sequence_length`, tc) } -tc_ptr_has_reference_sequence <- function(tc) { - .Call(`_RcppTskit_tc_ptr_has_reference_sequence`, tc) +tc_xptr_has_reference_sequence <- function(tc) { + .Call(`_RcppTskit_tc_xptr_has_reference_sequence`, tc) } -tc_ptr_time_units <- function(tc) { - .Call(`_RcppTskit_tc_ptr_time_units`, tc) +tc_xptr_time_units <- function(tc) { + .Call(`_RcppTskit_tc_xptr_time_units`, tc) } -tc_ptr_file_uuid <- function(tc) { - .Call(`_RcppTskit_tc_ptr_file_uuid`, tc) +tc_xptr_file_uuid <- function(tc) { + .Call(`_RcppTskit_tc_xptr_file_uuid`, tc) } -tc_ptr_has_index <- function(tc) { - .Call(`_RcppTskit_tc_ptr_has_index`, tc) +tc_xptr_has_index <- function(tc) { + .Call(`_RcppTskit_tc_xptr_has_index`, tc) } -tc_ptr_summary <- function(tc) { - .Call(`_RcppTskit_tc_ptr_summary`, tc) +tc_xptr_summary <- function(tc) { + .Call(`_RcppTskit_tc_xptr_summary`, tc) } -tc_ptr_metadata_length <- function(tc) { - .Call(`_RcppTskit_tc_ptr_metadata_length`, tc) +tc_xptr_metadata_length <- function(tc) { + .Call(`_RcppTskit_tc_xptr_metadata_length`, tc) } test_tsk_bug_assert_c <- function() { @@ -175,11 +175,11 @@ tsk_trace_errors_defined <- function() { .Call(`_RcppTskit_tsk_trace_errors_defined`) } -test_ts_ptr_to_tc_ptr_forced_error <- function(ts) { - .Call(`_RcppTskit_test_ts_ptr_to_tc_ptr_forced_error`, ts) +test_ts_xptr_to_tc_xptr_forced_error <- function(ts) { + .Call(`_RcppTskit_test_ts_xptr_to_tc_xptr_forced_error`, ts) } -test_tc_ptr_to_ts_ptr_forced_error <- function(tc) { - .Call(`_RcppTskit_test_tc_ptr_to_ts_ptr_forced_error`, tc) +test_tc_xptr_to_ts_xptr_forced_error <- function(tc) { + .Call(`_RcppTskit_test_tc_xptr_to_ts_xptr_forced_error`, tc) } diff --git a/RcppTskit/R/RcppTskit.R b/RcppTskit/R/RcppTskit.R index e13042a..48aac27 100644 --- a/RcppTskit/R/RcppTskit.R +++ b/RcppTskit/R/RcppTskit.R @@ -206,8 +206,8 @@ tc_read <- tc_load # @title Print a summary of a tree sequence and its contents # @param ts an external pointer (\code{externalptr}) to a \code{tsk_treeseq_t} # object. -# @details It uses \code{\link{ts_ptr_summary}} and -# \code{\link{ts_ptr_metadata_length}}. +# @details It uses \code{\link{ts_xptr_summary}} and +# \code{\link{ts_xptr_metadata_length}}. # Note that \code{nbytes} property is not available in \code{tskit} C API # compared to Python API, so also not available here. # @return A list with two data.frames; the first contains tree sequence @@ -217,14 +217,14 @@ tc_read <- tc_load # function is used and presented to users. # @examples # ts_file <- system.file("examples/test.trees", package = "RcppTskit") -# ts_ptr <- ts_ptr_load(ts_file) -# RcppTskit:::ts_ptr_print(ts_ptr) -ts_ptr_print <- function(ts) { +# ts_xptr <- ts_xptr_load(ts_file) +# RcppTskit:::ts_xptr_print(ts_xptr) +ts_xptr_print <- function(ts) { if (!is(ts, "externalptr")) { stop("ts must be an object of externalptr class!") } - tmp_summary <- ts_ptr_summary(ts) - tmp_metadata <- ts_ptr_metadata_length(ts) + tmp_summary <- ts_xptr_summary(ts) + tmp_metadata <- ts_xptr_metadata_length(ts) ret <- list( ts = data.frame( property = c( @@ -293,8 +293,8 @@ ts_ptr_print <- function(ts) { # @title Print a summary of a table collection and its contents # @param tc an external pointer (\code{externalptr}) to a # \code{tsk_table_collection_t} object. -# @details It uses \code{\link{tc_ptr_summary}} and -# \code{\link{tc_ptr_metadata_length}}. +# @details It uses \code{\link{tc_xptr_summary}} and +# \code{\link{tc_xptr_metadata_length}}. # @return A list with two data.frames; the first contains table collection # properties and their value; the second contains the numbers of rows in # tables and the length of their metadata. @@ -302,14 +302,14 @@ ts_ptr_print <- function(ts) { # function is used and presented to users. # @examples # ts_file <- system.file("examples/test.trees", package = "RcppTskit") -# tc_ptr <- tc_ptr_load(ts_file) -# RcppTskit:::tc_ptr_print(tc_ptr) -tc_ptr_print <- function(tc) { +# tc_xptr <- tc_xptr_load(ts_file) +# RcppTskit:::tc_xptr_print(tc_xptr) +tc_xptr_print <- function(tc) { if (!is(tc, "externalptr")) { stop("tc must be an object of externalptr class!") } - tmp_summary <- tc_ptr_summary(tc) - tmp_metadata <- tc_ptr_metadata_length(tc) + tmp_summary <- tc_xptr_summary(tc) + tmp_metadata <- tc_xptr_metadata_length(tc) ret <- list( tc = data.frame( property = c( @@ -379,17 +379,17 @@ tc_ptr_print <- function(tc) { # @seealso \code{\link{ts_py_to_r}}, \code{\link{ts_load}}, and # \code{\link[=TreeSequence]{TreeSequence$dump}} on how this function # is used and presented to users, -# and \code{\link{ts_ptr_py_to_r}}, \code{\link{ts_ptr_load}}, and -# \code{ts_ptr_dump} (Rcpp) for underlying pointer functions. +# and \code{\link{ts_xptr_py_to_r}}, \code{\link{ts_xptr_load}}, and +# \code{ts_xptr_dump} (Rcpp) for underlying pointer functions. # @examples # \dontrun{ # ts_file <- system.file("examples/test.trees", package = "RcppTskit") # ts_r <- ts_load(ts_file) -# ts_r_ptr <- ts_r$pointer -# is(ts_r_ptr) -# RcppTskit:::ts_ptr_num_samples(ts_r_ptr) # 16 +# ts_xptr_r <- ts_r$pointer +# is(ts_xptr_r) +# RcppTskit:::ts_xptr_num_samples(ts_xptr_r) # 16 # # Transfer the tree sequence to reticulate Python and use tskit Python API -# ts_py <- RcppTskit:::ts_ptr_r_to_py(ts_r_ptr) +# ts_py <- RcppTskit:::ts_xptr_r_to_py(ts_xptr_r) # is(ts_py) # ts_py$num_individuals # 8 # ts2_py <- ts_py$simplify(samples = c(0L, 1L, 2L, 3L)) @@ -398,7 +398,7 @@ tc_ptr_print <- function(tc) { # ts2_py$num_nodes # 8 # ts2_py$tables$nodes$time # 0.0 ... 5.0093910 # } -ts_ptr_r_to_py <- function(ts, tskit_module = get_tskit_py(), cleanup = TRUE) { +ts_xptr_r_to_py <- function(ts, tskit_module = get_tskit_py(), cleanup = TRUE) { if (!is(ts, "externalptr")) { stop("ts must be an object of externalptr class!") } @@ -407,7 +407,7 @@ ts_ptr_r_to_py <- function(ts, tskit_module = get_tskit_py(), cleanup = TRUE) { if (cleanup) { on.exit(file.remove(ts_file)) } - ts_ptr_dump(ts, file = ts_file) + ts_xptr_dump(ts, file = ts_file) ts_py <- tskit_module$load(ts_file) return(ts_py) } @@ -429,17 +429,17 @@ ts_ptr_r_to_py <- function(ts, tskit_module = get_tskit_py(), cleanup = TRUE) { # @seealso \code{\link{tc_py_to_r}}, \code{\link{tc_load}}, and # \code{\link[=TableCollection]{TableCollection$dump}} on how this function # is used and presented to users, -# and \code{\link{tc_ptr_py_to_r}}, \code{\link{tc_ptr_load}}, and -# \code{tc_ptr_dump} (Rcpp) for underlying pointer functions. +# and \code{\link{tc_xptr_py_to_r}}, \code{\link{tc_xptr_load}}, and +# \code{tc_xptr_dump} (Rcpp) for underlying pointer functions. # @examples # \dontrun{ # ts_file <- system.file("examples/test.trees", package = "RcppTskit") # tc_r <- tc_load(ts_file) -# tc_r_ptr <- tc_r$pointer -# is(tc_r_ptr) -# RcppTskit:::tc_ptr_summary(tc_r_ptr) +# tc_xptr_r <- tc_r$pointer +# is(tc_xptr_r) +# RcppTskit:::tc_xptr_summary(tc_xptr_r) # # Transfer the table collection to reticulate Python and use tskit Python API -# tc_py <- RcppTskit:::tc_ptr_r_to_py(tc_r_ptr) +# tc_py <- RcppTskit:::tc_xptr_r_to_py(tc_xptr_r) # is(tc_py) # tc_py$individuals$num_rows # 8 # tmp <- tc_py$simplify(samples = c(0L, 1L, 2L, 3L)) @@ -448,7 +448,7 @@ ts_ptr_r_to_py <- function(ts, tskit_module = get_tskit_py(), cleanup = TRUE) { # tc_py$nodes$num_rows # 8 # tc_py$nodes$time # 0.0 ... 5.0093910 # } -tc_ptr_r_to_py <- function(tc, tskit_module = get_tskit_py(), cleanup = TRUE) { +tc_xptr_r_to_py <- function(tc, tskit_module = get_tskit_py(), cleanup = TRUE) { if (!is(tc, "externalptr")) { stop("tc must be an object of externalptr class!") } @@ -457,7 +457,7 @@ tc_ptr_r_to_py <- function(tc, tskit_module = get_tskit_py(), cleanup = TRUE) { if (cleanup) { on.exit(file.remove(tc_file)) } - tc_ptr_dump(tc, file = tc_file) + tc_xptr_dump(tc, file = tc_file) tc_py <- tskit_module$TableCollection$load(tc_file) return(tc_py) } @@ -473,8 +473,8 @@ tc_ptr_r_to_py <- function(tc, tskit_module = get_tskit_py(), cleanup = TRUE) { # @seealso \code{\link[=TreeSequence]{TreeSequence$r_to_py}}, # \code{\link{ts_load}}, and \code{\link[=TreeSequence]{TreeSequence$dump}} # on how this function is used and presented to users, -# and \code{\link{ts_ptr_r_to_py}}, \code{\link{ts_ptr_load}}, and -# \code{ts_ptr_dump} (Rcpp) for underlying pointer functions. +# and \code{\link{ts_xptr_r_to_py}}, \code{\link{ts_xptr_load}}, and +# \code{ts_xptr_dump} (Rcpp) for underlying pointer functions. # @examples # \dontrun{ # ts_file <- system.file("examples/test.trees", package = "RcppTskit") @@ -492,12 +492,12 @@ tc_ptr_r_to_py <- function(tc, tskit_module = get_tskit_py(), cleanup = TRUE) { # ts2_py$tables$nodes$time # 0.0 ... 5.0093910 # # # Transfer the tree sequence to R and use RcppTskit -# ts2_ptr_r <- RcppTskit:::ts_ptr_py_to_r(ts2_py) -# is(ts2_ptr_r) -# RcppTskit:::ts_ptr_num_individuals(ts2_ptr_r) # 2 +# ts2_xptr_r <- RcppTskit:::ts_xptr_py_to_r(ts2_py) +# is(ts2_xptr_r) +# RcppTskit:::ts_xptr_num_individuals(ts2_xptr_r) # 2 # } # } -ts_ptr_py_to_r <- function(ts, cleanup = TRUE) { +ts_xptr_py_to_r <- function(ts, cleanup = TRUE) { if (!reticulate::is_py_object(ts)) { stop("ts must be a reticulate Python object!") } @@ -506,7 +506,7 @@ ts_ptr_py_to_r <- function(ts, cleanup = TRUE) { on.exit(file.remove(ts_file)) } ts$dump(ts_file) - ts_r <- ts_ptr_load(ts_file) + ts_r <- ts_xptr_load(ts_file) return(ts_r) } @@ -522,8 +522,8 @@ ts_ptr_py_to_r <- function(ts, cleanup = TRUE) { # @seealso \code{\link[=TableCollection]{TableCollection$r_to_py}}, # \code{\link{tc_load}}, and \code{\link[=TableCollection]{TableCollection$dump}} # on how this function is used and presented to users, -# and \code{\link{tc_ptr_r_to_py}}, \code{\link{tc_ptr_load}}, and -# \code{tc_ptr_dump} (Rcpp) for underlying pointer functions. +# and \code{\link{tc_xptr_r_to_py}}, \code{\link{tc_xptr_load}}, and +# \code{tc_xptr_dump} (Rcpp) for underlying pointer functions. # @examples # \dontrun{ # ts_file <- system.file("examples/test.trees", package = "RcppTskit") @@ -541,12 +541,12 @@ ts_ptr_py_to_r <- function(ts, cleanup = TRUE) { # tc_py$nodes$time # 0.0 ... 5.0093910 # # # Transfer the table collection to R and use RcppTskit -# tc2_ptr_r <- RcppTskit:::tc_ptr_py_to_r(tc_py) -# is(tc2_ptr_r) -# RcppTskit:::tc_ptr_summary(tc2_ptr_r) +# tc2_xptr_r <- RcppTskit:::tc_xptr_py_to_r(tc_py) +# is(tc2_xptr_r) +# RcppTskit:::tc_xptr_summary(tc2_xptr_r) # } # } -tc_ptr_py_to_r <- function(tc, cleanup = TRUE) { +tc_xptr_py_to_r <- function(tc, cleanup = TRUE) { if (!reticulate::is_py_object(tc)) { stop("tc must be a reticulate Python object!") } @@ -555,7 +555,7 @@ tc_ptr_py_to_r <- function(tc, cleanup = TRUE) { on.exit(file.remove(tc_file)) } tc$dump(tc_file) - tc_r <- tc_ptr_load(tc_file) + tc_r <- tc_xptr_load(tc_file) return(tc_r) } @@ -593,8 +593,8 @@ tc_ptr_py_to_r <- function(tc, cleanup = TRUE) { #' } #' @export ts_py_to_r <- function(ts, cleanup = TRUE) { - ptr <- ts_ptr_py_to_r(ts = ts, cleanup = cleanup) - ts_r <- TreeSequence$new(pointer = ptr) + xptr <- ts_xptr_py_to_r(ts = ts, cleanup = cleanup) + ts_r <- TreeSequence$new(pointer = xptr) return(ts_r) } @@ -632,7 +632,7 @@ ts_py_to_r <- function(ts, cleanup = TRUE) { #' } #' @export tc_py_to_r <- function(tc, cleanup = TRUE) { - ptr <- tc_ptr_py_to_r(tc = tc, cleanup = cleanup) - tc_r <- TableCollection$new(pointer = ptr) + xptr <- tc_xptr_py_to_r(tc = tc, cleanup = cleanup) + tc_r <- TableCollection$new(pointer = xptr) return(tc_r) } diff --git a/RcppTskit/inst/include/RcppTskit.hpp b/RcppTskit/inst/include/RcppTskit.hpp index 15051d5..8755c7a 100644 --- a/RcppTskit/inst/include/RcppTskit.hpp +++ b/RcppTskit/inst/include/RcppTskit.hpp @@ -36,4 +36,10 @@ using RcppTskit_table_collection_xptr = Rcpp::XPtr; +// Package implementation files define RCPPTSKIT_IMPL to avoid pulling +// PUBLIC declarations with default args into the same translation unit. +#ifndef RCPPTSKIT_IMPL +#include "RcppTskit_public.hpp" +#endif + #endif diff --git a/RcppTskit/inst/include/RcppTskit_public.hpp b/RcppTskit/inst/include/RcppTskit_public.hpp new file mode 100644 index 0000000..0fb8afc --- /dev/null +++ b/RcppTskit/inst/include/RcppTskit_public.hpp @@ -0,0 +1,50 @@ +#ifndef RCPPTSKIT_PUBLIC_H +#define RCPPTSKIT_PUBLIC_H + +#include + +// PUBLIC functions (in order as in the .cpp files) +// Sync the defaults between the .cpp files and declarations below! + +// RcppTskit.cpp +Rcpp::IntegerVector kastore_version(); +Rcpp::IntegerVector tskit_version(); + +// sync default options with .cpp! +SEXP ts_xptr_load(std::string file, int options = 0); +SEXP tc_xptr_load(std::string file, int options = 0); +void ts_xptr_dump(SEXP ts, std::string file, int options = 0); +void tc_xptr_dump(SEXP tc, std::string file, int options = 0); +SEXP ts_xptr_to_tc_xptr(SEXP ts, int options = 0); +SEXP tc_xptr_to_ts_xptr(SEXP tc, int options = 0); + +int ts_xptr_num_provenances(SEXP ts); +int ts_xptr_num_populations(SEXP ts); +int ts_xptr_num_migrations(SEXP ts); +int ts_xptr_num_individuals(SEXP ts); +int ts_xptr_num_samples(SEXP ts); +int ts_xptr_num_nodes(SEXP ts); +int ts_xptr_num_edges(SEXP ts); +int ts_xptr_num_trees(SEXP ts); +int ts_xptr_num_sites(SEXP ts); +int ts_xptr_num_mutations(SEXP ts); +double ts_xptr_sequence_length(SEXP ts); +bool ts_xptr_discrete_genome(SEXP ts); +bool ts_xptr_has_reference_sequence(SEXP ts); +Rcpp::String ts_xptr_time_units(SEXP ts); +bool ts_xptr_discrete_time(SEXP ts); +double ts_xptr_min_time(SEXP ts); +double ts_xptr_max_time(SEXP ts); +Rcpp::String ts_xptr_file_uuid(SEXP ts); +Rcpp::List ts_xptr_summary(SEXP ts); +Rcpp::List ts_xptr_metadata_length(SEXP ts); + +double tc_xptr_sequence_length(SEXP tc); +bool tc_xptr_has_reference_sequence(SEXP tc); +Rcpp::String tc_xptr_time_units(SEXP tc); +Rcpp::String tc_xptr_file_uuid(SEXP tc); +bool tc_xptr_has_index(SEXP tc); +Rcpp::List tc_xptr_summary(SEXP tc); +Rcpp::List tc_xptr_metadata_length(SEXP tc); + +#endif diff --git a/RcppTskit/notes_pkg_dev.Rmd b/RcppTskit/notes_pkg_dev.Rmd index 66dbb0e..9e2e414 100644 --- a/RcppTskit/notes_pkg_dev.Rmd +++ b/RcppTskit/notes_pkg_dev.Rmd @@ -37,19 +37,19 @@ Python also exposes these `TableCollection` methods: - `TSK_TS_INIT_COMPUTE_MUTATION_PARENTS` `TSK_TS_INIT_BUILD_INDEXES` is a C-level bitwise option and fits naturally in -the low-level `tc_ptr_to_ts_ptr(..., options)` wrapper. +the low-level `tc_xptr_to_ts_xptr(..., options)` wrapper. ### Current `RcppTskit` behavior (as of this note) - Public R method `TableCollection$tree_sequence()` currently sets `TSK_TS_INIT_BUILD_INDEXES` (via `bitwShiftL(1L, 0)`) and passes it to - `tc_ptr_to_ts_ptr(...)`. + `tc_xptr_to_ts_xptr(...)`. - This is functionally fine, but it exposes C-style flag handling in the R method implementation. Important nuance: -- `tc_ptr_to_ts_ptr()` calls `tsk_treeseq_init(...)` without `TSK_TAKE_OWNERSHIP`. +- `tc_xptr_to_ts_xptr()` calls `tsk_treeseq_init(...)` without `TSK_TAKE_OWNERSHIP`. - In tskit C, this means the tree sequence gets its own copied tables. - If `TSK_TS_INIT_BUILD_INDEXES` is used there, indexes are built on the copied tables (inside the tree sequence init path), not necessarily on the original @@ -79,8 +79,8 @@ tree_sequence = function() { if (!self$has_index()) { self$build_index() } - ts_ptr <- tc_ptr_to_ts_ptr(self$pointer, options = 0L) - TreeSequence$new(pointer = ts_ptr) + ts_xptr <- tc_xptr_to_ts_xptr(self$pointer, options = 0L) + TreeSequence$new(pointer = ts_xptr) } ``` @@ -110,8 +110,8 @@ So: Add explicit index mutators to R API (matching Python): -- `tc_ptr_build_index()` + `TableCollection$build_index()` -- `tc_ptr_drop_index()` + `TableCollection$drop_index()` +- `tc_xptr_build_index()` + `TableCollection$build_index()` +- `tc_xptr_drop_index()` + `TableCollection$drop_index()` Then tests become simple and deterministic: @@ -147,12 +147,12 @@ about for users switching between R and Python. ### Minimal next steps when time allows -1. Add `TableCollection$build_index()` / `$drop_index()` (+ `tc_ptr_*` wrappers). +1. Add `TableCollection$build_index()` / `$drop_index()` (+ `tc_xptr_*` wrappers). 2. Add focused tests for `has_index()` false/true transitions. 3. Refactor `TableCollection$tree_sequence()` to Python-style pre-check and `build_index()`. 4. Add a regression test for `tc$tree_sequence()` behavior after dropping index. -5. Keep `tc_ptr_to_ts_ptr(..., options)` as low-level C-like API (do not remove). +5. Keep `tc_xptr_to_ts_xptr(..., options)` as low-level C-like API (do not remove). ### Optional later (separate concern) @@ -205,8 +205,8 @@ SEXP tc_grow(SEXP tc) { // error using Rcpp::stop(), but should we also do something with the // ts pointer and object? If we delete, we discard/delete past work, // but if we do not, do we risk of returning a corrupted ts? - // tsk_table_collection_free(tc_ptr); - // delete tc_ptr; + // tsk_table_collection_free(tc_xptr); + // delete tc_xptr; Rcpp::stop(tsk_strerror(ret)); } return tc_xptr; diff --git a/RcppTskit/src/RcppExports.cpp b/RcppTskit/src/RcppExports.cpp index 08ed6bc..f779d57 100644 --- a/RcppTskit/src/RcppExports.cpp +++ b/RcppTskit/src/RcppExports.cpp @@ -30,372 +30,372 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// ts_ptr_load -SEXP ts_ptr_load(const std::string file, const int options); -RcppExport SEXP _RcppTskit_ts_ptr_load(SEXP fileSEXP, SEXP optionsSEXP) { +// ts_xptr_load +SEXP ts_xptr_load(const std::string file, const int options); +RcppExport SEXP _RcppTskit_ts_xptr_load(SEXP fileSEXP, SEXP optionsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const std::string >::type file(fileSEXP); Rcpp::traits::input_parameter< const int >::type options(optionsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_load(file, options)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_load(file, options)); return rcpp_result_gen; END_RCPP } -// tc_ptr_load -SEXP tc_ptr_load(const std::string file, const int options); -RcppExport SEXP _RcppTskit_tc_ptr_load(SEXP fileSEXP, SEXP optionsSEXP) { +// tc_xptr_load +SEXP tc_xptr_load(const std::string file, const int options); +RcppExport SEXP _RcppTskit_tc_xptr_load(SEXP fileSEXP, SEXP optionsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const std::string >::type file(fileSEXP); Rcpp::traits::input_parameter< const int >::type options(optionsSEXP); - rcpp_result_gen = Rcpp::wrap(tc_ptr_load(file, options)); + rcpp_result_gen = Rcpp::wrap(tc_xptr_load(file, options)); return rcpp_result_gen; END_RCPP } -// ts_ptr_dump -void ts_ptr_dump(const SEXP ts, const std::string file, const int options); -RcppExport SEXP _RcppTskit_ts_ptr_dump(SEXP tsSEXP, SEXP fileSEXP, SEXP optionsSEXP) { +// ts_xptr_dump +void ts_xptr_dump(const SEXP ts, const std::string file, const int options); +RcppExport SEXP _RcppTskit_ts_xptr_dump(SEXP tsSEXP, SEXP fileSEXP, SEXP optionsSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); Rcpp::traits::input_parameter< const std::string >::type file(fileSEXP); Rcpp::traits::input_parameter< const int >::type options(optionsSEXP); - ts_ptr_dump(ts, file, options); + ts_xptr_dump(ts, file, options); return R_NilValue; END_RCPP } -// tc_ptr_dump -void tc_ptr_dump(const SEXP tc, const std::string file, const int options); -RcppExport SEXP _RcppTskit_tc_ptr_dump(SEXP tcSEXP, SEXP fileSEXP, SEXP optionsSEXP) { +// tc_xptr_dump +void tc_xptr_dump(const SEXP tc, const std::string file, const int options); +RcppExport SEXP _RcppTskit_tc_xptr_dump(SEXP tcSEXP, SEXP fileSEXP, SEXP optionsSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type tc(tcSEXP); Rcpp::traits::input_parameter< const std::string >::type file(fileSEXP); Rcpp::traits::input_parameter< const int >::type options(optionsSEXP); - tc_ptr_dump(tc, file, options); + tc_xptr_dump(tc, file, options); return R_NilValue; END_RCPP } -// ts_ptr_to_tc_ptr -SEXP ts_ptr_to_tc_ptr(const SEXP ts, const int options); -RcppExport SEXP _RcppTskit_ts_ptr_to_tc_ptr(SEXP tsSEXP, SEXP optionsSEXP) { +// ts_xptr_to_tc_xptr +SEXP ts_xptr_to_tc_xptr(const SEXP ts, const int options); +RcppExport SEXP _RcppTskit_ts_xptr_to_tc_xptr(SEXP tsSEXP, SEXP optionsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); Rcpp::traits::input_parameter< const int >::type options(optionsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_to_tc_ptr(ts, options)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_to_tc_xptr(ts, options)); return rcpp_result_gen; END_RCPP } -// tc_ptr_to_ts_ptr -SEXP tc_ptr_to_ts_ptr(const SEXP tc, const int options); -RcppExport SEXP _RcppTskit_tc_ptr_to_ts_ptr(SEXP tcSEXP, SEXP optionsSEXP) { +// tc_xptr_to_ts_xptr +SEXP tc_xptr_to_ts_xptr(const SEXP tc, const int options); +RcppExport SEXP _RcppTskit_tc_xptr_to_ts_xptr(SEXP tcSEXP, SEXP optionsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type tc(tcSEXP); Rcpp::traits::input_parameter< const int >::type options(optionsSEXP); - rcpp_result_gen = Rcpp::wrap(tc_ptr_to_ts_ptr(tc, options)); + rcpp_result_gen = Rcpp::wrap(tc_xptr_to_ts_xptr(tc, options)); return rcpp_result_gen; END_RCPP } -// ts_ptr_num_provenances -int ts_ptr_num_provenances(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_num_provenances(SEXP tsSEXP) { +// ts_xptr_num_provenances +int ts_xptr_num_provenances(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_num_provenances(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_num_provenances(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_num_provenances(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_num_populations -int ts_ptr_num_populations(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_num_populations(SEXP tsSEXP) { +// ts_xptr_num_populations +int ts_xptr_num_populations(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_num_populations(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_num_populations(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_num_populations(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_num_migrations -int ts_ptr_num_migrations(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_num_migrations(SEXP tsSEXP) { +// ts_xptr_num_migrations +int ts_xptr_num_migrations(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_num_migrations(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_num_migrations(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_num_migrations(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_num_individuals -int ts_ptr_num_individuals(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_num_individuals(SEXP tsSEXP) { +// ts_xptr_num_individuals +int ts_xptr_num_individuals(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_num_individuals(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_num_individuals(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_num_individuals(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_num_samples -int ts_ptr_num_samples(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_num_samples(SEXP tsSEXP) { +// ts_xptr_num_samples +int ts_xptr_num_samples(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_num_samples(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_num_samples(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_num_samples(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_num_nodes -int ts_ptr_num_nodes(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_num_nodes(SEXP tsSEXP) { +// ts_xptr_num_nodes +int ts_xptr_num_nodes(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_num_nodes(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_num_nodes(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_num_nodes(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_num_edges -int ts_ptr_num_edges(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_num_edges(SEXP tsSEXP) { +// ts_xptr_num_edges +int ts_xptr_num_edges(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_num_edges(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_num_edges(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_num_edges(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_num_trees -int ts_ptr_num_trees(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_num_trees(SEXP tsSEXP) { +// ts_xptr_num_trees +int ts_xptr_num_trees(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_num_trees(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_num_trees(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_num_trees(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_num_sites -int ts_ptr_num_sites(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_num_sites(SEXP tsSEXP) { +// ts_xptr_num_sites +int ts_xptr_num_sites(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_num_sites(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_num_sites(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_num_sites(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_num_mutations -int ts_ptr_num_mutations(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_num_mutations(SEXP tsSEXP) { +// ts_xptr_num_mutations +int ts_xptr_num_mutations(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_num_mutations(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_num_mutations(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_num_mutations(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_sequence_length -double ts_ptr_sequence_length(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_sequence_length(SEXP tsSEXP) { +// ts_xptr_sequence_length +double ts_xptr_sequence_length(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_sequence_length(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_sequence_length(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_sequence_length(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_discrete_genome -bool ts_ptr_discrete_genome(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_discrete_genome(SEXP tsSEXP) { +// ts_xptr_discrete_genome +bool ts_xptr_discrete_genome(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_discrete_genome(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_discrete_genome(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_discrete_genome(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_has_reference_sequence -bool ts_ptr_has_reference_sequence(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_has_reference_sequence(SEXP tsSEXP) { +// ts_xptr_has_reference_sequence +bool ts_xptr_has_reference_sequence(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_has_reference_sequence(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_has_reference_sequence(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_has_reference_sequence(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_time_units -Rcpp::String ts_ptr_time_units(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_time_units(SEXP tsSEXP) { +// ts_xptr_time_units +Rcpp::String ts_xptr_time_units(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_time_units(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_time_units(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_time_units(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_discrete_time -bool ts_ptr_discrete_time(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_discrete_time(SEXP tsSEXP) { +// ts_xptr_discrete_time +bool ts_xptr_discrete_time(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_discrete_time(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_discrete_time(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_discrete_time(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_min_time -double ts_ptr_min_time(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_min_time(SEXP tsSEXP) { +// ts_xptr_min_time +double ts_xptr_min_time(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_min_time(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_min_time(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_min_time(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_max_time -double ts_ptr_max_time(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_max_time(SEXP tsSEXP) { +// ts_xptr_max_time +double ts_xptr_max_time(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_max_time(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_max_time(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_max_time(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_file_uuid -Rcpp::String ts_ptr_file_uuid(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_file_uuid(SEXP tsSEXP) { +// ts_xptr_file_uuid +Rcpp::String ts_xptr_file_uuid(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_file_uuid(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_file_uuid(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_file_uuid(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_summary -Rcpp::List ts_ptr_summary(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_summary(SEXP tsSEXP) { +// ts_xptr_summary +Rcpp::List ts_xptr_summary(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_summary(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_summary(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_summary(ts)); return rcpp_result_gen; END_RCPP } -// ts_ptr_metadata_length -Rcpp::List ts_ptr_metadata_length(const SEXP ts); -RcppExport SEXP _RcppTskit_ts_ptr_metadata_length(SEXP tsSEXP) { +// ts_xptr_metadata_length +Rcpp::List ts_xptr_metadata_length(const SEXP ts); +RcppExport SEXP _RcppTskit_ts_xptr_metadata_length(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(ts_ptr_metadata_length(ts)); + rcpp_result_gen = Rcpp::wrap(ts_xptr_metadata_length(ts)); return rcpp_result_gen; END_RCPP } -// tc_ptr_sequence_length -double tc_ptr_sequence_length(const SEXP tc); -RcppExport SEXP _RcppTskit_tc_ptr_sequence_length(SEXP tcSEXP) { +// tc_xptr_sequence_length +double tc_xptr_sequence_length(const SEXP tc); +RcppExport SEXP _RcppTskit_tc_xptr_sequence_length(SEXP tcSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type tc(tcSEXP); - rcpp_result_gen = Rcpp::wrap(tc_ptr_sequence_length(tc)); + rcpp_result_gen = Rcpp::wrap(tc_xptr_sequence_length(tc)); return rcpp_result_gen; END_RCPP } -// tc_ptr_has_reference_sequence -bool tc_ptr_has_reference_sequence(const SEXP tc); -RcppExport SEXP _RcppTskit_tc_ptr_has_reference_sequence(SEXP tcSEXP) { +// tc_xptr_has_reference_sequence +bool tc_xptr_has_reference_sequence(const SEXP tc); +RcppExport SEXP _RcppTskit_tc_xptr_has_reference_sequence(SEXP tcSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type tc(tcSEXP); - rcpp_result_gen = Rcpp::wrap(tc_ptr_has_reference_sequence(tc)); + rcpp_result_gen = Rcpp::wrap(tc_xptr_has_reference_sequence(tc)); return rcpp_result_gen; END_RCPP } -// tc_ptr_time_units -Rcpp::String tc_ptr_time_units(const SEXP tc); -RcppExport SEXP _RcppTskit_tc_ptr_time_units(SEXP tcSEXP) { +// tc_xptr_time_units +Rcpp::String tc_xptr_time_units(const SEXP tc); +RcppExport SEXP _RcppTskit_tc_xptr_time_units(SEXP tcSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type tc(tcSEXP); - rcpp_result_gen = Rcpp::wrap(tc_ptr_time_units(tc)); + rcpp_result_gen = Rcpp::wrap(tc_xptr_time_units(tc)); return rcpp_result_gen; END_RCPP } -// tc_ptr_file_uuid -Rcpp::String tc_ptr_file_uuid(const SEXP tc); -RcppExport SEXP _RcppTskit_tc_ptr_file_uuid(SEXP tcSEXP) { +// tc_xptr_file_uuid +Rcpp::String tc_xptr_file_uuid(const SEXP tc); +RcppExport SEXP _RcppTskit_tc_xptr_file_uuid(SEXP tcSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type tc(tcSEXP); - rcpp_result_gen = Rcpp::wrap(tc_ptr_file_uuid(tc)); + rcpp_result_gen = Rcpp::wrap(tc_xptr_file_uuid(tc)); return rcpp_result_gen; END_RCPP } -// tc_ptr_has_index -bool tc_ptr_has_index(const SEXP tc); -RcppExport SEXP _RcppTskit_tc_ptr_has_index(SEXP tcSEXP) { +// tc_xptr_has_index +bool tc_xptr_has_index(const SEXP tc); +RcppExport SEXP _RcppTskit_tc_xptr_has_index(SEXP tcSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type tc(tcSEXP); - rcpp_result_gen = Rcpp::wrap(tc_ptr_has_index(tc)); + rcpp_result_gen = Rcpp::wrap(tc_xptr_has_index(tc)); return rcpp_result_gen; END_RCPP } -// tc_ptr_summary -Rcpp::List tc_ptr_summary(const SEXP tc); -RcppExport SEXP _RcppTskit_tc_ptr_summary(SEXP tcSEXP) { +// tc_xptr_summary +Rcpp::List tc_xptr_summary(const SEXP tc); +RcppExport SEXP _RcppTskit_tc_xptr_summary(SEXP tcSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type tc(tcSEXP); - rcpp_result_gen = Rcpp::wrap(tc_ptr_summary(tc)); + rcpp_result_gen = Rcpp::wrap(tc_xptr_summary(tc)); return rcpp_result_gen; END_RCPP } -// tc_ptr_metadata_length -Rcpp::List tc_ptr_metadata_length(const SEXP tc); -RcppExport SEXP _RcppTskit_tc_ptr_metadata_length(SEXP tcSEXP) { +// tc_xptr_metadata_length +Rcpp::List tc_xptr_metadata_length(const SEXP tc); +RcppExport SEXP _RcppTskit_tc_xptr_metadata_length(SEXP tcSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type tc(tcSEXP); - rcpp_result_gen = Rcpp::wrap(tc_ptr_metadata_length(tc)); + rcpp_result_gen = Rcpp::wrap(tc_xptr_metadata_length(tc)); return rcpp_result_gen; END_RCPP } @@ -445,25 +445,25 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// test_ts_ptr_to_tc_ptr_forced_error -SEXP test_ts_ptr_to_tc_ptr_forced_error(const SEXP ts); -RcppExport SEXP _RcppTskit_test_ts_ptr_to_tc_ptr_forced_error(SEXP tsSEXP) { +// test_ts_xptr_to_tc_xptr_forced_error +SEXP test_ts_xptr_to_tc_xptr_forced_error(const SEXP ts); +RcppExport SEXP _RcppTskit_test_ts_xptr_to_tc_xptr_forced_error(SEXP tsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type ts(tsSEXP); - rcpp_result_gen = Rcpp::wrap(test_ts_ptr_to_tc_ptr_forced_error(ts)); + rcpp_result_gen = Rcpp::wrap(test_ts_xptr_to_tc_xptr_forced_error(ts)); return rcpp_result_gen; END_RCPP } -// test_tc_ptr_to_ts_ptr_forced_error -SEXP test_tc_ptr_to_ts_ptr_forced_error(const SEXP tc); -RcppExport SEXP _RcppTskit_test_tc_ptr_to_ts_ptr_forced_error(SEXP tcSEXP) { +// test_tc_xptr_to_ts_xptr_forced_error +SEXP test_tc_xptr_to_ts_xptr_forced_error(const SEXP tc); +RcppExport SEXP _RcppTskit_test_tc_xptr_to_ts_xptr_forced_error(SEXP tcSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const SEXP >::type tc(tcSEXP); - rcpp_result_gen = Rcpp::wrap(test_tc_ptr_to_ts_ptr_forced_error(tc)); + rcpp_result_gen = Rcpp::wrap(test_tc_xptr_to_ts_xptr_forced_error(tc)); return rcpp_result_gen; END_RCPP } @@ -471,46 +471,46 @@ END_RCPP static const R_CallMethodDef CallEntries[] = { {"_RcppTskit_kastore_version", (DL_FUNC) &_RcppTskit_kastore_version, 0}, {"_RcppTskit_tskit_version", (DL_FUNC) &_RcppTskit_tskit_version, 0}, - {"_RcppTskit_ts_ptr_load", (DL_FUNC) &_RcppTskit_ts_ptr_load, 2}, - {"_RcppTskit_tc_ptr_load", (DL_FUNC) &_RcppTskit_tc_ptr_load, 2}, - {"_RcppTskit_ts_ptr_dump", (DL_FUNC) &_RcppTskit_ts_ptr_dump, 3}, - {"_RcppTskit_tc_ptr_dump", (DL_FUNC) &_RcppTskit_tc_ptr_dump, 3}, - {"_RcppTskit_ts_ptr_to_tc_ptr", (DL_FUNC) &_RcppTskit_ts_ptr_to_tc_ptr, 2}, - {"_RcppTskit_tc_ptr_to_ts_ptr", (DL_FUNC) &_RcppTskit_tc_ptr_to_ts_ptr, 2}, - {"_RcppTskit_ts_ptr_num_provenances", (DL_FUNC) &_RcppTskit_ts_ptr_num_provenances, 1}, - {"_RcppTskit_ts_ptr_num_populations", (DL_FUNC) &_RcppTskit_ts_ptr_num_populations, 1}, - {"_RcppTskit_ts_ptr_num_migrations", (DL_FUNC) &_RcppTskit_ts_ptr_num_migrations, 1}, - {"_RcppTskit_ts_ptr_num_individuals", (DL_FUNC) &_RcppTskit_ts_ptr_num_individuals, 1}, - {"_RcppTskit_ts_ptr_num_samples", (DL_FUNC) &_RcppTskit_ts_ptr_num_samples, 1}, - {"_RcppTskit_ts_ptr_num_nodes", (DL_FUNC) &_RcppTskit_ts_ptr_num_nodes, 1}, - {"_RcppTskit_ts_ptr_num_edges", (DL_FUNC) &_RcppTskit_ts_ptr_num_edges, 1}, - {"_RcppTskit_ts_ptr_num_trees", (DL_FUNC) &_RcppTskit_ts_ptr_num_trees, 1}, - {"_RcppTskit_ts_ptr_num_sites", (DL_FUNC) &_RcppTskit_ts_ptr_num_sites, 1}, - {"_RcppTskit_ts_ptr_num_mutations", (DL_FUNC) &_RcppTskit_ts_ptr_num_mutations, 1}, - {"_RcppTskit_ts_ptr_sequence_length", (DL_FUNC) &_RcppTskit_ts_ptr_sequence_length, 1}, - {"_RcppTskit_ts_ptr_discrete_genome", (DL_FUNC) &_RcppTskit_ts_ptr_discrete_genome, 1}, - {"_RcppTskit_ts_ptr_has_reference_sequence", (DL_FUNC) &_RcppTskit_ts_ptr_has_reference_sequence, 1}, - {"_RcppTskit_ts_ptr_time_units", (DL_FUNC) &_RcppTskit_ts_ptr_time_units, 1}, - {"_RcppTskit_ts_ptr_discrete_time", (DL_FUNC) &_RcppTskit_ts_ptr_discrete_time, 1}, - {"_RcppTskit_ts_ptr_min_time", (DL_FUNC) &_RcppTskit_ts_ptr_min_time, 1}, - {"_RcppTskit_ts_ptr_max_time", (DL_FUNC) &_RcppTskit_ts_ptr_max_time, 1}, - {"_RcppTskit_ts_ptr_file_uuid", (DL_FUNC) &_RcppTskit_ts_ptr_file_uuid, 1}, - {"_RcppTskit_ts_ptr_summary", (DL_FUNC) &_RcppTskit_ts_ptr_summary, 1}, - {"_RcppTskit_ts_ptr_metadata_length", (DL_FUNC) &_RcppTskit_ts_ptr_metadata_length, 1}, - {"_RcppTskit_tc_ptr_sequence_length", (DL_FUNC) &_RcppTskit_tc_ptr_sequence_length, 1}, - {"_RcppTskit_tc_ptr_has_reference_sequence", (DL_FUNC) &_RcppTskit_tc_ptr_has_reference_sequence, 1}, - {"_RcppTskit_tc_ptr_time_units", (DL_FUNC) &_RcppTskit_tc_ptr_time_units, 1}, - {"_RcppTskit_tc_ptr_file_uuid", (DL_FUNC) &_RcppTskit_tc_ptr_file_uuid, 1}, - {"_RcppTskit_tc_ptr_has_index", (DL_FUNC) &_RcppTskit_tc_ptr_has_index, 1}, - {"_RcppTskit_tc_ptr_summary", (DL_FUNC) &_RcppTskit_tc_ptr_summary, 1}, - {"_RcppTskit_tc_ptr_metadata_length", (DL_FUNC) &_RcppTskit_tc_ptr_metadata_length, 1}, + {"_RcppTskit_ts_xptr_load", (DL_FUNC) &_RcppTskit_ts_xptr_load, 2}, + {"_RcppTskit_tc_xptr_load", (DL_FUNC) &_RcppTskit_tc_xptr_load, 2}, + {"_RcppTskit_ts_xptr_dump", (DL_FUNC) &_RcppTskit_ts_xptr_dump, 3}, + {"_RcppTskit_tc_xptr_dump", (DL_FUNC) &_RcppTskit_tc_xptr_dump, 3}, + {"_RcppTskit_ts_xptr_to_tc_xptr", (DL_FUNC) &_RcppTskit_ts_xptr_to_tc_xptr, 2}, + {"_RcppTskit_tc_xptr_to_ts_xptr", (DL_FUNC) &_RcppTskit_tc_xptr_to_ts_xptr, 2}, + {"_RcppTskit_ts_xptr_num_provenances", (DL_FUNC) &_RcppTskit_ts_xptr_num_provenances, 1}, + {"_RcppTskit_ts_xptr_num_populations", (DL_FUNC) &_RcppTskit_ts_xptr_num_populations, 1}, + {"_RcppTskit_ts_xptr_num_migrations", (DL_FUNC) &_RcppTskit_ts_xptr_num_migrations, 1}, + {"_RcppTskit_ts_xptr_num_individuals", (DL_FUNC) &_RcppTskit_ts_xptr_num_individuals, 1}, + {"_RcppTskit_ts_xptr_num_samples", (DL_FUNC) &_RcppTskit_ts_xptr_num_samples, 1}, + {"_RcppTskit_ts_xptr_num_nodes", (DL_FUNC) &_RcppTskit_ts_xptr_num_nodes, 1}, + {"_RcppTskit_ts_xptr_num_edges", (DL_FUNC) &_RcppTskit_ts_xptr_num_edges, 1}, + {"_RcppTskit_ts_xptr_num_trees", (DL_FUNC) &_RcppTskit_ts_xptr_num_trees, 1}, + {"_RcppTskit_ts_xptr_num_sites", (DL_FUNC) &_RcppTskit_ts_xptr_num_sites, 1}, + {"_RcppTskit_ts_xptr_num_mutations", (DL_FUNC) &_RcppTskit_ts_xptr_num_mutations, 1}, + {"_RcppTskit_ts_xptr_sequence_length", (DL_FUNC) &_RcppTskit_ts_xptr_sequence_length, 1}, + {"_RcppTskit_ts_xptr_discrete_genome", (DL_FUNC) &_RcppTskit_ts_xptr_discrete_genome, 1}, + {"_RcppTskit_ts_xptr_has_reference_sequence", (DL_FUNC) &_RcppTskit_ts_xptr_has_reference_sequence, 1}, + {"_RcppTskit_ts_xptr_time_units", (DL_FUNC) &_RcppTskit_ts_xptr_time_units, 1}, + {"_RcppTskit_ts_xptr_discrete_time", (DL_FUNC) &_RcppTskit_ts_xptr_discrete_time, 1}, + {"_RcppTskit_ts_xptr_min_time", (DL_FUNC) &_RcppTskit_ts_xptr_min_time, 1}, + {"_RcppTskit_ts_xptr_max_time", (DL_FUNC) &_RcppTskit_ts_xptr_max_time, 1}, + {"_RcppTskit_ts_xptr_file_uuid", (DL_FUNC) &_RcppTskit_ts_xptr_file_uuid, 1}, + {"_RcppTskit_ts_xptr_summary", (DL_FUNC) &_RcppTskit_ts_xptr_summary, 1}, + {"_RcppTskit_ts_xptr_metadata_length", (DL_FUNC) &_RcppTskit_ts_xptr_metadata_length, 1}, + {"_RcppTskit_tc_xptr_sequence_length", (DL_FUNC) &_RcppTskit_tc_xptr_sequence_length, 1}, + {"_RcppTskit_tc_xptr_has_reference_sequence", (DL_FUNC) &_RcppTskit_tc_xptr_has_reference_sequence, 1}, + {"_RcppTskit_tc_xptr_time_units", (DL_FUNC) &_RcppTskit_tc_xptr_time_units, 1}, + {"_RcppTskit_tc_xptr_file_uuid", (DL_FUNC) &_RcppTskit_tc_xptr_file_uuid, 1}, + {"_RcppTskit_tc_xptr_has_index", (DL_FUNC) &_RcppTskit_tc_xptr_has_index, 1}, + {"_RcppTskit_tc_xptr_summary", (DL_FUNC) &_RcppTskit_tc_xptr_summary, 1}, + {"_RcppTskit_tc_xptr_metadata_length", (DL_FUNC) &_RcppTskit_tc_xptr_metadata_length, 1}, {"_RcppTskit_test_tsk_bug_assert_c", (DL_FUNC) &_RcppTskit_test_tsk_bug_assert_c, 0}, {"_RcppTskit_test_tsk_bug_assert_cpp", (DL_FUNC) &_RcppTskit_test_tsk_bug_assert_cpp, 0}, {"_RcppTskit_test_tsk_trace_error_c", (DL_FUNC) &_RcppTskit_test_tsk_trace_error_c, 0}, {"_RcppTskit_test_tsk_trace_error_cpp", (DL_FUNC) &_RcppTskit_test_tsk_trace_error_cpp, 0}, {"_RcppTskit_tsk_trace_errors_defined", (DL_FUNC) &_RcppTskit_tsk_trace_errors_defined, 0}, - {"_RcppTskit_test_ts_ptr_to_tc_ptr_forced_error", (DL_FUNC) &_RcppTskit_test_ts_ptr_to_tc_ptr_forced_error, 1}, - {"_RcppTskit_test_tc_ptr_to_ts_ptr_forced_error", (DL_FUNC) &_RcppTskit_test_tc_ptr_to_ts_ptr_forced_error, 1}, + {"_RcppTskit_test_ts_xptr_to_tc_xptr_forced_error", (DL_FUNC) &_RcppTskit_test_ts_xptr_to_tc_xptr_forced_error, 1}, + {"_RcppTskit_test_tc_xptr_to_ts_xptr_forced_error", (DL_FUNC) &_RcppTskit_test_tc_xptr_to_ts_xptr_forced_error, 1}, {NULL, NULL, 0} }; diff --git a/RcppTskit/src/RcppTskit.cpp b/RcppTskit/src/RcppTskit.cpp index d91ee7e..415480e 100644 --- a/RcppTskit/src/RcppTskit.cpp +++ b/RcppTskit/src/RcppTskit.cpp @@ -1,3 +1,8 @@ +// Avoid pulling PUBLIC declarations with defaults into this translation unit, +// because Rcpp-exported definitions below carry defaults for autogenerated +// R wrappers. Yes, defaults are here in .cpp and in _public.hpp, so ensure +// they are synced! +#define RCPPTSKIT_IMPL #include namespace { @@ -11,12 +16,13 @@ constexpr tsk_flags_t kCopyTablesSupportedOptions = TSK_COPY_FILE_UUID; constexpr tsk_flags_t kTreeseqInitSupportedOptions = TSK_TS_INIT_BUILD_INDEXES | TSK_TS_INIT_COMPUTE_MUTATION_PARENTS; +// INTERNAL // @title Validate load options // @param options passed to load functions // @param caller function name // @details See // \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.tsk_table_collection_load}. -// The \code{ts_ptr_load} and \code{tc_ptr_load} allocate objects, so +// The \code{ts_xptr_load} and \code{tc_xptr_load} allocate objects, so // we can't work with \code{TSK_NO_INIT} // \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.TSK_NO_INIT}. tsk_flags_t validate_load_options(const int options, const char *caller) { @@ -32,6 +38,7 @@ tsk_flags_t validate_load_options(const int options, const char *caller) { return load_options; } +// INTERNAL // @title Validate copy tables options // @param options passed to load functions // @param caller function name @@ -39,7 +46,7 @@ tsk_flags_t validate_load_options(const int options, const char *caller) { // \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.tsk_treeseq_copy_tables} // and // \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.tsk_table_collection_copy}. -// The \code{ts_ptr_to_tc_ptr} allocates table collection, so +// The \code{ts_xptr_to_tc_xptr} allocates table collection, so // we can't work with \code{TSK_NO_INIT} // \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.TSK_NO_INIT}. tsk_flags_t validate_copy_tables_options(const int options, @@ -59,14 +66,15 @@ tsk_flags_t validate_copy_tables_options(const int options, return copy_options; } +// INTERNAL // @title Validate tree sequence initialisation options // @param options passed to load functions // @param caller function name // @details See // \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.tsk_treeseq_init}. -// The \code{tc_ptr_to_ts_ptr} allocates tree sequence from table collection, -// so we can't use \code{TSK_TAKE_OWNERSHIP} as the table collection object -// still exists on R side +// The \code{tc_xptr_to_ts_xptr} allocates tree sequence from table +// collection, so we can't use \code{TSK_TAKE_OWNERSHIP} as the table +// collection object still exists on R side // \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.TSK_TAKE_OWNERSHIP}. tsk_flags_t validate_treeseq_init_options(const int options, const char *caller) { @@ -88,6 +96,7 @@ tsk_flags_t validate_treeseq_init_options(const int options, return init_options; } +// INTERNAL // @title Validate tree sequence/table collection dump options // @param options passed to dump functions // @param caller function name @@ -108,6 +117,7 @@ tsk_flags_t validate_dump_options(const int options, const char *caller) { } // namespace +// PUBLIC //' @title Report the version of installed kastore C API //' @details The version is stored in the installed header \code{kastore.h}. //' @return A named vector with three elements \code{major}, \code{minor}, and @@ -123,6 +133,7 @@ Rcpp::IntegerVector kastore_version() { Rcpp::_["patch"] = KAS_VERSION_PATCH); } +// PUBLIC //' @title Report the version of installed \code{tskit} C API //' @details The version is defined in the installed header \code{tskit/core.h}. //' @return A named vector with three elements \code{major}, \code{minor}, and @@ -137,6 +148,7 @@ Rcpp::IntegerVector tskit_version() { Rcpp::_["patch"] = TSK_VERSION_PATCH); } +// PUBLIC // @title Load a tree sequence from a file // @param file a string specifying the full path of the tree sequence file. // @param options \code{tskit} bitwise flags (see details and note that only @@ -151,16 +163,16 @@ Rcpp::IntegerVector tskit_version() { // and presented to users. // @examples // ts_file <- system.file("examples/test.trees", package = "RcppTskit") -// ts_ptr <- RcppTskit:::ts_ptr_load(ts_file) -// is(ts_ptr) -// ts_ptr -// RcppTskit:::ts_ptr_num_nodes(ts_ptr) -// ts <- TreeSequence$new(pointer = ts_ptr) +// ts_xptr <- RcppTskit:::ts_xptr_load(ts_file) +// is(ts_xptr) +// ts_xptr +// RcppTskit:::ts_xptr_num_nodes(ts_xptr) +// ts <- TreeSequence$new(pointer = ts_xptr) // is(ts) // [[Rcpp::export]] -SEXP ts_ptr_load(const std::string file, const int options = 0) { +SEXP ts_xptr_load(const std::string file, const int options = 0) { const tsk_flags_t load_options = - validate_load_options(options, "ts_ptr_load"); + validate_load_options(options, "ts_xptr_load"); // tsk_treeseq_t ts; // on stack, destroyed end of func, must free resources tsk_treeseq_t *ts_ptr = new tsk_treeseq_t(); // on heap, persists function // See also https://tskit.dev/tskit/docs/stable/c-api.html#api-structure @@ -170,12 +182,13 @@ SEXP ts_ptr_load(const std::string file, const int options = 0) { delete ts_ptr; Rcpp::stop(tsk_strerror(ret)); } - // Wrap ts_ptr for R as an external pointer + // Wrap standard/raw ts_ptr for R as an external pointer handle (xptr) // "true" below means that R will call finaliser on garbage collection RcppTskit_treeseq_xptr ts_xptr(ts_ptr, true); return ts_xptr; } +// PUBLIC // @title Load a table collection from a file // @param file a string specifying the full path of the tree sequence file. // @param options \code{tskit} bitwise flags (see details and note that only @@ -190,16 +203,16 @@ SEXP ts_ptr_load(const std::string file, const int options = 0) { // used and presented to users. // @examples // ts_file <- system.file("examples/test.trees", package = "RcppTskit") -// tc_ptr <- RcppTskit:::tc_ptr_load(ts_file) -// is(tc_ptr) -// tc_ptr -// RcppTskit:::tc_ptr_print(tc_ptr) -// tc <- TableCollection$new(pointer = tc_ptr) +// tc_xptr <- RcppTskit:::tc_xptr_load(ts_file) +// is(tc_xptr) +// tc_xptr +// RcppTskit:::tc_xptr_print(tc_xptr) +// tc <- TableCollection$new(pointer = tc_xptr) // is(tc) // [[Rcpp::export]] -SEXP tc_ptr_load(const std::string file, const int options = 0) { +SEXP tc_xptr_load(const std::string file, const int options = 0) { const tsk_flags_t load_options = - validate_load_options(options, "tc_ptr_load"); + validate_load_options(options, "tc_xptr_load"); tsk_table_collection_t *tc_ptr = new tsk_table_collection_t(); int ret = tsk_table_collection_load(tc_ptr, file.c_str(), load_options); if (ret != 0) { @@ -207,10 +220,13 @@ SEXP tc_ptr_load(const std::string file, const int options = 0) { delete tc_ptr; Rcpp::stop(tsk_strerror(ret)); } + // Wrap standard/raw tc_ptr for R as an external pointer handle (xptr) + // "true" below means that R will call finaliser on garbage collection RcppTskit_table_collection_xptr tc_xptr(tc_ptr, true); return tc_xptr; } +// PUBLIC // @title Write a tree sequence to a file // @param ts an external pointer to tree sequence as a \code{tsk_treeseq_t} // object. @@ -222,14 +238,15 @@ SEXP tc_ptr_load(const std::string file, const int options = 0) { // @return No return value; called for side effects. // @examples // ts_file <- system.file("examples/test.trees", package = "RcppTskit") -// ts_ptr <- RcppTskit:::ts_ptr_load(ts_file) +// ts_xptr <- RcppTskit:::ts_xptr_load(ts_file) // dump_file <- tempfile() -// RcppTskit:::ts_ptr_dump(ts_ptr, dump_file) +// RcppTskit:::ts_xptr_dump(ts_xptr, dump_file) // file.remove(dump_file) // [[Rcpp::export]] -void ts_ptr_dump(const SEXP ts, const std::string file, const int options = 0) { +void ts_xptr_dump(const SEXP ts, const std::string file, + const int options = 0) { const tsk_flags_t dump_options = - validate_dump_options(options, "ts_ptr_dump"); + validate_dump_options(options, "ts_xptr_dump"); RcppTskit_treeseq_xptr ts_xptr(ts); int ret = tsk_treeseq_dump(ts_xptr, file.c_str(), dump_options); if (ret != 0) { @@ -237,6 +254,7 @@ void ts_ptr_dump(const SEXP ts, const std::string file, const int options = 0) { } } +// PUBLIC // @title Write a table collection to a file // @param tc an external pointer to table collection as a // \code{tsk_table_collection_t} object. @@ -248,14 +266,15 @@ void ts_ptr_dump(const SEXP ts, const std::string file, const int options = 0) { // @return No return value; called for side effects. // @examples // ts_file <- system.file("examples/test.trees", package = "RcppTskit") -// tc_ptr <- RcppTskit:::tc_ptr_load(ts_file) +// tc_xptr <- RcppTskit:::tc_xptr_load(ts_file) // dump_file <- tempfile() -// RcppTskit:::tc_ptr_dump(tc_ptr, dump_file) +// RcppTskit:::tc_xptr_dump(tc_xptr, dump_file) // file.remove(dump_file) // [[Rcpp::export]] -void tc_ptr_dump(const SEXP tc, const std::string file, const int options = 0) { +void tc_xptr_dump(const SEXP tc, const std::string file, + const int options = 0) { const tsk_flags_t dump_options = - validate_dump_options(options, "tc_ptr_dump"); + validate_dump_options(options, "tc_xptr_dump"); RcppTskit_table_collection_xptr tc_xptr(tc); int ret = tsk_table_collection_dump(tc_xptr, file.c_str(), dump_options); if (ret != 0) { @@ -263,6 +282,7 @@ void tc_ptr_dump(const SEXP tc, const std::string file, const int options = 0) { } } +// PUBLIC // @title Copy a tree sequence's tables into a table collection // @param ts an external pointer to tree sequence as a \code{tsk_treeseq_t} // object. @@ -280,15 +300,15 @@ void tc_ptr_dump(const SEXP tc, const std::string file, const int options = 0) { // is used and presented to users. // @examples // ts_file <- system.file("examples/test.trees", package = "RcppTskit") -// ts_ptr <- RcppTskit:::ts_ptr_load(ts_file) -// tc_ptr <- RcppTskit:::ts_ptr_to_tc_ptr(ts_ptr) -// is(tc_ptr) -// tc_ptr -// RcppTskit:::tc_ptr_print(tc_ptr) +// ts_xptr <- RcppTskit:::ts_xptr_load(ts_file) +// tc_xptr <- RcppTskit:::ts_xptr_to_tc_xptr(ts_xptr) +// is(tc_xptr) +// tc_xptr +// RcppTskit:::tc_xptr_print(tc_xptr) // [[Rcpp::export]] -SEXP ts_ptr_to_tc_ptr(const SEXP ts, const int options = 0) { +SEXP ts_xptr_to_tc_xptr(const SEXP ts, const int options = 0) { const tsk_flags_t copy_options = - validate_copy_tables_options(options, "ts_ptr_to_tc_ptr"); + validate_copy_tables_options(options, "ts_xptr_to_tc_xptr"); RcppTskit_treeseq_xptr ts_xptr(ts); tsk_table_collection_t *tc_ptr = new tsk_table_collection_t(); int ret = tsk_treeseq_copy_tables(ts_xptr, tc_ptr, copy_options); @@ -297,10 +317,13 @@ SEXP ts_ptr_to_tc_ptr(const SEXP ts, const int options = 0) { delete tc_ptr; Rcpp::stop(tsk_strerror(ret)); } + // Wrap standard/raw tc_ptr for R as an external pointer handle (xptr) + // "true" below means that R will call finaliser on garbage collection RcppTskit_table_collection_xptr tc_xptr(tc_ptr, true); return tc_xptr; } +// PUBLIC // @title Initialise a tree sequence from a table collection // @param tc an external pointer to table collection as a // \code{tsk_table_collection_t} object. @@ -320,14 +343,14 @@ SEXP ts_ptr_to_tc_ptr(const SEXP ts, const int options = 0) { // function is used and presented to users. // @examples // ts_file <- system.file("examples/test.trees", package = "RcppTskit") -// tc_ptr <- RcppTskit:::tc_ptr_load(ts_file) -// RcppTskit:::tc_ptr_print(tc_ptr) -// ts_ptr <- RcppTskit:::tc_ptr_to_ts_ptr(tc_ptr) -// RcppTskit:::ts_ptr_print(ts_ptr) +// tc_xptr <- RcppTskit:::tc_xptr_load(ts_file) +// RcppTskit:::tc_xptr_print(tc_xptr) +// ts_xptr <- RcppTskit:::tc_xptr_to_ts_xptr(tc_xptr) +// RcppTskit:::ts_xptr_print(ts_xptr) // [[Rcpp::export]] -SEXP tc_ptr_to_ts_ptr(const SEXP tc, const int options = 0) { +SEXP tc_xptr_to_ts_xptr(const SEXP tc, const int options = 0) { const tsk_flags_t init_options = - validate_treeseq_init_options(options, "tc_ptr_to_ts_ptr"); + validate_treeseq_init_options(options, "tc_xptr_to_ts_xptr"); RcppTskit_table_collection_xptr tc_xptr(tc); tsk_treeseq_t *ts_ptr = new tsk_treeseq_t(); int ret = tsk_treeseq_init(ts_ptr, tc_xptr, init_options); @@ -336,6 +359,8 @@ SEXP tc_ptr_to_ts_ptr(const SEXP tc, const int options = 0) { delete ts_ptr; Rcpp::stop(tsk_strerror(ret)); } + // Wrap standard/raw ts_ptr for R as an external pointer handle (xptr) + // "true" below means that R will call finaliser on garbage collection RcppTskit_treeseq_xptr ts_xptr(ts_ptr, true); return ts_xptr; } @@ -372,105 +397,119 @@ SEXP tc_ptr_to_ts_ptr(const SEXP tc, const int options = 0) { // is a scalar property (which we have strived to implement / mirror here), // but this one requires table-column arrays, which we will look into in #49 -// @describeIn ts_ptr_summary Get the number of provenances in a tree sequence +// PUBLIC +// @describeIn ts_xptr_summary Get the number of provenances in a tree sequence // [[Rcpp::export]] -int ts_ptr_num_provenances(const SEXP ts) { +int ts_xptr_num_provenances(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return static_cast(tsk_treeseq_get_num_provenances(ts_xptr)); } -// @describeIn ts_ptr_summary Get the number of populations in a tree sequence +// PUBLIC +// @describeIn ts_xptr_summary Get the number of populations in a tree sequence // [[Rcpp::export]] -int ts_ptr_num_populations(const SEXP ts) { +int ts_xptr_num_populations(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return static_cast(tsk_treeseq_get_num_populations(ts_xptr)); } -// @describeIn ts_ptr_summary Get the number of migrations in a tree sequence +// PUBLIC +// @describeIn ts_xptr_summary Get the number of migrations in a tree sequence // [[Rcpp::export]] -int ts_ptr_num_migrations(const SEXP ts) { +int ts_xptr_num_migrations(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return static_cast(tsk_treeseq_get_num_migrations(ts_xptr)); } -// @describeIn ts_ptr_summary Get the number of individuals in a tree sequence +// PUBLIC +// @describeIn ts_xptr_summary Get the number of individuals in a tree sequence // [[Rcpp::export]] -int ts_ptr_num_individuals(const SEXP ts) { +int ts_xptr_num_individuals(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return static_cast(tsk_treeseq_get_num_individuals(ts_xptr)); } -// @describeIn ts_ptr_summary Get the number of samples (of nodes) in a tree +// PUBLIC +// @describeIn ts_xptr_summary Get the number of samples (of nodes) in a tree // sequence // [[Rcpp::export]] -int ts_ptr_num_samples(const SEXP ts) { +int ts_xptr_num_samples(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return static_cast(tsk_treeseq_get_num_samples(ts_xptr)); } -// @describeIn ts_ptr_summary Get the number of nodes in a tree sequence +// PUBLIC +// @describeIn ts_xptr_summary Get the number of nodes in a tree sequence // [[Rcpp::export]] -int ts_ptr_num_nodes(const SEXP ts) { +int ts_xptr_num_nodes(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return static_cast(tsk_treeseq_get_num_nodes(ts_xptr)); } -// @describeIn ts_ptr_summary Get the number of edges in a tree sequence +// PUBLIC +// @describeIn ts_xptr_summary Get the number of edges in a tree sequence // [[Rcpp::export]] -int ts_ptr_num_edges(const SEXP ts) { +int ts_xptr_num_edges(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return static_cast(tsk_treeseq_get_num_edges(ts_xptr)); } -// @describeIn ts_ptr_summary Get the number of trees in a tree sequence +// PUBLIC +// @describeIn ts_xptr_summary Get the number of trees in a tree sequence // [[Rcpp::export]] -int ts_ptr_num_trees(const SEXP ts) { +int ts_xptr_num_trees(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return static_cast(tsk_treeseq_get_num_trees(ts_xptr)); } -// @describeIn ts_ptr_summary Get the number of sites in a tree sequence +// PUBLIC +// @describeIn ts_xptr_summary Get the number of sites in a tree sequence // [[Rcpp::export]] -int ts_ptr_num_sites(const SEXP ts) { +int ts_xptr_num_sites(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return static_cast(tsk_treeseq_get_num_sites(ts_xptr)); } -// @describeIn ts_ptr_summary Get the number of mutations in a tree sequence +// PUBLIC +// @describeIn ts_xptr_summary Get the number of mutations in a tree sequence // [[Rcpp::export]] -int ts_ptr_num_mutations(const SEXP ts) { +int ts_xptr_num_mutations(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return static_cast(tsk_treeseq_get_num_mutations(ts_xptr)); } -// @describeIn ts_ptr_summary Get the sequence length +// PUBLIC +// @describeIn ts_xptr_summary Get the sequence length // [[Rcpp::export]] -double ts_ptr_sequence_length(const SEXP ts) { +double ts_xptr_sequence_length(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return tsk_treeseq_get_sequence_length(ts_xptr); } -// @describeIn ts_ptr_summary Get the discrete genome status +// PUBLIC +// @describeIn ts_xptr_summary Get the discrete genome status // [[Rcpp::export]] -bool ts_ptr_discrete_genome(const SEXP ts) { +bool ts_xptr_discrete_genome(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return tsk_treeseq_get_discrete_genome(ts_xptr); } -// @describeIn ts_ptr_summary Does the tree sequence hold a reference genome +// PUBLIC +// @describeIn ts_xptr_summary Does the tree sequence hold a reference genome // sequence // @details Note that tsk_treeseq_has_reference_sequence is undocumented // method in the tskit C API (see trees.h), but documented in tskit Python API // https://tskit.dev/tskit/docs/stable/python-api.html#tskit.TreeSequence.has_reference_sequence // [[Rcpp::export]] -bool ts_ptr_has_reference_sequence(const SEXP ts) { +bool ts_xptr_has_reference_sequence(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return tsk_treeseq_has_reference_sequence(ts_xptr); } -// @describeIn ts_ptr_summary Get the time units string +// PUBLIC +// @describeIn ts_xptr_summary Get the time units string // [[Rcpp::export]] -Rcpp::String ts_ptr_time_units(const SEXP ts) { +Rcpp::String ts_xptr_time_units(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); const char *p = tsk_treeseq_get_time_units(ts_xptr); tsk_size_t n = tsk_treeseq_get_time_units_length(ts_xptr); @@ -481,30 +520,34 @@ Rcpp::String ts_ptr_time_units(const SEXP ts) { return Rcpp::String(time_units); } -// @describeIn ts_ptr_summary Get the discrete time status +// PUBLIC +// @describeIn ts_xptr_summary Get the discrete time status // [[Rcpp::export]] -bool ts_ptr_discrete_time(const SEXP ts) { +bool ts_xptr_discrete_time(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return tsk_treeseq_get_discrete_time(ts_xptr); } -// @describeIn ts_ptr_summary Get the min time in node table and mutation table +// PUBLIC +// @describeIn ts_xptr_summary Get the min time in node table and mutation table // [[Rcpp::export]] -double ts_ptr_min_time(const SEXP ts) { +double ts_xptr_min_time(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return tsk_treeseq_get_min_time(ts_xptr); } -// @describeIn ts_ptr_summary Get the max time in node table and mutation table +// PUBLIC +// @describeIn ts_xptr_summary Get the max time in node table and mutation table // [[Rcpp::export]] -double ts_ptr_max_time(const SEXP ts) { +double ts_xptr_max_time(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return tsk_treeseq_get_max_time(ts_xptr); } -// @describeIn ts_ptr_summary Get the file uuid string +// PUBLIC +// @describeIn ts_xptr_summary Get the file uuid string // [[Rcpp::export]] -Rcpp::String ts_ptr_file_uuid(const SEXP ts) { +Rcpp::String ts_xptr_file_uuid(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); const char *p = tsk_treeseq_get_file_uuid(ts_xptr); if (p == NULL || p[0] == '\0') { @@ -513,7 +556,8 @@ Rcpp::String ts_ptr_file_uuid(const SEXP ts) { return Rcpp::String(p); } -// @name ts_ptr_summary +// PUBLIC +// @name ts_xptr_summary // @title Summary of properties and number of records in a tree sequence // @param ts an external pointer to tree sequence as a \code{tsk_treeseq_t} // object. @@ -538,32 +582,32 @@ Rcpp::String ts_ptr_file_uuid(const SEXP ts) { // \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.tsk_treeseq_get_max_time}, // and // \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.tsk_treeseq_get_file_uuid}, -// @return \code{ts_ptr_summary} returns a named list with numbers and values, -// while functions \code{ts_ptr_*} return the number or value for each item. +// @return \code{ts_xptr_summary} returns a named list with numbers and values, +// while functions \code{ts_xptr_*} return the number or value for each item. // @examples // ts_file <- system.file("examples/test.trees", package = "RcppTskit") -// ts_ptr <- RcppTskit:::ts_ptr_load(ts_file) -// RcppTskit:::ts_ptr_summary(ts_ptr) -// RcppTskit:::ts_ptr_num_provenances(ts_ptr) -// RcppTskit:::ts_ptr_num_populations(ts_ptr) -// RcppTskit:::ts_ptr_num_migrations(ts_ptr) -// RcppTskit:::ts_ptr_num_individuals(ts_ptr) -// RcppTskit:::ts_ptr_num_samples(ts_ptr) -// RcppTskit:::ts_ptr_num_nodes(ts_ptr) -// RcppTskit:::ts_ptr_num_edges(ts_ptr) -// RcppTskit:::ts_ptr_num_trees(ts_ptr) -// RcppTskit:::ts_ptr_num_sites(ts_ptr) -// RcppTskit:::ts_ptr_num_mutations(ts_ptr) -// RcppTskit:::ts_ptr_sequence_length(ts_ptr) -// RcppTskit:::ts_ptr_discrete_genome(ts_ptr) -// RcppTskit:::ts_ptr_has_reference_sequence(ts_ptr) -// RcppTskit:::ts_ptr_time_units(ts_ptr) -// RcppTskit:::ts_ptr_discrete_time(ts_ptr) -// RcppTskit:::ts_ptr_min_time(ts_ptr) -// RcppTskit:::ts_ptr_max_time(ts_ptr) -// RcppTskit:::ts_ptr_file_uuid(ts_ptr) -// [[Rcpp::export]] -Rcpp::List ts_ptr_summary(const SEXP ts) { +// ts_xptr <- RcppTskit:::ts_xptr_load(ts_file) +// RcppTskit:::ts_xptr_summary(ts_xptr) +// RcppTskit:::ts_xptr_num_provenances(ts_xptr) +// RcppTskit:::ts_xptr_num_populations(ts_xptr) +// RcppTskit:::ts_xptr_num_migrations(ts_xptr) +// RcppTskit:::ts_xptr_num_individuals(ts_xptr) +// RcppTskit:::ts_xptr_num_samples(ts_xptr) +// RcppTskit:::ts_xptr_num_nodes(ts_xptr) +// RcppTskit:::ts_xptr_num_edges(ts_xptr) +// RcppTskit:::ts_xptr_num_trees(ts_xptr) +// RcppTskit:::ts_xptr_num_sites(ts_xptr) +// RcppTskit:::ts_xptr_num_mutations(ts_xptr) +// RcppTskit:::ts_xptr_sequence_length(ts_xptr) +// RcppTskit:::ts_xptr_discrete_genome(ts_xptr) +// RcppTskit:::ts_xptr_has_reference_sequence(ts_xptr) +// RcppTskit:::ts_xptr_time_units(ts_xptr) +// RcppTskit:::ts_xptr_discrete_time(ts_xptr) +// RcppTskit:::ts_xptr_min_time(ts_xptr) +// RcppTskit:::ts_xptr_max_time(ts_xptr) +// RcppTskit:::ts_xptr_file_uuid(ts_xptr) +// [[Rcpp::export]] +Rcpp::List ts_xptr_summary(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); return Rcpp::List::create( Rcpp::_["num_provenances"] = tsk_treeseq_get_num_provenances(ts_xptr), @@ -580,13 +624,14 @@ Rcpp::List ts_ptr_summary(const SEXP ts) { Rcpp::_["discrete_genome"] = tsk_treeseq_get_discrete_genome(ts_xptr), Rcpp::_["has_reference_sequence"] = tsk_treeseq_has_reference_sequence(ts_xptr), - Rcpp::_["time_units"] = ts_ptr_time_units(ts), + Rcpp::_["time_units"] = ts_xptr_time_units(ts), Rcpp::_["discrete_time"] = tsk_treeseq_get_discrete_time(ts_xptr), - Rcpp::_["min_time"] = ts_ptr_min_time(ts), - Rcpp::_["max_time"] = ts_ptr_max_time(ts), - Rcpp::_["file_uuid"] = ts_ptr_file_uuid(ts)); + Rcpp::_["min_time"] = ts_xptr_min_time(ts), + Rcpp::_["max_time"] = ts_xptr_max_time(ts), + Rcpp::_["file_uuid"] = ts_xptr_file_uuid(ts)); } +// PUBLIC // @title Get the length of metadata in a tree sequence and its tables // @param ts tree sequence as a \code{\link{TreeSequence}} object or // an external pointer to tree sequence as a \code{tsk_treeseq_t} object. @@ -598,10 +643,10 @@ Rcpp::List ts_ptr_summary(const SEXP ts) { // @return A named list with the length of metadata. // @examples // ts_file <- system.file("examples/test.trees", package = "RcppTskit") -// ts_ptr <- RcppTskit:::ts_ptr_load(ts_file) -// RcppTskit:::ts_ptr_metadata_length(ts_ptr) +// ts_xptr <- RcppTskit:::ts_xptr_load(ts_file) +// RcppTskit:::ts_xptr_metadata_length(ts_xptr) // [[Rcpp::export]] -Rcpp::List ts_ptr_metadata_length(const SEXP ts) { +Rcpp::List ts_xptr_metadata_length(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); const tsk_table_collection_t *tables = ts_xptr->tables; return Rcpp::List::create( @@ -624,16 +669,17 @@ Rcpp::List ts_ptr_metadata_length(const SEXP ts) { static_cast(tables->mutations.metadata_length)); } +// INTERNAL (for now) // # nocov start // TODO: Metadata notes if we do anything with metadata #36 // https://github.com/HighlanderLab/RcppTskit/issues/36 // This is how we would get metadata, but it will be raw bytes, // so would have to work with schema and codes ... // ts_file <- system.file("examples/test.trees", package = "RcppTskit") -// ts_ptr <- RcppTskit:::ts_ptr_load(ts_file) -// RcppTskit:::ts_ptr_metadata(ts_ptr) +// ts_xptr <- RcppTskit:::ts_xptr_load(ts_file) +// RcppTskit:::ts_xptr_metadata(ts_xptr) // slendr::ts_metadata(slim_ts) -Rcpp::String ts_ptr_metadata(const SEXP ts) { +Rcpp::String ts_xptr_metadata(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); const char *p = tsk_treeseq_get_metadata(ts_xptr); tsk_size_t n = tsk_treeseq_get_metadata_length(ts_xptr); @@ -647,7 +693,7 @@ Rcpp::String ts_ptr_metadata(const SEXP ts) { // TODO: Metadata notes if we do anything with metadata #36 // https://github.com/HighlanderLab/RcppTskit/issues/36 -// int ts_ptr_metadata_schema_length(const SEXP ts) { +// int ts_xptr_metadata_schema_length(const SEXP ts) { // RcppTskit_treeseq_xptr ts_xptr(ts); // return static_cast(tsk_treeseq_get_metadata_schema_length(ts_xptr)); // } @@ -668,11 +714,11 @@ Rcpp::String ts_ptr_metadata(const SEXP ts) { // * tsk_size_t time_units_length; IMPLEMENTED HERE (as part of the above) // TODO: Metadata notes if we do anything with metadata #36 // https://github.com/HighlanderLab/RcppTskit/issues/36 -// * char *metadata; "SCALAR", TODO --> tc_ptr_metadata +// * char *metadata; "SCALAR", TODO --> tc_xptr_metadata // * tsk_size_t metadata_length; SCALAR, TODO as part of the above // TODO: Metadata notes if we do anything with metadata #36 // https://github.com/HighlanderLab/RcppTskit/issues/36 -// * char *metadata_schema; "SCALAR", TODO --> tc_ptr_metadata_schema +// * char *metadata_schema; "SCALAR", TODO --> tc_xptr_metadata_schema // * tsk_size_t metadata_schema_length; SCALAR, TODO as part of the above // * tsk_reference_sequence_t reference_sequence; TODO? // * tsk_individual_table_t individuals; TABLE, SKIP OR TODO LATER #49 @@ -693,28 +739,31 @@ Rcpp::String ts_ptr_metadata(const SEXP ts) { // https://tskit.dev/tskit/docs/stable/python-api.html#sec-tables-api-table-collection // https://tskit.dev/tskit/docs/stable/python-api.html#tskit.TableCollection -// @describeIn tc_ptr_summary Get the sequence length +// PUBLIC +// @describeIn tc_xptr_summary Get the sequence length // [[Rcpp::export]] -double tc_ptr_sequence_length(const SEXP tc) { +double tc_xptr_sequence_length(const SEXP tc) { RcppTskit_table_collection_xptr tc_xptr(tc); return tc_xptr->sequence_length; } -// @describeIn tc_ptr_summary Does the table collection hold a reference genome +// PUBLIC +// @describeIn tc_xptr_summary Does the table collection hold a reference genome // sequence // @details Note that tsk_table_collection_has_reference_sequence is // undocumented method in the tskit C API (see tables.h), // but documented in tskit Python API // https://tskit.dev/tskit/docs/stable/python-api.html#tskit.TableCollection.has_reference_sequence // [[Rcpp::export]] -bool tc_ptr_has_reference_sequence(const SEXP tc) { +bool tc_xptr_has_reference_sequence(const SEXP tc) { RcppTskit_table_collection_xptr tc_xptr(tc); return tsk_table_collection_has_reference_sequence(tc_xptr); } -// @describeIn tc_ptr_summary Get the time units string +// PUBLIC +// @describeIn tc_xptr_summary Get the time units string // [[Rcpp::export]] -Rcpp::String tc_ptr_time_units(const SEXP tc) { +Rcpp::String tc_xptr_time_units(const SEXP tc) { RcppTskit_table_collection_xptr tc_xptr(tc); const char *p = tc_xptr->time_units; tsk_size_t n = tc_xptr->time_units_length; @@ -725,9 +774,10 @@ Rcpp::String tc_ptr_time_units(const SEXP tc) { return Rcpp::String(time_units); } -// @describeIn tc_ptr_summary Get the file uuid string +// PUBLIC +// @describeIn tc_xptr_summary Get the file uuid string // [[Rcpp::export]] -Rcpp::String tc_ptr_file_uuid(const SEXP tc) { +Rcpp::String tc_xptr_file_uuid(const SEXP tc) { RcppTskit_table_collection_xptr tc_xptr(tc); if (tc_xptr->file_uuid == NULL || tc_xptr->file_uuid[0] == '\0') { return Rcpp::String(NA_STRING); @@ -735,32 +785,34 @@ Rcpp::String tc_ptr_file_uuid(const SEXP tc) { return Rcpp::String(tc_xptr->file_uuid); } -// @describeIn tc_ptr_summary Is the table collection indexed +// PUBLIC +// @describeIn tc_xptr_summary Is the table collection indexed // [[Rcpp::export]] -bool tc_ptr_has_index(const SEXP tc) { +bool tc_xptr_has_index(const SEXP tc) { RcppTskit_table_collection_xptr tc_xptr(tc); return tsk_table_collection_has_index(tc_xptr, 0); } +// PUBLIC // @title Summary of properties and number of records in a table collection // @param tc an external pointer to table collection as a // \code{tsk_table_collection_t} object. // @details These functions return the summary of properties and number of // records in a table collection, by accessing its elements and/or calling // \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.tsk_table_collection_has_index} -// @return \code{tc_ptr_summary} returns a named list with numbers and values, -// while functions \code{tc_ptr_*} return the number or value for each item. +// @return \code{tc_xptr_summary} returns a named list with numbers and values, +// while functions \code{tc_xptr_*} return the number or value for each item. // @examples // ts_file <- system.file("examples/test.trees", package = "RcppTskit") -// tc_ptr <- RcppTskit:::tc_ptr_load(ts_file) -// RcppTskit:::tc_ptr_summary(tc_ptr) -// RcppTskit:::tc_ptr_sequence_length(tc_ptr) -// RcppTskit:::tc_ptr_has_reference_sequence(tc_ptr) -// RcppTskit:::tc_ptr_time_units(tc_ptr) -// RcppTskit:::tc_ptr_file_uuid(tc_ptr) -// RcppTskit:::tc_ptr_has_index(tc_ptr) -// [[Rcpp::export]] -Rcpp::List tc_ptr_summary(const SEXP tc) { +// tc_xptr <- RcppTskit:::tc_xptr_load(ts_file) +// RcppTskit:::tc_xptr_summary(tc_xptr) +// RcppTskit:::tc_xptr_sequence_length(tc_xptr) +// RcppTskit:::tc_xptr_has_reference_sequence(tc_xptr) +// RcppTskit:::tc_xptr_time_units(tc_xptr) +// RcppTskit:::tc_xptr_file_uuid(tc_xptr) +// RcppTskit:::tc_xptr_has_index(tc_xptr) +// [[Rcpp::export]] +Rcpp::List tc_xptr_summary(const SEXP tc) { RcppTskit_table_collection_xptr tc_xptr(tc); const tsk_table_collection_t *tables = tc_xptr; return Rcpp::List::create( @@ -773,22 +825,23 @@ Rcpp::List tc_ptr_summary(const SEXP tc) { Rcpp::_["num_sites"] = tables->sites.num_rows, Rcpp::_["num_mutations"] = tables->mutations.num_rows, Rcpp::_["sequence_length"] = tables->sequence_length, - Rcpp::_["has_reference_sequence"] = tc_ptr_has_reference_sequence(tc), - Rcpp::_["time_units"] = tc_ptr_time_units(tc), - Rcpp::_["file_uuid"] = tc_ptr_file_uuid(tc), - Rcpp::_["has_index"] = tc_ptr_has_index(tc)); + Rcpp::_["has_reference_sequence"] = tc_xptr_has_reference_sequence(tc), + Rcpp::_["time_units"] = tc_xptr_time_units(tc), + Rcpp::_["file_uuid"] = tc_xptr_file_uuid(tc), + Rcpp::_["has_index"] = tc_xptr_has_index(tc)); } +// PUBLIC // @title Get the length of metadata in a table collection and its tables // @param tc an external pointer to table collection as a // \code{tsk_table_collection_t} object. // @return A named list with the length of metadata. // @examples // ts_file <- system.file("examples/test.trees", package = "RcppTskit") -// tc_ptr <- RcppTskit:::tc_ptr_load(ts_file) -// RcppTskit:::tc_ptr_metadata_length(tc_ptr) +// tc_xptr <- RcppTskit:::tc_xptr_load(ts_file) +// RcppTskit:::tc_xptr_metadata_length(tc_xptr) // [[Rcpp::export]] -Rcpp::List tc_ptr_metadata_length(const SEXP tc) { +Rcpp::List tc_xptr_metadata_length(const SEXP tc) { RcppTskit_table_collection_xptr tc_xptr(tc); return Rcpp::List::create( Rcpp::_["tc"] = static_cast(tc_xptr->metadata_length), @@ -807,7 +860,7 @@ Rcpp::List tc_ptr_metadata_length(const SEXP tc) { // TODO: Metadata notes if we do anything with metadata #36 // https://github.com/HighlanderLab/RcppTskit/issues/36 -// int tc_ptr_metadata_schema_length(const SEXP tc) { +// int tc_xptr_metadata_schema_length(const SEXP tc) { // RcppTskit_table_collection_xptr tc_xptr(tc); // return static_cast(tc_xptr->metadata_schema_length); // } @@ -815,6 +868,6 @@ Rcpp::List tc_ptr_metadata_length(const SEXP tc) { // TODO: document the above function // TODO: expose the above function to R, including TableCollection method -// TODO: Develop tc_ptr_metadata_schema +// TODO: Develop tc_xptr_metadata_schema // TODO: Metadata notes if we do anything with metadata #36 // https://github.com/HighlanderLab/RcppTskit/issues/36 diff --git a/RcppTskit/src/tests.cpp b/RcppTskit/src/tests.cpp index fa30a78..91ed807 100644 --- a/RcppTskit/src/tests.cpp +++ b/RcppTskit/src/tests.cpp @@ -6,22 +6,27 @@ extern "C" void RcppTskit_bug_assert_c(void); +// TEST-ONLY // [[Rcpp::export]] void test_tsk_bug_assert_c() { RcppTskit_bug_assert_c(); } +// TEST-ONLY // [[Rcpp::export]] void test_tsk_bug_assert_cpp() { tsk_bug_assert(0); } extern "C" void RcppTskit_trace_error_c(void); +// TEST-ONLY // This is tested if we compile with -DTSK_TRACE_ERRORS // [[Rcpp::export]] void test_tsk_trace_error_c() { RcppTskit_trace_error_c(); } // # nocov +// TEST-ONLY // This is tested if we compile with -DTSK_TRACE_ERRORS // [[Rcpp::export]] void test_tsk_trace_error_cpp() { (void)tsk_trace_error(-1); } // # nocov +// TEST-ONLY // [[Rcpp::export]] bool tsk_trace_errors_defined() { #ifdef TSK_TRACE_ERRORS @@ -34,15 +39,16 @@ bool tsk_trace_errors_defined() { // ---------------------------------------------------------------------------- // Declarations for wrappers implemented in RcppTskit.cpp. -SEXP ts_ptr_to_tc_ptr(const SEXP ts, const int options); -SEXP tc_ptr_to_ts_ptr(const SEXP tc, const int options); +SEXP ts_xptr_to_tc_xptr(const SEXP ts, const int options); +SEXP tc_xptr_to_ts_xptr(const SEXP tc, const int options); -// @title Force tskit-level error path in \code{ts_ptr_to_tc_ptr} +// TEST-ONLY +// @title Force tskit-level error path in \code{ts_xptr_to_tc_xptr} // @param ts an external pointer to tree sequence as a \code{tsk_treeseq_t} // object. // @return No return value; called for side effects - testing. // [[Rcpp::export]] -SEXP test_ts_ptr_to_tc_ptr_forced_error(const SEXP ts) { +SEXP test_ts_xptr_to_tc_xptr_forced_error(const SEXP ts) { RcppTskit_treeseq_xptr ts_xptr(ts); tsk_node_table_t &nodes = ts_xptr->tables->nodes; tsk_flags_t *saved_flags = nodes.flags; @@ -50,8 +56,8 @@ SEXP test_ts_ptr_to_tc_ptr_forced_error(const SEXP ts) { nodes.flags = NULL; nodes.time = NULL; try { - SEXP ret = ts_ptr_to_tc_ptr(ts, 0); - // Lines below not hit by tests because ts_ptr_to_tc_ptr() throws error + SEXP ret = ts_xptr_to_tc_xptr(ts, 0); + // Lines below not hit by tests because ts_xptr_to_tc_xptr() throws error // # nocov start nodes.flags = saved_flags; nodes.time = saved_time; @@ -64,12 +70,13 @@ SEXP test_ts_ptr_to_tc_ptr_forced_error(const SEXP ts) { } } -// @title Force tskit-level error path in \code{tc_ptr_to_ts_ptr} +// TEST-ONLY +// @title Force tskit-level error path in \code{tc_xptr_to_ts_xptr} // @param tc an external pointer to table collection as a // \code{tsk_table_collection_t} object. // @return No return value; called for side effects - testing. // [[Rcpp::export]] -SEXP test_tc_ptr_to_ts_ptr_forced_error(const SEXP tc) { +SEXP test_tc_xptr_to_ts_xptr_forced_error(const SEXP tc) { RcppTskit_table_collection_xptr tc_xptr(tc); tsk_node_table_t &nodes = tc_xptr->nodes; tsk_flags_t *saved_flags = nodes.flags; @@ -77,8 +84,8 @@ SEXP test_tc_ptr_to_ts_ptr_forced_error(const SEXP tc) { nodes.flags = NULL; nodes.time = NULL; try { - SEXP ret = tc_ptr_to_ts_ptr(tc, 0); - // Lines below not hit by tests because ts_ptr_to_tc_ptr() throws error + SEXP ret = tc_xptr_to_ts_xptr(tc, 0); + // Lines below not hit by tests because ts_xptr_to_tc_xptr() throws error // # nocov start nodes.flags = saved_flags; nodes.time = saved_time; diff --git a/RcppTskit/tests/testthat/test_TableCollection.R b/RcppTskit/tests/testthat/test_TableCollection.R index 80aaeb5..c8453bc 100644 --- a/RcppTskit/tests/testthat/test_TableCollection.R +++ b/RcppTskit/tests/testthat/test_TableCollection.R @@ -44,32 +44,32 @@ test_that("TableCollection$new() works", { test_that("TableCollection and TreeSequence round-trip works", { ts_file <- system.file("examples/test.trees", package = "RcppTskit") test_trees_file_uuid <- "79ec383f-a57d-b44f-2a5c-f0feecbbcb32" - ts_ptr <- ts_ptr_load(ts_file) + ts_xptr <- ts_xptr_load(ts_file) # ---- Integer bitmask of tskit flags ---- - # See ts_ptr_to_tc_ptr() and tc_ptr_to_ts_ptr() documentation + # See ts_xptr_to_tc_xptr() and tc_xptr_to_ts_xptr() documentation unsupported_options <- bitwShiftL(1L, 27) supported_copy_option <- bitwShiftL(1L, 0) supported_init_options <- bitwOr(bitwShiftL(1L, 0), bitwShiftL(1L, 1)) expect_error( - ts_ptr_to_tc_ptr(ts_ptr, options = bitwShiftL(1L, 30)), + ts_xptr_to_tc_xptr(ts_xptr, options = bitwShiftL(1L, 30)), regexp = "does not support TSK_NO_INIT" ) expect_error( - ts_ptr_to_tc_ptr(ts_ptr, options = unsupported_options), + ts_xptr_to_tc_xptr(ts_xptr, options = unsupported_options), regexp = "only supports copy option TSK_COPY_FILE_UUID" ) expect_true(is( - ts_ptr_to_tc_ptr(ts_ptr, options = supported_copy_option), + ts_xptr_to_tc_xptr(ts_xptr, options = supported_copy_option), "externalptr" )) - # ---- ts_ptr --> tc_ptr --> ts_ptr ---- + # ---- ts_xptr --> tc_xptr --> ts_xptr ---- - tc_ptr <- ts_ptr_to_tc_ptr(ts_ptr) - expect_true(is(tc_ptr, "externalptr")) - p <- tc_ptr_print(tc_ptr) + tc_xptr <- ts_xptr_to_tc_xptr(ts_xptr) + expect_true(is(tc_xptr, "externalptr")) + p <- tc_xptr_print(tc_xptr) expect_equal( p, list( @@ -110,24 +110,24 @@ test_that("TableCollection and TreeSequence round-trip works", { ) ) expect_error( - tc_ptr_to_ts_ptr(tc_ptr, options = bitwShiftL(1L, 28)), + tc_xptr_to_ts_xptr(tc_xptr, options = bitwShiftL(1L, 28)), regexp = "does not support TSK_TAKE_OWNERSHIP" ) expect_error( - tc_ptr_to_ts_ptr(tc_ptr, options = unsupported_options), + tc_xptr_to_ts_xptr(tc_xptr, options = unsupported_options), regexp = "only supports init options" ) expect_true(is( - tc_ptr_to_ts_ptr(tc_ptr, options = supported_init_options), + tc_xptr_to_ts_xptr(tc_xptr, options = supported_init_options), "externalptr" )) - ts_ptr2 <- tc_ptr_to_ts_ptr(tc_ptr) - p_ts_ptr <- ts_ptr_print(ts_ptr) - p_ts_ptr2 <- ts_ptr_print(ts_ptr2) - i_file_uuid <- p_ts_ptr$ts$property == "file_uuid" - p_ts_ptr$ts$value[i_file_uuid] <- NA_character_ - p_ts_ptr2$ts$value[p_ts_ptr2$ts$property == "file_uuid"] <- NA_character_ - expect_equal(p_ts_ptr, p_ts_ptr2) + ts_xptr2 <- tc_xptr_to_ts_xptr(tc_xptr) + p_ts_xptr <- ts_xptr_print(ts_xptr) + p_ts_xptr2 <- ts_xptr_print(ts_xptr2) + i_file_uuid <- p_ts_xptr$ts$property == "file_uuid" + p_ts_xptr$ts$value[i_file_uuid] <- NA_character_ + p_ts_xptr2$ts$value[p_ts_xptr2$ts$property == "file_uuid"] <- NA_character_ + expect_equal(p_ts_xptr, p_ts_xptr2) # ---- ts --> tc --> ts ---- @@ -201,14 +201,14 @@ test_that("TableCollection and TreeSequence round-trip works", { # Edge cases expect_error( - test_ts_ptr_to_tc_ptr_forced_error(ts_ptr), + test_ts_xptr_to_tc_xptr_forced_error(ts_xptr), regexp = "TSK_ERR_BAD_PARAM_VALUE" ) - expect_true(is(ts_ptr_to_tc_ptr(ts_ptr), "externalptr")) + expect_true(is(ts_xptr_to_tc_xptr(ts_xptr), "externalptr")) expect_error( - test_tc_ptr_to_ts_ptr_forced_error(tc_ptr), + test_tc_xptr_to_ts_xptr_forced_error(tc_xptr), regexp = "TSK_ERR_BAD_PARAM_VALUE" ) - expect_true(is(tc_ptr_to_ts_ptr(tc_ptr), "externalptr")) + expect_true(is(tc_xptr_to_ts_xptr(tc_xptr), "externalptr")) }) diff --git a/RcppTskit/tests/testthat/test_cpp_public_api.R b/RcppTskit/tests/testthat/test_cpp_public_api.R new file mode 100644 index 0000000..1437dd2 --- /dev/null +++ b/RcppTskit/tests/testthat/test_cpp_public_api.R @@ -0,0 +1,69 @@ +test_that("public C++ wrappers compile for downstream-style usage", { + skip_on_cran() + skip_if_not( + nzchar(system.file("libs", package = "RcppTskit")), + "Requires installed package libs for the RcppTskit plugin." + ) + + tc_public_scalars <- Rcpp::cppFunction( + code = ' + #include + Rcpp::List tc_public_scalars(SEXP tc) { + return Rcpp::List::create( + Rcpp::_["has_reference_sequence"] = + tc_xptr_has_reference_sequence(tc), + Rcpp::_["time_units"] = tc_xptr_time_units(tc), + Rcpp::_["file_uuid"] = tc_xptr_file_uuid(tc), + Rcpp::_["has_index"] = tc_xptr_has_index(tc) + ); + }', + depends = "RcppTskit", + plugins = "RcppTskit" + ) + + ts_public_summary <- Rcpp::cppFunction( + code = ' + #include + Rcpp::List ts_public_summary(SEXP ts) { + return ts_xptr_summary(ts); + }', + depends = "RcppTskit", + plugins = "RcppTskit" + ) + + tc_public_summary <- Rcpp::cppFunction( + code = ' + #include + Rcpp::List tc_public_summary(SEXP tc) { + return tc_xptr_summary(tc); + }', + depends = "RcppTskit", + plugins = "RcppTskit" + ) + + ts_file <- system.file("examples/test.trees", package = "RcppTskit") + # jarl-ignore internal_function: it's just a test + ts_xptr <- RcppTskit:::ts_xptr_load(ts_file) + # jarl-ignore internal_function: it's just a test + tc_xptr <- RcppTskit:::tc_xptr_load(ts_file) + + tc_scalars <- tc_public_scalars(tc_xptr) + # jarl-ignore internal_function: it's just a test + expect_identical( + tc_scalars$has_reference_sequence, + RcppTskit:::tc_xptr_has_reference_sequence(tc_xptr) + ) + # jarl-ignore internal_function: it's just a test + expect_identical( + tc_scalars$time_units, + RcppTskit:::tc_xptr_time_units(tc_xptr) + ) + # jarl-ignore internal_function: it's just a test + expect_identical(tc_scalars$file_uuid, RcppTskit:::tc_xptr_file_uuid(tc_xptr)) + # jarl-ignore internal_function: it's just a test + expect_identical(tc_scalars$has_index, RcppTskit:::tc_xptr_has_index(tc_xptr)) + # jarl-ignore internal_function: it's just a test + expect_equal(ts_public_summary(ts_xptr), RcppTskit:::ts_xptr_summary(ts_xptr)) + # jarl-ignore internal_function: it's just a test + expect_equal(tc_public_summary(tc_xptr), RcppTskit:::tc_xptr_summary(tc_xptr)) +}) diff --git a/RcppTskit/tests/testthat/test_load_summary_and_dump.R b/RcppTskit/tests/testthat/test_load_summary_and_dump.R index d7e6e27..1cad22a 100644 --- a/RcppTskit/tests/testthat/test_load_summary_and_dump.R +++ b/RcppTskit/tests/testthat/test_load_summary_and_dump.R @@ -6,15 +6,15 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { # ---- ts_load() ---- - expect_error(ts_ptr_load()) + expect_error(ts_xptr_load()) expect_error(ts_load()) - expect_error(ts_ptr_load("nonexistent_ts")) + expect_error(ts_xptr_load("nonexistent_ts")) expect_error(ts_load("nonexistent_ts")) ts_file <- system.file("examples/test.trees", package = "RcppTskit") expect_error( - ts_ptr_load(ts_file, options = bitwShiftL(1L, 30)), - regexp = "ts_ptr_load only supports load options" + ts_xptr_load(ts_file, options = bitwShiftL(1L, 30)), + regexp = "ts_xptr_load only supports load options" # TSK_LOAD_SKIP_TABLES (1 << 0) and TSK_LOAD_SKIP_REFERENCE_SEQUENCE (1 << 1) ) @@ -23,11 +23,11 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { ts_load(ts_file, skip_tables = "y"), regexp = "skip_tables must be TRUE/FALSE!" ) - expect_no_error(ts_ptr_load(ts_file, options = bitwShiftL(1L, 0L))) + expect_no_error(ts_xptr_load(ts_file, options = bitwShiftL(1L, 0L))) expect_no_error(ts_load(ts_file, skip_tables = TRUE)) - check_empty_tables_ptr <- function(ts) { + check_empty_tables_xptr <- function(ts) { # jarl-ignore implicit_assignment: it's just a test - tmp <- capture.output(p <- ts_ptr_print(ts)) + tmp <- capture.output(p <- ts_xptr_print(ts)) expect_true(all(p$tables$number == 0)) } check_empty_tables <- function(ts) { @@ -35,8 +35,8 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { tmp <- capture.output(p <- ts$print()) expect_true(all(p$tables$number == 0)) } - ts_ptr <- ts_ptr_load(ts_file, options = bitwShiftL(1L, 0L)) - check_empty_tables_ptr(ts_ptr) + ts_xptr <- ts_xptr_load(ts_file, options = bitwShiftL(1L, 0L)) + check_empty_tables_xptr(ts_xptr) ts <- ts_load(ts_file, skip_tables = TRUE) check_empty_tables(ts) ts <- TreeSequence$new(file = ts_file, skip_tables = TRUE) @@ -47,15 +47,15 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { ts_load(ts_file, skip_reference_sequence = 1L), regexp = "skip_reference_sequence must be TRUE/FALSE!" ) - expect_no_error(ts_ptr_load(ts_file, options = bitwShiftL(1L, 1L))) + expect_no_error(ts_xptr_load(ts_file, options = bitwShiftL(1L, 1L))) expect_no_error(ts_load(ts_file, skip_reference_sequence = TRUE)) ts_with_ref_seq_file <- system.file( "examples/test_with_ref_seq.trees", package = "RcppTskit" ) - expect_no_error(ts_ptr_load(ts_with_ref_seq_file)) - expect_no_error(ts_ptr_load( + expect_no_error(ts_xptr_load(ts_with_ref_seq_file)) + expect_no_error(ts_xptr_load( ts_with_ref_seq_file, options = bitwShiftL(1L, 1L) )) @@ -63,20 +63,20 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { expect_no_error(ts_load(ts_with_ref_seq_file, skip_reference_sequence = TRUE)) # For tests below - ts_ptr <- ts_ptr_load(ts_file) + ts_xptr <- ts_xptr_load(ts_file) ts <- ts_load(ts_file) # ---- tc_load() ---- - expect_error(tc_ptr_load()) + expect_error(tc_xptr_load()) expect_error(tc_load()) - expect_error(tc_ptr_load("nonexistent_ts")) + expect_error(tc_xptr_load("nonexistent_ts")) expect_error(tc_load("nonexistent_ts")) ts_file <- system.file("examples/test.trees", package = "RcppTskit") expect_error( - tc_ptr_load(ts_file, options = bitwShiftL(1L, 30)), - regexp = "tc_ptr_load only supports load options" + tc_xptr_load(ts_file, options = bitwShiftL(1L, 30)), + regexp = "tc_xptr_load only supports load options" # TSK_LOAD_SKIP_TABLES (1 << 0) and TSK_LOAD_SKIP_REFERENCE_SEQUENCE (1 << 1) ) @@ -85,11 +85,11 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { tc_load(ts_file, skip_tables = "y"), regexp = "skip_tables must be TRUE/FALSE!" ) - expect_no_error(tc_ptr_load(ts_file, options = bitwShiftL(1L, 0L))) + expect_no_error(tc_xptr_load(ts_file, options = bitwShiftL(1L, 0L))) expect_no_error(tc_load(ts_file, skip_tables = TRUE)) - check_empty_tables_ptr <- function(tc) { + check_empty_tables_xptr <- function(tc) { # jarl-ignore implicit_assignment: it's just a test - tmp <- capture.output(p <- tc_ptr_print(tc)) + tmp <- capture.output(p <- tc_xptr_print(tc)) expect_true(all(p$tables$number == 0)) } check_empty_tables <- function(tc) { @@ -97,8 +97,8 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { tmp <- capture.output(p <- tc$print()) expect_true(all(p$tables$number == 0)) } - tc_ptr <- tc_ptr_load(ts_file, options = bitwShiftL(1L, 0L)) - check_empty_tables_ptr(tc_ptr) + tc_xptr <- tc_xptr_load(ts_file, options = bitwShiftL(1L, 0L)) + check_empty_tables_xptr(tc_xptr) tc <- tc_load(ts_file, skip_tables = TRUE) check_empty_tables(tc) tc <- TableCollection$new(file = ts_file, skip_tables = TRUE) @@ -109,15 +109,15 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { tc_load(ts_file, skip_reference_sequence = 1L), regexp = "skip_reference_sequence must be TRUE/FALSE!" ) - expect_no_error(tc_ptr_load(ts_file, options = bitwShiftL(1L, 1L))) + expect_no_error(tc_xptr_load(ts_file, options = bitwShiftL(1L, 1L))) expect_no_error(tc_load(ts_file, skip_reference_sequence = TRUE)) ts_with_ref_seq_file <- system.file( "examples/test_with_ref_seq.trees", package = "RcppTskit" ) - expect_no_error(tc_ptr_load(ts_with_ref_seq_file)) - expect_no_error(tc_ptr_load( + expect_no_error(tc_xptr_load(ts_with_ref_seq_file)) + expect_no_error(tc_xptr_load( ts_with_ref_seq_file, options = bitwShiftL(1L, 1L) )) @@ -125,16 +125,16 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { expect_no_error(tc_load(ts_with_ref_seq_file, skip_reference_sequence = TRUE)) # For tests below - tc_ptr <- tc_ptr_load(ts_file) + tc_xptr <- tc_xptr_load(ts_file) tc <- tc_load(ts_file) - # ---- ts_ptr_summary() ---- + # ---- ts_xptr_summary() ---- # Simple comparison of summaries - expect_error(ts_ptr_summary(ts)) - n_ptr <- ts_ptr_summary(ts_ptr) + expect_error(ts_xptr_summary(ts)) + n_xptr <- ts_xptr_summary(ts_xptr) expect_equal( - n_ptr, + n_xptr, list( # we got these numbers from inst/examples/create_test.trees.R "num_provenances" = 2L, @@ -158,177 +158,177 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { ) ) - expect_error(ts_ptr_num_provenances()) - expect_error(ts_ptr_num_provenances(ts)) - n_ptr <- ts_ptr_num_provenances(ts_ptr) - expect_true(is.integer(n_ptr)) - expect_equal(n_ptr, 2L) + expect_error(ts_xptr_num_provenances()) + expect_error(ts_xptr_num_provenances(ts)) + n_xptr <- ts_xptr_num_provenances(ts_xptr) + expect_true(is.integer(n_xptr)) + expect_equal(n_xptr, 2L) expect_equal(ts$num_provenances(), 2L) - expect_error(ts_ptr_num_populations()) - expect_error(ts_ptr_num_populations(ts)) - n_ptr <- ts_ptr_num_populations(ts_ptr) - expect_true(is.integer(n_ptr)) - expect_equal(n_ptr, 1L) + expect_error(ts_xptr_num_populations()) + expect_error(ts_xptr_num_populations(ts)) + n_xptr <- ts_xptr_num_populations(ts_xptr) + expect_true(is.integer(n_xptr)) + expect_equal(n_xptr, 1L) expect_equal(ts$num_populations(), 1L) - expect_error(ts_ptr_num_migrations()) - expect_error(ts_ptr_num_migrations(ts)) - n_ptr <- ts_ptr_num_migrations(ts_ptr) - expect_true(is.integer(n_ptr)) - expect_equal(n_ptr, 0L) + expect_error(ts_xptr_num_migrations()) + expect_error(ts_xptr_num_migrations(ts)) + n_xptr <- ts_xptr_num_migrations(ts_xptr) + expect_true(is.integer(n_xptr)) + expect_equal(n_xptr, 0L) expect_equal(ts$num_migrations(), 0L) - expect_error(ts_ptr_num_individuals()) - expect_error(ts_ptr_num_individuals(ts)) - n_ptr <- ts_ptr_num_individuals(ts_ptr) - expect_true(is.integer(n_ptr)) - expect_equal(n_ptr, 8L) + expect_error(ts_xptr_num_individuals()) + expect_error(ts_xptr_num_individuals(ts)) + n_xptr <- ts_xptr_num_individuals(ts_xptr) + expect_true(is.integer(n_xptr)) + expect_equal(n_xptr, 8L) expect_equal(ts$num_individuals(), 8L) - expect_error(ts_ptr_num_samples()) - expect_error(ts_ptr_num_samples(ts)) - n_ptr <- ts_ptr_num_samples(ts_ptr) - expect_true(is.integer(n_ptr)) - expect_equal(n_ptr, 16L) + expect_error(ts_xptr_num_samples()) + expect_error(ts_xptr_num_samples(ts)) + n_xptr <- ts_xptr_num_samples(ts_xptr) + expect_true(is.integer(n_xptr)) + expect_equal(n_xptr, 16L) expect_equal(ts$num_samples(), 16L) - expect_error(ts_ptr_num_nodes()) - expect_error(ts_ptr_num_nodes(ts)) - n_ptr <- ts_ptr_num_nodes(ts_ptr) - expect_true(is.integer(n_ptr)) - expect_equal(n_ptr, 39L) + expect_error(ts_xptr_num_nodes()) + expect_error(ts_xptr_num_nodes(ts)) + n_xptr <- ts_xptr_num_nodes(ts_xptr) + expect_true(is.integer(n_xptr)) + expect_equal(n_xptr, 39L) expect_equal(ts$num_nodes(), 39L) - expect_error(ts_ptr_num_edges()) - expect_error(ts_ptr_num_edges(ts)) - n_ptr <- ts_ptr_num_edges(ts_ptr) - expect_true(is.integer(n_ptr)) - expect_equal(n_ptr, 59L) + expect_error(ts_xptr_num_edges()) + expect_error(ts_xptr_num_edges(ts)) + n_xptr <- ts_xptr_num_edges(ts_xptr) + expect_true(is.integer(n_xptr)) + expect_equal(n_xptr, 59L) expect_equal(ts$num_edges(), 59L) - expect_error(ts_ptr_num_trees()) - expect_error(ts_ptr_num_trees(ts)) - n_ptr <- ts_ptr_num_trees(ts_ptr) - expect_true(is.integer(n_ptr)) - expect_equal(n_ptr, 9L) + expect_error(ts_xptr_num_trees()) + expect_error(ts_xptr_num_trees(ts)) + n_xptr <- ts_xptr_num_trees(ts_xptr) + expect_true(is.integer(n_xptr)) + expect_equal(n_xptr, 9L) expect_equal(ts$num_trees(), 9L) - expect_error(ts_ptr_num_sites()) - expect_error(ts_ptr_num_sites(ts)) - n_ptr <- ts_ptr_num_sites(ts_ptr) - expect_true(is.integer(n_ptr)) - expect_equal(n_ptr, 25L) + expect_error(ts_xptr_num_sites()) + expect_error(ts_xptr_num_sites(ts)) + n_xptr <- ts_xptr_num_sites(ts_xptr) + expect_true(is.integer(n_xptr)) + expect_equal(n_xptr, 25L) expect_equal(ts$num_sites(), 25L) - expect_error(ts_ptr_num_mutations()) - expect_error(ts_ptr_num_mutations(ts)) - n_ptr <- ts_ptr_num_mutations(ts_ptr) - expect_true(is.integer(n_ptr)) - expect_equal(n_ptr, 30L) + expect_error(ts_xptr_num_mutations()) + expect_error(ts_xptr_num_mutations(ts)) + n_xptr <- ts_xptr_num_mutations(ts_xptr) + expect_true(is.integer(n_xptr)) + expect_equal(n_xptr, 30L) expect_equal(ts$num_mutations(), 30L) - expect_error(ts_ptr_sequence_length()) - expect_error(ts_ptr_sequence_length(ts)) - n_ptr <- ts_ptr_sequence_length(ts_ptr) - expect_true(is.numeric(n_ptr)) - expect_equal(n_ptr, 100) + expect_error(ts_xptr_sequence_length()) + expect_error(ts_xptr_sequence_length(ts)) + n_xptr <- ts_xptr_sequence_length(ts_xptr) + expect_true(is.numeric(n_xptr)) + expect_equal(n_xptr, 100) expect_equal(ts$sequence_length(), 100) - expect_error(ts_ptr_discrete_genome()) - expect_error(ts_ptr_discrete_genome(ts)) - l_ptr <- ts_ptr_discrete_genome(ts_ptr) - expect_true(is.logical(l_ptr)) - expect_true(l_ptr) + expect_error(ts_xptr_discrete_genome()) + expect_error(ts_xptr_discrete_genome(ts)) + l_xptr <- ts_xptr_discrete_genome(ts_xptr) + expect_true(is.logical(l_xptr)) + expect_true(l_xptr) expect_true(ts$discrete_genome()) ts_non_discrete_file <- system.file( "examples/test_non_discrete_genome.trees", package = "RcppTskit" ) - ts_non_discrete_ptr <- ts_ptr_load(ts_non_discrete_file) + ts_non_discrete_xptr <- ts_xptr_load(ts_non_discrete_file) ts_non_discrete <- ts_load(ts_non_discrete_file) - expect_false(ts_ptr_discrete_genome(ts_non_discrete_ptr)) + expect_false(ts_xptr_discrete_genome(ts_non_discrete_xptr)) expect_false(ts_non_discrete$discrete_genome()) - expect_error(ts_ptr_has_reference_sequence()) - expect_error(ts_ptr_has_reference_sequence(ts)) - l_ptr <- ts_ptr_has_reference_sequence(ts_ptr) - expect_true(is.logical(l_ptr)) - expect_false(l_ptr) + expect_error(ts_xptr_has_reference_sequence()) + expect_error(ts_xptr_has_reference_sequence(ts)) + l_xptr <- ts_xptr_has_reference_sequence(ts_xptr) + expect_true(is.logical(l_xptr)) + expect_false(l_xptr) expect_false(ts$has_reference_sequence()) - ts_with_ref_seq_ptr <- ts_ptr_load(ts_with_ref_seq_file) + ts_with_ref_seq_xptr <- ts_xptr_load(ts_with_ref_seq_file) ts_with_ref_seq <- ts_load(ts_with_ref_seq_file) - expect_true(ts_ptr_has_reference_sequence(ts_with_ref_seq_ptr)) + expect_true(ts_xptr_has_reference_sequence(ts_with_ref_seq_xptr)) expect_true(ts_with_ref_seq$has_reference_sequence()) - f_ptr <- ts_ptr_sequence_length(ts_non_discrete_ptr) - expect_true(is.numeric(f_ptr)) - expect_equal(f_ptr, 10.5) + f_xptr <- ts_xptr_sequence_length(ts_non_discrete_xptr) + expect_true(is.numeric(f_xptr)) + expect_equal(f_xptr, 10.5) expect_equal(ts_non_discrete$sequence_length(), 10.5) - expect_error(ts_ptr_time_units()) - expect_error(ts_ptr_time_units(ts)) - c_ptr <- ts_ptr_time_units(ts_ptr) - expect_true(is.character(c_ptr)) - expect_equal(c_ptr, "generations") + expect_error(ts_xptr_time_units()) + expect_error(ts_xptr_time_units(ts)) + c_xptr <- ts_xptr_time_units(ts_xptr) + expect_true(is.character(c_xptr)) + expect_equal(c_xptr, "generations") expect_equal(ts$time_units(), "generations") - expect_error(ts_ptr_discrete_time()) - expect_error(ts_ptr_discrete_time(ts)) - l_ptr <- ts_ptr_discrete_time(ts_ptr) - expect_true(is.logical(l_ptr)) - expect_false(l_ptr) + expect_error(ts_xptr_discrete_time()) + expect_error(ts_xptr_discrete_time(ts)) + l_xptr <- ts_xptr_discrete_time(ts_xptr) + expect_true(is.logical(l_xptr)) + expect_false(l_xptr) expect_false(ts$discrete_time()) ts_discrete_time_file <- system.file( "examples/test_discrete_time.trees", package = "RcppTskit" ) - ts_discrete_time_ptr <- ts_ptr_load(ts_discrete_time_file) + ts_discrete_time_xptr <- ts_xptr_load(ts_discrete_time_file) ts_discrete_time <- ts_load(ts_discrete_time_file) - expect_true(ts_ptr_discrete_time(ts_discrete_time_ptr)) + expect_true(ts_xptr_discrete_time(ts_discrete_time_xptr)) expect_true(ts_discrete_time$discrete_time()) - expect_error(ts_ptr_min_time()) - expect_error(ts_ptr_min_time(ts)) - d_ptr <- ts_ptr_min_time(ts_ptr) - expect_true(is.numeric(d_ptr)) - expect_equal(d_ptr, 0.0) + expect_error(ts_xptr_min_time()) + expect_error(ts_xptr_min_time(ts)) + d_xptr <- ts_xptr_min_time(ts_xptr) + expect_true(is.numeric(d_xptr)) + expect_equal(d_xptr, 0.0) expect_equal(ts$min_time(), 0.0) - expect_error(ts_ptr_max_time()) - expect_error(ts_ptr_max_time(ts)) - d_ptr <- ts_ptr_max_time(ts_ptr) - expect_true(is.numeric(d_ptr)) - expect_equal(d_ptr, 6.9619933371908083) + expect_error(ts_xptr_max_time()) + expect_error(ts_xptr_max_time(ts)) + d_xptr <- ts_xptr_max_time(ts_xptr) + expect_true(is.numeric(d_xptr)) + expect_equal(d_xptr, 6.9619933371908083) expect_equal(ts$max_time(), 6.9619933371908083) - expect_error(ts_ptr_file_uuid()) - expect_error(ts_ptr_file_uuid(ts)) - c_ptr <- ts_ptr_file_uuid(ts_ptr) - expect_true(is.character(c_ptr)) - expect_equal(length(c_ptr), 1L) - expect_equal(c_ptr, test_trees_file_uuid) - expect_equal(c_ptr, ts$file_uuid()) + expect_error(ts_xptr_file_uuid()) + expect_error(ts_xptr_file_uuid(ts)) + c_xptr <- ts_xptr_file_uuid(ts_xptr) + expect_true(is.character(c_xptr)) + expect_equal(length(c_xptr), 1L) + expect_equal(c_xptr, test_trees_file_uuid) + expect_equal(c_xptr, ts$file_uuid()) expect_equal( - ts_ptr_file_uuid(ts_with_ref_seq_ptr), + ts_xptr_file_uuid(ts_with_ref_seq_xptr), test_with_ref_seq_file_uuid ) expect_equal(ts_with_ref_seq$file_uuid(), test_with_ref_seq_file_uuid) - expect_false(identical(c_ptr, ts_ptr_file_uuid(ts_with_ref_seq_ptr))) + expect_false(identical(c_xptr, ts_xptr_file_uuid(ts_with_ref_seq_xptr))) ts_from_tc <- ts$dump_tables()$tree_sequence() expect_true(is.na(ts_from_tc$file_uuid())) - expect_true(is.na(ts_ptr_file_uuid(ts_from_tc$pointer))) + expect_true(is.na(ts_xptr_file_uuid(ts_from_tc$pointer))) - # ---- tc_ptr_summary() ---- + # ---- tc_xptr_summary() ---- # Simple comparison of summaries - expect_error(tc_ptr_summary(tc)) - n_ptr_tc <- tc_ptr_summary(tc_ptr) - n_ptr_ts <- ts_ptr_summary(ts_ptr) + expect_error(tc_xptr_summary(tc)) + n_xptr_tc <- tc_xptr_summary(tc_xptr) + n_xptr_ts <- ts_xptr_summary(ts_xptr) shared_items <- c( "num_provenances", "num_populations", @@ -343,66 +343,66 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { "time_units", "file_uuid" ) - expect_equal(n_ptr_tc[shared_items], n_ptr_ts[shared_items]) + expect_equal(n_xptr_tc[shared_items], n_xptr_ts[shared_items]) - expect_error(tc_ptr_sequence_length()) - expect_error(tc_ptr_sequence_length(ts)) - n_ptr <- tc_ptr_sequence_length(tc_ptr) - expect_true(is.numeric(n_ptr)) - expect_equal(n_ptr, 100) + expect_error(tc_xptr_sequence_length()) + expect_error(tc_xptr_sequence_length(ts)) + n_xptr <- tc_xptr_sequence_length(tc_xptr) + expect_true(is.numeric(n_xptr)) + expect_equal(n_xptr, 100) expect_equal(tc$sequence_length(), 100) tc_non_discrete_file <- system.file( "examples/test_non_discrete_genome.trees", package = "RcppTskit" ) - tc_non_discrete_ptr <- tc_ptr_load(tc_non_discrete_file) + tc_non_discrete_xptr <- tc_xptr_load(tc_non_discrete_file) tc_non_discrete <- tc_load(tc_non_discrete_file) - f_ptr <- tc_ptr_sequence_length(tc_non_discrete_ptr) - expect_true(is.numeric(f_ptr)) - expect_equal(f_ptr, 10.5) + f_xptr <- tc_xptr_sequence_length(tc_non_discrete_xptr) + expect_true(is.numeric(f_xptr)) + expect_equal(f_xptr, 10.5) expect_equal(tc_non_discrete$sequence_length(), 10.5) - expect_error(tc_ptr_has_reference_sequence()) - expect_error(tc_ptr_has_reference_sequence(ts)) - l_ptr <- tc_ptr_has_reference_sequence(tc_ptr) - expect_true(is.logical(l_ptr)) - expect_false(l_ptr) + expect_error(tc_xptr_has_reference_sequence()) + expect_error(tc_xptr_has_reference_sequence(ts)) + l_xptr <- tc_xptr_has_reference_sequence(tc_xptr) + expect_true(is.logical(l_xptr)) + expect_false(l_xptr) expect_false(tc$has_reference_sequence()) - expect_error(tc_ptr_time_units()) - expect_error(tc_ptr_time_units(ts)) - c_ptr <- tc_ptr_time_units(tc_ptr) - expect_true(is.character(c_ptr)) - expect_equal(c_ptr, "generations") + expect_error(tc_xptr_time_units()) + expect_error(tc_xptr_time_units(ts)) + c_xptr <- tc_xptr_time_units(tc_xptr) + expect_true(is.character(c_xptr)) + expect_equal(c_xptr, "generations") expect_equal(tc$time_units(), "generations") - expect_error(tc_ptr_file_uuid()) - expect_error(tc_ptr_file_uuid(ts)) - c_ptr <- tc_ptr_file_uuid(tc_ptr) - expect_true(is.character(c_ptr)) - expect_equal(length(c_ptr), 1L) - expect_equal(c_ptr, test_trees_file_uuid) - expect_equal(c_ptr, tc$file_uuid()) + expect_error(tc_xptr_file_uuid()) + expect_error(tc_xptr_file_uuid(ts)) + c_xptr <- tc_xptr_file_uuid(tc_xptr) + expect_true(is.character(c_xptr)) + expect_equal(length(c_xptr), 1L) + expect_equal(c_xptr, test_trees_file_uuid) + expect_equal(c_xptr, tc$file_uuid()) tc_from_ts <- ts$dump_tables() expect_true(is.na(tc_from_ts$file_uuid())) - expect_true(is.na(tc_ptr_file_uuid(tc_from_ts$pointer))) + expect_true(is.na(tc_xptr_file_uuid(tc_from_ts$pointer))) - expect_error(tc_ptr_has_index()) - expect_error(tc_ptr_has_index(ts)) - l_ptr <- tc_ptr_has_index(tc_ptr) - expect_true(is.logical(l_ptr)) - expect_true(l_ptr) + expect_error(tc_xptr_has_index()) + expect_error(tc_xptr_has_index(ts)) + l_xptr <- tc_xptr_has_index(tc_xptr) + expect_true(is.logical(l_xptr)) + expect_true(l_xptr) expect_true(tc$has_index()) - # ---- ts_ptr_print() and ts$print() ---- + # ---- ts_xptr_print() and ts$print() ---- # Simple comparison of summaries expect_error( - ts_ptr_print("not an externalptr object"), + ts_xptr_print("not an externalptr object"), regexp = "ts must be an object of externalptr class!" ) - p_ptr <- ts_ptr_print(ts_ptr) + p_xptr <- ts_xptr_print(ts_xptr) # jarl-ignore implicit_assignment: it's just a test tmp <- capture.output(p <- ts$print()) expect_equal( @@ -461,16 +461,16 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { ) ) ) - expect_equal(p_ptr, p) + expect_equal(p_xptr, p) - # ---- tc_ptr_print() and tc$print() ---- + # ---- tc_xptr_print() and tc$print() ---- # Simple comparison of summaries expect_error( - tc_ptr_print("not an externalptr object"), + tc_xptr_print("not an externalptr object"), regexp = "tc must be an object of externalptr class!" ) - p_ptr <- tc_ptr_print(tc_ptr) + p_xptr <- tc_xptr_print(tc_xptr) # jarl-ignore implicit_assignment: it's just a test tmp <- capture.output(p <- tc$print()) expect_equal( @@ -519,35 +519,35 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { ) ) ) - expect_equal(p_ptr, p) + expect_equal(p_xptr, p) - # ---- ts_ptr_dump() ---- + # ---- ts_xptr_dump() ---- - expect_error(ts_ptr_dump()) - expect_error(ts_ptr_dump(nonexistent_ts)) - expect_error(ts_ptr_dump(file = 1)) - expect_error(ts_ptr_dump(nonexistent_ts, file = 1)) - expect_error(ts_ptr_dump(1, file = 1)) - expect_error(ts_ptr_dump(1, file = "1")) - expect_error(ts_ptr_dump(1, file = 1)) - expect_error(ts_ptr_dump(ts_ptr)) - expect_error(ts_ptr_dump(ts)) + expect_error(ts_xptr_dump()) + expect_error(ts_xptr_dump(nonexistent_ts)) + expect_error(ts_xptr_dump(file = 1)) + expect_error(ts_xptr_dump(nonexistent_ts, file = 1)) + expect_error(ts_xptr_dump(1, file = 1)) + expect_error(ts_xptr_dump(1, file = "1")) + expect_error(ts_xptr_dump(1, file = 1)) + expect_error(ts_xptr_dump(ts_xptr)) + expect_error(ts_xptr_dump(ts)) bad_path <- file.path(tempdir(), "no_such_dir", "out.trees") - expect_error(ts_ptr_dump(ts_ptr, file = bad_path)) + expect_error(ts_xptr_dump(ts_xptr, file = bad_path)) expect_error( - ts_ptr_dump(ts_ptr, file = tempfile(fileext = ".trees"), options = 1L), + ts_xptr_dump(ts_xptr, file = tempfile(fileext = ".trees"), options = 1L), regexp = "does not support non-zero options" ) # Write ts to disk, read it back, and check that nums are still the same dump_file <- tempfile(fileext = ".trees") - ts_ptr_dump(ts_ptr, dump_file) - rm(ts_ptr) - ts_ptr <- ts_ptr_load(dump_file) + ts_xptr_dump(ts_xptr, dump_file) + rm(ts_xptr) + ts_xptr <- ts_xptr_load(dump_file) file.remove(dump_file) # Simple comparison of summaries - n <- ts_ptr_summary(ts_ptr) + n <- ts_xptr_summary(ts_xptr) expect_equal( n, list( @@ -569,42 +569,42 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { "discrete_time" = FALSE, "min_time" = 0.0, "max_time" = 6.9619933371908083, - "file_uuid" = ts_ptr_file_uuid(ts_ptr) - # using ts_ptr_file_uuid() here since I don't have UUID + "file_uuid" = ts_xptr_file_uuid(ts_xptr) + # using ts_xptr_file_uuid() here since I don't have UUID # on this file from Python code due to disk serialisation # on our end (we test for correctness elsewhere anyway) ) ) - # ---- tc_ptr_dump() ---- + # ---- tc_xptr_dump() ---- - expect_error(tc_ptr_dump()) - expect_error(tc_ptr_dump(nonexistent_ts)) - expect_error(tc_ptr_dump(file = 1)) - expect_error(tc_ptr_dump(nonexistent_ts, file = 1)) - expect_error(tc_ptr_dump(1, file = 1)) - expect_error(tc_ptr_dump(1, file = "1")) - expect_error(tc_ptr_dump(1, file = 1)) - expect_error(tc_ptr_dump(tc_ptr)) - expect_error(tc_ptr_dump(tc)) + expect_error(tc_xptr_dump()) + expect_error(tc_xptr_dump(nonexistent_ts)) + expect_error(tc_xptr_dump(file = 1)) + expect_error(tc_xptr_dump(nonexistent_ts, file = 1)) + expect_error(tc_xptr_dump(1, file = 1)) + expect_error(tc_xptr_dump(1, file = "1")) + expect_error(tc_xptr_dump(1, file = 1)) + expect_error(tc_xptr_dump(tc_xptr)) + expect_error(tc_xptr_dump(tc)) bad_path <- file.path(tempdir(), "no_such_dir", "out.trees") - expect_error(tc_ptr_dump(tc_ptr, file = bad_path)) + expect_error(tc_xptr_dump(tc_xptr, file = bad_path)) expect_error( - tc_ptr_dump(tc_ptr, file = tempfile(fileext = ".trees"), options = 1L), + tc_xptr_dump(tc_xptr, file = tempfile(fileext = ".trees"), options = 1L), regexp = "does not support non-zero options" ) # Write ts to disk, read it back, and check that nums are still the same dump_file <- tempfile(fileext = ".trees") - tc_ptr_dump(tc_ptr, dump_file) - rm(tc_ptr) - tc_ptr <- tc_ptr_load(dump_file) - ts_ptr <- ts_ptr_load(dump_file) + tc_xptr_dump(tc_xptr, dump_file) + rm(tc_xptr) + tc_xptr <- tc_xptr_load(dump_file) + ts_xptr <- ts_xptr_load(dump_file) file.remove(dump_file) # Simple comparison of summaries - n_ts <- ts_ptr_summary(ts_ptr) - n_tc <- tc_ptr_summary(tc_ptr) + n_ts <- ts_xptr_summary(ts_xptr) + n_tc <- tc_xptr_summary(tc_xptr) shared_items <- c( "num_provenances", @@ -642,9 +642,9 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { file.remove(dump_file) # Simple comparison of summaries - n_ptr <- ts_ptr_summary(ts$pointer) + n_xptr <- ts_xptr_summary(ts$pointer) expect_equal( - n_ptr, + n_xptr, list( # we got these numbers from inst/examples/create_test.trees.R "num_provenances" = 2L, @@ -664,8 +664,8 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { "discrete_time" = FALSE, "min_time" = 0.0, "max_time" = 6.9619933371908083, - "file_uuid" = ts_ptr_file_uuid(ts$pointer) - # using ts_ptr_file_uuid() here since I don't have UUID + "file_uuid" = ts_xptr_file_uuid(ts$pointer) + # using ts_xptr_file_uuid() here since I don't have UUID # on this file from Python code due to disk serialisation # on our end (we test for correctness elsewhere anyway) ) @@ -691,9 +691,9 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { file.remove(dump_file) # Simple comparison of summaries - n_ptr <- tc_ptr_summary(tc$pointer) + n_xptr <- tc_xptr_summary(tc$pointer) expect_equal( - n_ptr, + n_xptr, list( # we got these numbers from inst/examples/create_test.trees.R "num_provenances" = 2L, @@ -707,21 +707,21 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { "sequence_length" = 100.0, "has_reference_sequence" = FALSE, "time_units" = "generations", - "file_uuid" = tc_ptr_file_uuid(tc$pointer), + "file_uuid" = tc_xptr_file_uuid(tc$pointer), "has_index" = TRUE - # using ts_ptr_file_uuid() here since I don't have UUID + # using ts_xptr_file_uuid() here since I don't have UUID # on this file from Python code due to disk serialisation # on our end (we test for correctness elsewhere anyway) ) ) - # ---- ts_ptr_metadata_length() ---- + # ---- ts_xptr_metadata_length() ---- # Simple comparison of the lengths of metadata - n_ptr <- ts_ptr_metadata_length(ts_ptr) + n_xptr <- ts_xptr_metadata_length(ts_xptr) n <- ts$metadata_length() expect_equal( - n_ptr, + n_xptr, list( # we got these numbers from inst/examples/create_test.trees.R "ts" = 0L, @@ -734,15 +734,15 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { "mutations" = 0L ) ) - expect_equal(n_ptr, n) + expect_equal(n_xptr, n) ts_file <- system.file("examples/test2.trees", package = "RcppTskit") - ts_ptr <- ts_ptr_load(ts_file) + ts_xptr <- ts_xptr_load(ts_file) ts <- ts_load(ts_file) - n_ptr <- ts_ptr_summary(ts_ptr) + n_xptr <- ts_xptr_summary(ts_xptr) expect_equal( - n_ptr, + n_xptr, list( # we got these numbers from inst/examples/create_test.trees.{py,R} "num_provenances" = 2L, @@ -766,10 +766,10 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { ) ) - m_ptr <- ts_ptr_metadata_length(ts_ptr) + m_xptr <- ts_xptr_metadata_length(ts_xptr) m <- ts$metadata_length() expect_equal( - m_ptr, + m_xptr, list( # we got these numbers from inst/examples/create_test.trees.{py,R} "ts" = 23L, @@ -782,13 +782,13 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { "mutations" = 0L ) ) - expect_equal(m_ptr, m) + expect_equal(m_xptr, m) - p_ptr <- ts_ptr_print(ts_ptr) + p_xptr <- ts_xptr_print(ts_xptr) # jarl-ignore implicit_assignment: it's just a test tmp <- capture.output(p <- ts$print()) expect_equal( - p_ptr, + p_xptr, list( ts = data.frame( property = c( @@ -843,26 +843,26 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { ) ) ) - expect_equal(p_ptr, p) + expect_equal(p_xptr, p) - # ---- tc_ptr_metadata_length() ---- + # ---- tc_xptr_metadata_length() ---- # Simple comparison of the lengths of metadata - n_ptr_tc <- tc_ptr_metadata_length(tc_ptr) + n_xptr_tc <- tc_xptr_metadata_length(tc_xptr) ts_file <- system.file("examples/test.trees", package = "RcppTskit") - ts_ptr <- ts_ptr_load(ts_file) - n_ptr_ts <- ts_ptr_metadata_length(ts_ptr) - names(n_ptr_tc)[1] <- "ts" - expect_equal(n_ptr_tc, n_ptr_ts) + ts_xptr <- ts_xptr_load(ts_file) + n_xptr_ts <- ts_xptr_metadata_length(ts_xptr) + names(n_xptr_tc)[1] <- "ts" + expect_equal(n_xptr_tc, n_xptr_ts) ts_file <- system.file("examples/test2.trees", package = "RcppTskit") - tc_ptr <- tc_ptr_load(ts_file) + tc_xptr <- tc_xptr_load(ts_file) tc <- tc_load(ts_file) - ts_ptr <- ts_ptr_load(ts_file) + ts_xptr <- ts_xptr_load(ts_file) ts <- ts_load(ts_file) - n_ptr_tc <- tc_ptr_summary(tc_ptr) - n_ptr_ts <- ts_ptr_summary(ts_ptr) + n_xptr_tc <- tc_xptr_summary(tc_xptr) + n_xptr_ts <- ts_xptr_summary(ts_xptr) shared_items <- c( "num_provenances", "num_populations", @@ -877,18 +877,18 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { "time_units", "file_uuid" ) - expect_equal(n_ptr_ts[shared_items], n_ptr_tc[shared_items]) + expect_equal(n_xptr_ts[shared_items], n_xptr_tc[shared_items]) - m_ptr_tc <- tc_ptr_metadata_length(tc_ptr) - m_ptr_ts <- ts_ptr_metadata_length(ts_ptr) - names(m_ptr_tc)[1] <- "ts" - expect_equal(m_ptr_tc, m_ptr_ts) + m_xptr_tc <- tc_xptr_metadata_length(tc_xptr) + m_xptr_ts <- ts_xptr_metadata_length(ts_xptr) + names(m_xptr_tc)[1] <- "ts" + expect_equal(m_xptr_tc, m_xptr_ts) - p_ptr <- tc_ptr_print(tc_ptr) + p_xptr <- tc_xptr_print(tc_xptr) # jarl-ignore implicit_assignment: it's just a test tmp <- capture.output(p <- tc$print()) expect_equal( - p_ptr, + p_xptr, list( tc = data.frame( property = c( @@ -933,5 +933,5 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { ) ) ) - expect_equal(p_ptr, p) + expect_equal(p_xptr, p) }) diff --git a/RcppTskit/tests/testthat/test_r_to_py_and_py_to_r.R b/RcppTskit/tests/testthat/test_r_to_py_and_py_to_r.R index b6bd4ee..c44a07a 100644 --- a/RcppTskit/tests/testthat/test_r_to_py_and_py_to_r.R +++ b/RcppTskit/tests/testthat/test_r_to_py_and_py_to_r.R @@ -15,8 +15,8 @@ test_that("ts_r_to_py() and ts_py_to_r() work", { ts_file <- system.file("examples/test.trees", package = "RcppTskit") ts_r <- ts_load(ts_file) - n <- ts_ptr_summary(ts_r$pointer) - m <- ts_ptr_metadata_length(ts_r$pointer) + n <- ts_xptr_summary(ts_r$pointer) + m <- ts_xptr_metadata_length(ts_r$pointer) expect_error( ts_r$r_to_py(tskit_module = "bla"), @@ -61,14 +61,14 @@ test_that("ts_r_to_py() and ts_py_to_r() work", { expect_equal(length(ts_py$tables$mutations$metadata), m$mutations) expect_error( - ts_ptr_r_to_py("not_an_externalptr_object"), + ts_xptr_r_to_py("not_an_externalptr_object"), regexp = "ts must be an object of externalptr class!" ) expect_error( - ts_ptr_r_to_py(ts_r$pointer, tskit_module = "not_a_module"), + ts_xptr_r_to_py(ts_r$pointer, tskit_module = "not_a_module"), regexp = "object must be a reticulate Python module object!" ) - ts_py <- ts_ptr_r_to_py(ts_r$pointer) + ts_py <- ts_xptr_r_to_py(ts_r$pointer) # Simple comparison of summaries and of the lengths of metadata expect_equal(ts_py$num_provenances, n$num_provenances) @@ -97,7 +97,7 @@ test_that("ts_r_to_py() and ts_py_to_r() work", { # ---- ts_py_to_r() ---- expect_error( - ts_ptr_py_to_r(1L), + ts_xptr_py_to_r(1L), regexp = "ts must be a reticulate Python object!" ) expect_error( @@ -105,7 +105,7 @@ test_that("ts_r_to_py() and ts_py_to_r() work", { regexp = "ts must be a reticulate Python object!" ) expect_error( - ts_ptr_py_to_r(ts_r), + ts_xptr_py_to_r(ts_r), regexp = "ts must be a reticulate Python object!" ) expect_error( @@ -113,10 +113,10 @@ test_that("ts_r_to_py() and ts_py_to_r() work", { regexp = "ts must be a reticulate Python object!" ) ts2_py <- ts_py$simplify(samples = c(0L, 1L, 2L, 3L)) - ts_ptr2_r <- ts_ptr_py_to_r(ts2_py) + ts_xptr2_r <- ts_xptr_py_to_r(ts2_py) ts2_r <- ts_py_to_r(ts2_py) - n2 <- ts_ptr_summary(ts_ptr2_r) - m2 <- ts_ptr_metadata_length(ts_ptr2_r) + n2 <- ts_xptr_summary(ts_xptr2_r) + m2 <- ts_xptr_metadata_length(ts_xptr2_r) # Simple comparison of summaries and of the lengths of metadata expect_equal(ts2_py$num_provenances, n2$num_provenances) @@ -145,12 +145,12 @@ test_that("ts_r_to_py() and ts_py_to_r() work", { # jarl-ignore implicit_assignment: it's just a test tmp <- capture.output(ts2_r_print <- ts2_r$print()) # jarl-ignore implicit_assignment: it's just a test - tmp <- capture.output(ts_ptr2_r_print <- ts_ptr_print(ts_ptr2_r)) + tmp <- capture.output(ts_xptr2_r_print <- ts_xptr_print(ts_xptr2_r)) sel <- ts2_r_print$ts$property == "file_uuid" ts2_r_print$ts$value[sel] <- NA_character_ - sel <- ts_ptr2_r_print$ts$property == "file_uuid" - ts_ptr2_r_print$ts$value[sel] <- NA_character_ - expect_equal(ts2_r_print, ts_ptr2_r_print) + sel <- ts_xptr2_r_print$ts$property == "file_uuid" + ts_xptr2_r_print$ts$value[sel] <- NA_character_ + expect_equal(ts2_r_print, ts_xptr2_r_print) }) test_that("tc_r_to_py() and tc_py_to_r() work", { @@ -160,8 +160,8 @@ test_that("tc_r_to_py() and tc_py_to_r() work", { ts_file <- system.file("examples/test.trees", package = "RcppTskit") tc_r <- tc_load(ts_file) - n <- tc_ptr_summary(tc_r$pointer) - m <- tc_ptr_metadata_length(tc_r$pointer) + n <- tc_xptr_summary(tc_r$pointer) + m <- tc_xptr_metadata_length(tc_r$pointer) expect_error( tc_r$r_to_py(tskit_module = "bla"), @@ -191,14 +191,14 @@ test_that("tc_r_to_py() and tc_py_to_r() work", { expect_equal(length(tc_py$mutations$metadata), m$mutations) expect_error( - tc_ptr_r_to_py("not_an_externalptr_object"), + tc_xptr_r_to_py("not_an_externalptr_object"), regexp = "tc must be an object of externalptr class!" ) expect_error( - tc_ptr_r_to_py(tc_r$pointer, tskit_module = "not_a_module"), + tc_xptr_r_to_py(tc_r$pointer, tskit_module = "not_a_module"), regexp = "object must be a reticulate Python module object!" ) - tc_py <- tc_ptr_r_to_py(tc_r$pointer) + tc_py <- tc_xptr_r_to_py(tc_r$pointer) # Simple comparison of summaries and of the lengths of metadata expect_equal(tc_py$provenances$num_rows, n$num_provenances) @@ -224,7 +224,7 @@ test_that("tc_r_to_py() and tc_py_to_r() work", { # ---- tc_py_to_r() ---- expect_error( - tc_ptr_py_to_r(1L), + tc_xptr_py_to_r(1L), regexp = "tc must be a reticulate Python object!" ) expect_error( @@ -232,7 +232,7 @@ test_that("tc_r_to_py() and tc_py_to_r() work", { regexp = "tc must be a reticulate Python object!" ) expect_error( - tc_ptr_py_to_r(tc_r), + tc_xptr_py_to_r(tc_r), regexp = "tc must be a reticulate Python object!" ) expect_error( @@ -243,10 +243,10 @@ test_that("tc_r_to_py() and tc_py_to_r() work", { tskit <- get_tskit_py() ts2_py <- tskit$load(ts_file)$simplify(samples = c(0L, 1L, 2L, 3L)) tc2_py <- ts2_py$dump_tables() - tc_ptr2_r <- tc_ptr_py_to_r(tc2_py) + tc_xptr2_r <- tc_xptr_py_to_r(tc2_py) tc2_r <- tc_py_to_r(tc2_py) - n2 <- tc_ptr_summary(tc_ptr2_r) - m2 <- tc_ptr_metadata_length(tc_ptr2_r) + n2 <- tc_xptr_summary(tc_xptr2_r) + m2 <- tc_xptr_metadata_length(tc_xptr2_r) # Simple comparison of summaries and of the lengths of metadata expect_equal(tc2_py$provenances$num_rows, n2$num_provenances) @@ -273,10 +273,10 @@ test_that("tc_r_to_py() and tc_py_to_r() work", { # jarl-ignore implicit_assignment: it's just a test tmp <- capture.output(tc2_r_print <- tc2_r$print()) # jarl-ignore implicit_assignment: it's just a test - tmp <- capture.output(tc_ptr2_r <- tc_ptr_print(tc_ptr2_r)) + tmp <- capture.output(tc_xptr2_r <- tc_xptr_print(tc_xptr2_r)) sel <- tc2_r_print$tc$property == "file_uuid" tc2_r_print$tc$value[sel] <- NA_character_ - sel <- tc_ptr2_r$tc$property == "file_uuid" - tc_ptr2_r$tc$value[sel] <- NA_character_ - expect_equal(tc2_r_print, tc_ptr2_r) + sel <- tc_xptr2_r$tc$property == "file_uuid" + tc_xptr2_r$tc$value[sel] <- NA_character_ + expect_equal(tc2_r_print, tc_xptr2_r) }) diff --git a/RcppTskit/vignettes/RcppTskit_intro.qmd b/RcppTskit/vignettes/RcppTskit_intro.qmd index db869fd..45d1bbb 100644 --- a/RcppTskit/vignettes/RcppTskit_intro.qmd +++ b/RcppTskit/vignettes/RcppTskit_intro.qmd @@ -386,7 +386,7 @@ remotes::install_github("HighlanderLab/RcppTskitTestLinking") library(RcppTskitTestLinking) # Check the demo function -print(ts_num_individuals_ptr2) +print(ts_xptr_num_individuals2) # Example tree sequence ts_file <- system.file("examples", "test.trees", package = "RcppTskit") @@ -396,7 +396,7 @@ ts <- ts_load(ts_file) ts$num_individuals() # Function from RcppTskitTestLinking (working with externalptr) -ts_num_individuals_ptr2(ts$pointer) +ts_xptr_num_individuals2(ts$pointer) ``` ## Conclusion