Reads, aggregates, and processes the SQLite database
(data/geelite.db
).
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
)
A list where the first element (grid
) is a simple feature
(sf) object, and subsequent elements are data frame objects corresponding
to the variables.
[mandatory] (character) Path to the root directory of the generated database.
[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"
).
[optional] (character) The frequency for data aggregation.
Options include "day"
, "week"
, "month"
,
"bimonth"
, "quarter"
, "season"
, "halfyear"
,
"year"
(default: "month"
).
[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.
[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)
.
[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.
# 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