dbOut_update_values: Update values of dbOutput based on a new database

Description Usage Arguments Value Examples

View source: R/OutputDatabase.R

Description

Update values of dbOutput based on a new database

Usage

1
2
3
4
5
6
7
dbOut_update_values(
  dbOut_fname,
  dbNew_fname,
  fields_update = NULL,
  fields_exclude = NULL,
  verbose = FALSE
)

Arguments

dbOut_fname

A character string. The file path of the main dbOutput that is to be updated.

dbNew_fname

A character string. The file path of a database with new values that are used to update corresponding values in dbOutput.

fields_update

A named list of vectors with character strings. The field names per table to be updated. Each table is represented by a correspondingly named element. If NULL, then all output tables, according to dbOutput_ListOutputTables, and all fields (except for ID-fields, i.e., P_id and Soil_Layer) are updated.

fields_exclude

A named list of vectors with character strings. The field names per table to be updated. Each table is represented by a correspondingly named element. If NULL, then no fields are excluded from the update operation.

verbose

A logical value.

Value

Invisibly, the name of a new table that tracks which records (identified by P_id) have been updated (value 1) for each table.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
if (requireNamespace("RSQLite") && exists("SFSW2_prj_meta")) {
  table <- dbOut_update_values(
    dbOut_fname = SFSW2_prj_meta[["fnames_out"]][["dbOutput"]],
    dbNew_fname = "path/to/new.sqlite3",
    fields_exclude = list(
      aggregation_overall_mean = c("MAT_C_mean", "MAP_mm_mean"),
      aggregation_overall_sd = c("MAT_C_sd", "MAP_mm_sd")))

  con <- RSQLite::dbConnect(RSQLite::SQLite(),
    SFSW2_prj_meta[["fnames_out"]][["dbOutput"]])
  fields <- RSQLite::dbQuoteIdentifier(con,
    RSQLite::dbListFields(con, table))

  # Extract Pids from records that were updated
  sql <- paste("SELECT P_id FROM", table, "WHERE",
    paste(fields[-1], "= 1", collapse = " AND "))
  is_good <- RSQLite::dbGetQuery(con, sql)

  RSQLite::dbDisconnect(con)
}
## End(Not run)

Burke-Lauenroth-Lab/rSFSW2 documentation built on Aug. 14, 2020, 5:20 p.m.