Skip to content

Commit b4608da

Browse files
committed
Polish docs from PR #126
1 parent 5e62773 commit b4608da

4 files changed

Lines changed: 111 additions & 88 deletions

File tree

RcppTskit/R/Class-TableCollection.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ TableCollection <- R6Class(
205205
#' @description Add a row to the nodes table.
206206
#' @param flags integer flags for the new node.
207207
#' @param time numeric time value for the new node.
208-
#' @param population integer population row ID (0-based, or \code{-1});
209-
#' \code{NULL} maps to \code{-1}.
210-
#' @param individual integer individual row ID (0-based, or \code{-1});
211-
#' \code{NULL} maps to \code{-1}.
208+
#' @param population integer population row ID (0-based);
209+
#' use \code{-1} if not known - \code{NULL} maps to \code{-1}.
210+
#' @param individual integer individual row ID (0-based);
211+
#' use \code{-1} if not known - \code{NULL} maps to \code{-1}.
212212
#' @param metadata for the new node; accepts \code{NULL},
213213
#' a raw vector, or a character of length 1.
214214
#' @details See the \code{tskit Python} equivalent at
@@ -285,17 +285,16 @@ TableCollection <- R6Class(
285285
#' @examples
286286
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
287287
#' tc <- tc_load(ts_file)
288-
#' parent <- 0L
289-
#' child <- 1L
288+
#' child <- tc$node_table_add_row(time = 0.0)
290289
#' n_before <- tc$num_edges()
291290
#' new_id <- tc$edge_table_add_row(
292-
#' left = 0, right = 1, parent = parent, child = child
291+
#' left = 0, right = 50, parent = 16L, child = child
293292
#' )
294293
#' new_id <- tc$edge_table_add_row(
295-
#' left = 1, right = 2, parent = parent, child = child, metadata = "abc"
294+
#' left = 50, right = 75, parent = 17L, child = child, metadata = "abc"
296295
#' )
297296
#' new_id <- tc$edge_table_add_row(
298-
#' left = 2, right = 3, parent = parent, child = child, metadata = charToRaw("cba")
297+
#' left = 75, right = 100, parent = 18L, child = child, metadata = charToRaw("cba")
299298
#' )
300299
#' n_after <- tc$num_edges()
301300
edge_table_add_row = function(

RcppTskit/man/TableCollection.Rd

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

RcppTskit/src/RcppTskit.cpp

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,18 +1246,20 @@ Rcpp::List rtsk_table_collection_metadata_length(const SEXP tc) {
12461246
// @param flags passed to \code{tskit C}.
12471247
// @param location numeric vector with the location of the new individual
12481248
// (can be \code{NULL}).
1249-
// @param parents integer vector with parent individual IDs
1249+
// @param parents integer vector with parent individual IDs (0-based)
12501250
// (can be \code{NULL}).
12511251
// @param metadata raw vector with metadata bytes
12521252
// (can be \code{NULL}).
12531253
// @details This function calls
12541254
// \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.tsk_individual_table_add_row}
12551255
// on the individuals table of \code{tc}.
1256-
// @return The 0-based row ID of the newly added individual.
1256+
// @return The row ID (0-based) of the newly added individual.
12571257
// @examples
12581258
// ts_file <- system.file("examples/test.trees", package = "RcppTskit")
12591259
// tc_xptr <- RcppTskit:::rtsk_table_collection_load(ts_file)
12601260
// n_before <- RcppTskit:::rtsk_table_collection_get_num_individuals(tc_xptr)
1261+
// m_before
1262+
// <- RcppTskit:::rtsk_table_collection_metadata_length(tc_xptr)$individuals
12611263
// tc_py <- RcppTskit:::rtsk_table_collection_r_to_py(tc_xptr)
12621264
// tc_py$individuals$max_rows
12631265
// tc_py$individuals["flags"]
@@ -1279,8 +1281,13 @@ Rcpp::List rtsk_table_collection_metadata_length(const SEXP tc) {
12791281
// new_id <- RcppTskit:::rtsk_individual_table_add_row(tc = tc_xptr, flags = 3L,
12801282
// location = c(2, 11), parents = c(1L, 3L), metadata = charToRaw("abc"))
12811283
// n_after <- RcppTskit:::rtsk_table_collection_get_num_individuals(tc_xptr)
1282-
// new_id == as.integer(n_before) && n_after == n_before + 3L
1283-
// tc_py <- RcppTskit:::rtsk_table_collection_r_to_py(tc_xptr)
1284+
// m_after <-
1285+
// RcppTskit:::rtsk_table_collection_metadata_length(tc_xptr)$individuals
1286+
// new_id == n_after - 1L
1287+
// n_after == n_before + 3L
1288+
// m_after == m_before + 3L
1289+
// tc_py <-
1290+
// RcppTskit:::rtsk_table_collection_r_to_py(tc_xptr)
12841291
// tc_py$individuals$max_rows
12851292
// tc_py$individuals["flags"]
12861293
// tc_py$individuals["location"]
@@ -1340,18 +1347,21 @@ int rtsk_individual_table_add_row(
13401347
// \code{tsk_table_collection_t} object.
13411348
// @param flags passed to \code{tskit C}.
13421349
// @param time numeric time value for the new node.
1343-
// @param population integer population row ID (0-based, or \code{-1}).
1344-
// @param individual integer individual row ID (0-based, or \code{-1}).
1350+
// @param population integer population row ID (0-based);
1351+
// use \code{-1} if not known.
1352+
// @param individual integer individual row ID (0-based);
1353+
// use \code{-1} if not known.
13451354
// @param metadata raw vector with metadata bytes
13461355
// (can be \code{NULL}).
13471356
// @details This function calls
13481357
// \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.tsk_node_table_add_row}
13491358
// on the nodes table of \code{tc}.
1350-
// @return The 0-based row ID of the newly added node.
1359+
// @return The row ID (0-based) of the newly added node.
13511360
// @examples
13521361
// ts_file <- system.file("examples/test.trees", package = "RcppTskit")
13531362
// tc_xptr <- RcppTskit:::rtsk_table_collection_load(ts_file)
13541363
// n_before <- RcppTskit:::rtsk_table_collection_get_num_nodes(tc_xptr)
1364+
// m_before <- RcppTskit:::rtsk_table_collection_metadata_length(tc_xptr)$nodes
13551365
// tc_py <- RcppTskit:::rtsk_table_collection_r_to_py(tc_xptr)
13561366
// tc_py$nodes$max_rows
13571367
// tc_py$nodes["flags"]
@@ -1370,7 +1380,10 @@ int rtsk_individual_table_add_row(
13701380
// metadata = charToRaw("abc")
13711381
// )
13721382
// n_after <- RcppTskit:::rtsk_table_collection_get_num_nodes(tc_xptr)
1373-
// new_id == as.integer(n_before) && n_after == n_before + 3L
1383+
// m_after <- RcppTskit:::rtsk_table_collection_metadata_length(tc_xptr)$nodes
1384+
// new_id == n_after - 1L
1385+
// n_after == n_before + 4L
1386+
// m_after == m_before + 3L
13741387
// tc_py <- RcppTskit:::rtsk_table_collection_r_to_py(tc_xptr)
13751388
// tc_py$nodes$max_rows
13761389
// tc_py$nodes["flags"]
@@ -1428,27 +1441,29 @@ int rtsk_node_table_add_row(
14281441
// @details This function calls
14291442
// \url{https://tskit.dev/tskit/docs/stable/c-api.html#c.tsk_edge_table_add_row}
14301443
// on the edges table of \code{tc}.
1431-
// @return The 0-based row ID of the newly added edge.
1444+
// @return The row ID (0-based) of the newly added edge.
14321445
// @examples
14331446
// ts_file <- system.file("examples/test.trees", package = "RcppTskit")
14341447
// tc_xptr <- RcppTskit:::rtsk_table_collection_load(ts_file)
1435-
// parent <- 0L
1436-
// child <- 1L
1448+
// child <- rtsk_node_table_add_row(tc_xptr, time = 0.0)
14371449
// n_before <- RcppTskit:::rtsk_table_collection_get_num_edges(tc_xptr)
1438-
// m_before <-
1439-
// RcppTskit:::rtsk_table_collection_metadata_length(tc_xptr)[["edges"]] new_id
1440-
// <- RcppTskit:::rtsk_edge_table_add_row(
1441-
// tc = tc_xptr, left = 0, right = 1, parent = parent, child = child
1450+
// m_before <- RcppTskit:::rtsk_table_collection_metadata_length(tc_xptr)$edges
1451+
// new_id <- RcppTskit:::rtsk_edge_table_add_row(
1452+
// tc = tc_xptr, left = 0, right = 50, parent = 16L, child = child
14421453
// )
14431454
// new_id <- RcppTskit:::rtsk_edge_table_add_row(
1444-
// tc = tc_xptr, left = 1, right = 2, parent = parent, child = child,
1445-
// metadata = charToRaw("abc")
1455+
// tc = tc_xptr, left = 50, right = 75, parent = 17L, child = child,
1456+
// metadata = "abc"
1457+
// )
1458+
// new_id <- RcppTskit:::rtsk_edge_table_add_row(
1459+
// tc = tc_xptr, left = 75, right = 100, parent = 18L, child = child,
1460+
// metadata = charToRaw("cba")
14461461
// )
14471462
// n_after <- RcppTskit:::rtsk_table_collection_get_num_edges(tc_xptr)
1448-
// m_after <-
1449-
// RcppTskit:::rtsk_table_collection_metadata_length(tc_xptr)[["edges"]] new_id
1450-
// == as.integer(n_before) && n_after == n_before + 2L && m_after == m_before +
1451-
// 3L
1463+
// m_after <- RcppTskit:::rtsk_table_collection_metadata_length(tc_xptr)$edges
1464+
// new_id == n_after - 1L
1465+
// n_after == n_before + 3L
1466+
// m_after == m_before + 3L
14521467
// [[Rcpp::export]]
14531468
int rtsk_edge_table_add_row(
14541469
const SEXP tc, const double left, const double right, const int parent,

0 commit comments

Comments
 (0)