@@ -138,6 +138,31 @@ TableCollection <- R6Class(
138138 rtsk_table_collection_get_num_provenances(self $ xptr )
139139 },
140140
141+ # ' @description Add a row to the provenances table.
142+ # ' @param timestamp character string timestamp for the new provenance.
143+ # ' @param record character string record for the new provenance.
144+ # ' @details See the \code{tskit Python} equivalent at
145+ # ' \url{https://tskit.dev/tskit/docs/stable/python-api.html#tskit.ProvenanceTable.add_row}.
146+ # ' @return An integer row index and hence ID (0-based) of the newly added provenance.
147+ # ' @examples
148+ # ' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
149+ # ' tc <- tc_load(ts_file)
150+ # ' (n_before <- tc$num_provenances())
151+ # ' new_id <- tc$provenance_table_add_row(
152+ # ' timestamp = "2025-01-01T00:00:00Z",
153+ # ' record = "{\"software\":\"RcppTskit\"}"
154+ # ' )
155+ # ' (n_after <- tc$num_provenances())
156+ provenance_table_add_row = function (timestamp , record ) {
157+ validate_character_scalar_arg(timestamp , " timestamp" )
158+ validate_character_scalar_arg(record , " record" )
159+ rtsk_provenance_table_add_row(
160+ tc = self $ xptr ,
161+ timestamp = as.character(timestamp ),
162+ record = as.character(record )
163+ )
164+ },
165+
141166 # ' @description Get the number of populations in a table collection.
142167 # ' @return A signed 64 bit integer \code{bit64::integer64}.
143168 # ' @examples
@@ -148,6 +173,28 @@ TableCollection <- R6Class(
148173 rtsk_table_collection_get_num_populations(self $ xptr )
149174 },
150175
176+ # ' @description Add a row to the populations table.
177+ # ' @param metadata for the new population; accepts \code{NULL},
178+ # ' a raw vector, or a character of length 1.
179+ # ' @details See the \code{tskit Python} equivalent at
180+ # ' \url{https://tskit.dev/tskit/docs/stable/python-api.html#tskit.PopulationTable.add_row}.
181+ # ' @return An integer row index and hence ID (0-based) of the newly added population.
182+ # ' @examples
183+ # ' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
184+ # ' tc <- tc_load(ts_file)
185+ # ' (n_before <- tc$num_populations())
186+ # ' new_id <- tc$population_table_add_row()
187+ # ' new_id <- tc$population_table_add_row(metadata = "abc")
188+ # ' new_id <- tc$population_table_add_row(metadata = charToRaw("xyz"))
189+ # ' (n_after <- tc$num_populations())
190+ population_table_add_row = function (metadata = NULL ) {
191+ metadata_raw <- validate_metadata_arg(metadata )
192+ rtsk_population_table_add_row(
193+ tc = self $ xptr ,
194+ metadata = metadata_raw
195+ )
196+ },
197+
151198 # ' @description Get the number of migrations in a table collection.
152199 # ' @return A signed 64 bit integer \code{bit64::integer64}.
153200 # ' @examples
@@ -158,6 +205,71 @@ TableCollection <- R6Class(
158205 rtsk_table_collection_get_num_migrations(self $ xptr )
159206 },
160207
208+ # ' @description Add a row to the migrations table.
209+ # ' @param left numeric scalar left coordinate for the new migration.
210+ # ' @param right numeric scalar right coordinate for the new migration.
211+ # ' @param node integer scalar node ID (0-based).
212+ # ' @param source integer scalar source population ID (0-based).
213+ # ' @param dest integer scalar destination population ID (0-based).
214+ # ' @param time numeric scalar time value for the new migration.
215+ # ' @param metadata for the new migration; accepts \code{NULL},
216+ # ' a raw vector, or a character of length 1.
217+ # ' @details See the \code{tskit Python} equivalent at
218+ # ' \url{https://tskit.dev/tskit/docs/stable/python-api.html#tskit.MigrationTable.add_row}.
219+ # ' @return An integer row index and hence ID (0-based) of the newly added migration.
220+ # ' @examples
221+ # ' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
222+ # ' tc <- tc_load(ts_file)
223+ # ' (n_before <- tc$num_migrations())
224+ # ' new_id <- tc$migration_table_add_row(
225+ # ' left = 0,
226+ # ' right = 1,
227+ # ' node = 0L,
228+ # ' source = 0L,
229+ # ' dest = 0L,
230+ # ' time = 1.0
231+ # ' )
232+ # ' new_id <- tc$migration_table_add_row(
233+ # ' left = 1,
234+ # ' right = 2,
235+ # ' node = 1L,
236+ # ' source = 0L,
237+ # ' dest = 0L,
238+ # ' time = 2.0,
239+ # ' metadata = "abc"
240+ # ' )
241+ # ' (n_after <- tc$num_migrations())
242+ migration_table_add_row = function (
243+ left ,
244+ right ,
245+ node ,
246+ source ,
247+ dest ,
248+ time ,
249+ metadata = NULL
250+ ) {
251+ validate_numeric_scalar_arg(left , " left" )
252+ validate_numeric_scalar_arg(right , " right" )
253+ if (as.numeric(left ) > = as.numeric(right )) {
254+ stop(" left must be strictly less than right!" )
255+ }
256+ validate_row_index(node , " node" )
257+ validate_row_index(source , " source" )
258+ validate_row_index(dest , " dest" )
259+ validate_numeric_scalar_arg(time , " time" )
260+ metadata_raw <- validate_metadata_arg(metadata )
261+ rtsk_migration_table_add_row(
262+ tc = self $ xptr ,
263+ left = as.numeric(left ),
264+ right = as.numeric(right ),
265+ node = as.integer(node ),
266+ source = as.integer(source ),
267+ dest = as.integer(dest ),
268+ time = as.numeric(time ),
269+ metadata = metadata_raw
270+ )
271+ },
272+
161273 # ' @description Get the number of individuals in a table collection.
162274 # ' @return A signed 64 bit integer \code{bit64::integer64}.
163275 # ' @examples
0 commit comments