Learn R Programming

geeLite (version 1.0.2)

read_db: Reading, Aggregating, and Processing the SQLite Database

Description

Reads, aggregates, and processes the SQLite database (data/geelite.db).

Usage

read_db(
  path,
  variables = "all",
  freq = c("month", "day", "week", "bimonth", "quarter", "season", "halfyear", "year"),
  prep_fun = NULL,
  aggr_funs = function(x) mean(x, na.rm = TRUE),
  postp_funs = NULL
)

Value

A list where the first element (grid) is a simple feature (sf) object, and subsequent elements are data frame objects corresponding to the variables.

Arguments

path

[mandatory] (character) Path to the root directory of the generated database.

variables

[optional] (character or integer) Names or IDs of the variables to be read. Use the fetch_vars function to identify available variables and IDs (default: "all").

freq

[optional] (character) The frequency for data aggregation. Options include "day", "week", "month", "bimonth", "quarter", "season", "halfyear", "year" (default: "month").

prep_fun

[optional] (function or NULL) A function for pre-processing time series data prior to aggregation. If NULL, a default linear interpolation (via linear_interp) will be used for daily-frequency data. If non-daily, the default behavior simply returns the vector without interpolation.

aggr_funs

[optional] (function or list) A function or a list of functions for aggregating data to the specified frequency (freq). Users can directly refer to variable names or IDs. The default function is the mean: function(x) mean(x, na.rm = TRUE).

postp_funs

[optional] (function or list) A function or list of functions applied to the time series data of a single bin after aggregation. Users can directly refer to variable names or IDs. The default is NULL, indicating no post-processing.

Examples

Run this code
# Example: Reading variables by IDs
if (FALSE) {
  db_list <- read_db(path = "path/to/db",
    variables = c(1, 3))
}

Run the code above in your browser using DataLab