Update Grist table with new data, updating existing rows or adding new ones, matching rows on the given key columns. (This method does not remove rows from Grist.)
sync_table(api, table_id, new_data, key_cols)
TRUE
if the transaction was sucessfull.
Other function_gristapi:
add_records()
,
countrows()
,
delete_records()
,
fetch_table()
,
listcolumns()
,
listtables()
,
update_records()
# Synchronize the table with a dataframe (update or add) on unique key
library(dplyr)
table_name <- paste0("Mtcars_", get_os())
api <- grist_api$new(
server = 'https://grist.numerique.gouv.fr',
api_key = Sys.getenv("GRIST_KEY"),
doc_id = Sys.getenv("GRIST_DOC_TEST")
)
new_data <- fetch_table(api, table_name, filters = 'filter={"cyl": [8]}')
new_data <- new_data |>
mutate(carb = 4, names = ifelse(names == 'Camaro Z28', 'Camaro Z28 - custom', names))
new_data <- new_data |> select(-id)
# synchronization on the "names" key
sync_table(api, table_name, new_data, c("names"))
#> [1] TRUE