update_table: update_table

View source: R/update_table.R

update_tableR Documentation

update_table

Description

updates the data.table-like object to based on the data.frame-like from object, using date_column to determine which rows have been updated and updating only those with matching primary_keys.

Usage

update_table(
  from,
  to,
  date_column = NULL,
  primary_keys = NULL,
  delete = FALSE,
  incremental = TRUE,
  ...
)

## Default S3 method:
update_table(
  from,
  to,
  date_column = NULL,
  primary_keys = NULL,
  delete = FALSE,
  incremental = TRUE,
  ...
)

## S3 method for class 'data.table'
update_table(
  from,
  to,
  date_column = NULL,
  primary_keys = NULL,
  delete = FALSE,
  incremental = TRUE,
  ...
)

update_table_date_only(from, to, date_column = NULL, prefer = "to")

## S3 method for class 'data.table'
update_table_date_only(from, to, date_column = NULL, prefer = "to")

## Default S3 method:
update_table_date_only(from, to, date_column = NULL, prefer = "to")

Arguments

from

the source object

to

the object to be updated

date_column

string or tidy-selected column identifying the date column to use to determine which rows to update

primary_keys

vector of strings or tidy-selected columns identifying the primary keys to determine which rows to update

delete

whether to delete rows in to missing from from, default is not to delete the rows

incremental

whether or not to update the table incrementally or to simply overwrite the existing table with a new one, the default is TRUE

...

Arguments passed on to update_table_date_only

prefer

"from" or "to": which table to prefer on conflict during a date-only update. The default is to prefer the destination table, so that existing data in to is not overwritten.

Value

a data.table updated in-place

Functions

  • update_table_date_only(): update incrementally when primary_keys not given but date_column given

  • update_table_date_only(data.table): update incrementally when primary_keys not given but date_column given

  • update_table_date_only(default): update incrementally when primary_keys not given but date_column given

Examples

library(data.table)
expect <- data.table(expand.grid(x = 1:100, y = 1:100))[, data := runif(.N)]
# divide the data
from <- copy(expect)[1:9000]
to <- copy(expect)[1000:10000]
# and mung it up
to[1:5000, data := runif(.N)]

update_table(from, to, primary_keys = c(x, y)) == expect
# TRUE



skysyzygy/tessilake documentation built on June 14, 2025, 6:50 p.m.