R/save_results_access.R
save_results_access.Rd
This function saves the results from calculations in the forrescalc package (or any other named list with dataframes) in an Access database. List item names will be used to name each of the tables, which contain as a content the different dataframes.
save_results_access(results, database, remove_tables = FALSE)
results from calculations in package forrescalc as a named list
name of (empty) Access database including path in which results should be saved
overwrite existing tables in database? Default is FALSE, which means tables are not overwritten/deleted unless this parameter is explicitly put on TRUE.
No value is returned, data are saved in the specified database
library(forrescalc)
# (add path to your own fieldmap database here)
path_to_fieldmapdb <-
system.file("example/database/mdb_bosres.sqlite", package = "forrescalc")
# do calculations
data_dendro <- load_data_dendrometry(path_to_fieldmapdb)
data_deadwood <- load_data_deadwood(path_to_fieldmapdb)
data_shoots <- load_data_shoots(path_to_fieldmapdb)
# omit argument 'example_dataset = TRUE' below to use all height models
height_model <- load_height_models(example_dataset = TRUE)
plotinfo <- load_plotinfo(path_to_fieldmapdb)
#> Joining with `by = join_by(forest_reserve, plot_id, plottype, survey_trees)`
result_dendro <-
calculate_dendrometry(
data_dendro, data_deadwood, data_shoots, height_model, plotinfo)
# save the results
save_results_access(result = result_dendro, database = path_to_fieldmapdb)
# Repeating the previous line of code will give an error, because you try to
# overwrite a table that was already saved in the database on the first run.
# To overwrite previously saved tables, use this command:
save_results_access(
result = result_dendro, database = path_to_fieldmapdb, remove_tables = TRUE
)
# To remove the tables again in the example database (undo the changes),
# use this code:
con <- forrescalc:::connect_to_database(path_to_fieldmapdb)
for (tablename in names(result_dendro)) {
DBI::dbRemoveTable(con, tablename)
}
DBI::dbDisconnect(con)