| Title: | SDM Evaluation Tool Core Functions |
|---|---|
| Description: | The goal of sdmEvalToolCore is to implement the data model and common non-interactive functionality for the SDM Evaluation Tool packages. |
| Authors: | Peter Solymos [aut, cre] (ORCID: <https://orcid.org/0000-0001-7337-1740>), Steffi LaZerte [aut] (ORCID: <https://orcid.org/0000-0002-7690-8360>), Analythium Solutions Inc. [cph], His Majesty the King in Right of Canada as represented by the Minister of the Environment [cph] (Copyright holder for default evaluation/drill down questions.), Biodiversity Pathways [cph] (Copyright holder for glossary.csv, and default evaluation/drill down questions.), Alberta Biodiversity Monitoring Institute [cph] (Copyright holder for glossary.csv, and default evaluation/drill down questions.) |
| Maintainer: | Peter Solymos <[email protected]> |
| License: | Apache License 2.0 |
| Version: | 0.0.1 |
| Built: | 2026-10-01 07:39:48 UTC |
| Source: | https://github.com/LandSciTech/sdmEvaluationTool |
Check Table
check_table(x, table_name, dryrun = FALSE)check_table(x, table_name, dryrun = FALSE)
x |
A data frame. |
table_name |
Table name. |
dryrun |
Logical, if checks fail and error is produced, unless it is a dry run. |
Invisible TRUE if all check passed.
users <- data.frame( user_id = c("holden", "draper", "okoye"), user_name = c("James Holden", "Bobbie Draper", "Elvi Okoye"), user_email = c( "[email protected]", "[email protected]", "[email protected]" ), user_affiliation = c("Rocinante", "MCRN", "RCE"), admin = c(TRUE, FALSE, FALSE), password = c("pass1", "pass2", "pass3") ) check_table(users, "users") models <- data.frame( model_id = "bam_v5_can71", model_name = "BAM v5 Can 71", model_description = "BAM version 5 Canada model in BCR 71" ) check_table(models, "models") check_table(models, "users", dryrun = TRUE)users <- data.frame( user_id = c("holden", "draper", "okoye"), user_name = c("James Holden", "Bobbie Draper", "Elvi Okoye"), user_email = c( "[email protected]", "[email protected]", "[email protected]" ), user_affiliation = c("Rocinante", "MCRN", "RCE"), admin = c(TRUE, FALSE, FALSE), password = c("pass1", "pass2", "pass3") ) check_table(users, "users") models <- data.frame( model_id = "bam_v5_can71", model_name = "BAM v5 Can 71", model_description = "BAM version 5 Canada model in BCR 71" ) check_table(models, "models") check_table(models, "users", dryrun = TRUE)
Join questions and follow-ups
combine_questions(q)combine_questions(q)
q |
A data frame with questions. |
q <- sdmEvalToolCore::default_questions q$followup_level[5] <- 3 combine_questions(q)q <- sdmEvalToolCore::default_questions q$followup_level[5] <- 3 combine_questions(q)
Components
componentscomponents
A data frame with component configuration (some columns are lists).
Connect to Database
db_connect(dbname = NULL, ...)db_connect(dbname = NULL, ...)
dbname |
DB name. |
... |
Arguments passed to |
A database connection.
Create DB tables
db_create_tables(con, tables = NULL, force = FALSE)db_create_tables(con, tables = NULL, force = FALSE)
con |
DB connection. |
tables |
Character, table name. |
force |
Logical, force (create even if not exists). |
con <- db_connect(":memory:") db_create_tables(con, "models") db_create_tables(con) db_disconnect(con)con <- db_connect(":memory:") db_create_tables(con, "models") db_create_tables(con) db_disconnect(con)
Disconnect from Database
db_disconnect(con, ...)db_disconnect(con, ...)
con |
DB connection. |
... |
Arguments passed to |
Path to Database
db_path()db_path()
Path to default database
Get Comments from DB
db_read_comments(con, deployment_id)db_read_comments(con, deployment_id)
con |
DB connection. |
deployment_id |
Deployment ID. |
A data frame with comments for the deployment.
Get Deployment Materials from DB
db_read_deployment_materials(con, deployment_id = NULL, user_id = NULL)db_read_deployment_materials(con, deployment_id = NULL, user_id = NULL)
con |
DB connection. |
deployment_id |
Deployment IDs (multiple permitted). |
user_id |
User ID. |
A data frame with joined deployment materials.
Get Evaluations from DB
db_read_evaluations(con, deployment_id = NULL, user_id = NULL)db_read_evaluations(con, deployment_id = NULL, user_id = NULL)
con |
DB connection. |
deployment_id |
Deployment ID. |
user_id |
Evaluation create user IDs (multiple allowed). |
A data frame with evaluations for the deployment.
Get models from DB
db_read_models(con, model_id = NULL)db_read_models(con, model_id = NULL)
con |
DB connection. |
model_id |
Model ID (optional). |
A data frame with models. Optionally filtered to model_id.
Get species from DB
db_read_species(con, species_id = NULL)db_read_species(con, species_id = NULL)
con |
DB connection. |
species_id |
Species ID (optional). |
A data frame with species and display names. Optionally filtered to species_id.
Get Table from DB
db_read_table(con, table_name)db_read_table(con, table_name)
con |
DB connection. |
table_name |
Table name. |
A data frame with the table data.
Get User Info from DB
db_read_user_info(con, user_id, deployment_id)db_read_user_info(con, user_id, deployment_id)
con |
DB connection. |
user_id |
User ID. |
deployment_id |
Deployment ID. |
A data frame with user info and access roles.
The "user_roles" attribute gives the user roles as a vector.
Data will be inserted/updated/upserted in an existing DB table.
db_write_table( con, table, data, mode = c("insert", "update", "upsert"), check = TRUE, dryrun = FALSE )db_write_table( con, table, data, mode = c("insert", "update", "upsert"), check = TRUE, dryrun = FALSE )
con |
A database connection. |
table |
Table name. |
data |
Data frame to append to the DB table. |
mode |
How to execute the write operation: insert (append) new record, update existing record, or upsert (update existing or insert if not). |
check |
Logical, should |
dryrun |
Logical, write to a text file when |
Invisible TRUE.
con <- db_connect(":memory:") db_create_tables(con, "models") models <- data.frame( model_id = "bam_v5_can71", model_name = "BAM v5 Can 71", model_description = "BAM version 5 Canada model in BCR 71" ) db_write_table(con, "models", models, mode = "insert") db_disconnect(con)con <- db_connect(":memory:") db_create_tables(con, "models") models <- data.frame( model_id = "bam_v5_can71", model_name = "BAM v5 Can 71", model_description = "BAM version 5 Canada model in BCR 71" ) db_write_table(con, "models", models, mode = "insert") db_disconnect(con)
Default Questions
default_questionsdefault_questions
A data frame with default questions.
Default Species Table
default_species_table_canada()default_species_table_canada()
Data frame.
str(default_species_table_canada())str(default_species_table_canada())
Fake DB Entries
fake_comment(deployment_id, model_id, species_id, user_id, time = NULL) fake_evaluation( deployment_id, material_id, component_id, user_id, questions = NULL, time = NULL ) fake_response(question)fake_comment(deployment_id, model_id, species_id, user_id, time = NULL) fake_evaluation( deployment_id, material_id, component_id, user_id, questions = NULL, time = NULL ) fake_response(question)
deployment_id |
Deployment ID. |
model_id |
Model ID. |
species_id |
Species ID. |
user_id |
User ID. |
time |
Date-time. |
material_id |
Material ID. |
component_id |
Component ID. |
questions |
A questions data frame. |
question |
A questions data frame with a single row. |
fake_comment( deployment_id = "deployment1", model_id = "model1", species_id = "MOTR", user_id = "draper") str(fake_response(sdmEvalToolCore::default_questions[1,])) fake_evaluation( deployment_id = "deployment1", material_id = "material1", component_id = "model_fit", user_id = "draper")fake_comment( deployment_id = "deployment1", model_id = "model1", species_id = "MOTR", user_id = "draper") str(fake_response(sdmEvalToolCore::default_questions[1,])) fake_evaluation( deployment_id = "deployment1", material_id = "material1", component_id = "model_fit", user_id = "draper")
Follow-up Questions
followup_questionsfollowup_questions
A data frame with follow-up questions.
Handling Boolean
fromBoolean(x)fromBoolean(x)
x |
An R vector. |
Generate password
generate_password(length = 12, start_with_letter = TRUE)generate_password(length = 12, start_with_letter = TRUE)
length |
Length of the password. Default is 12. |
start_with_letter |
Logical indicating if the password should start with a letter. Default is TRUE. |
A randomly generated password.
generate_password()generate_password()
Which Components Are Ready
get_comp_ready(ready = character(0L))get_comp_ready(ready = character(0L))
ready |
Character, component names that are ready. |
A data frame with components and a column telling which ones are ready.
The "percent_ready" attribute gives a percentage value of the
mandatory components that are ready.
r <- get_comp_ready(c("observations", "model_metadata")) r attr(r, "percent_ready")r <- get_comp_ready(c("observations", "model_metadata")) r attr(r, "percent_ready")
Get Rule for a Component
get_comp_rule(component_id, rule_type = c("upload", "display", "evaluation"))get_comp_rule(component_id, rule_type = c("upload", "display", "evaluation"))
component_id |
Character, component name (length 1). |
rule_type |
CHaracter, the type of rule. |
A list with the rules, or NULL.
str(get_comp_rule("observations", "upload")) str(get_comp_rule("observations", "evaluation"))str(get_comp_rule("observations", "upload")) str(get_comp_rule("observations", "evaluation"))
Get Table Fields
get_fields(table_name)get_fields(table_name)
table_name |
Table name. |
A data frame.
get_fields("users") get_fields("components")get_fields("users") get_fields("components")
Get File Extension
get_file_ext(path)get_file_ext(path)
path |
Character, a file path. |
Lower case file extension as string.
get_file_ext("bam_v5/oven/observations.parquet")get_file_ext("bam_v5/oven/observations.parquet")
Get User Roles
get_user_roles(role)get_user_roles(role)
role |
Character, 1 or multiple user roles. |
A data frame with the permissible user actions (TRUE/FALSE).
str(get_user_roles(c("modeler"))) str(get_user_roles(c("evaluator"))) str(get_user_roles(c("evaluator", "modeler")))str(get_user_roles(c("modeler"))) str(get_user_roles(c("evaluator"))) str(get_user_roles(c("evaluator", "modeler")))
Make Directory
make_dir(path, ...)make_dir(path, ...)
path |
Character, a file path. |
... |
Arguments passed to |
Create a directory recursively as a side effect, returning logical indicating the result ().
Make Material ID
make_material_id(model_id, species_id, component_id, sep = "_")make_material_id(model_id, species_id, component_id, sep = "_")
model_id |
Model ID. |
species_id |
Species ID. |
component_id |
Component ID. |
sep |
Character. Separator. |
make_material_id("model1", NA, "predictor_metadata") make_material_id("model1", "CAWA", "predictor_raster")make_material_id("model1", NA, "predictor_metadata") make_material_id("model1", "CAWA", "predictor_raster")
Make Target Path
make_target_path(path, data = list(), base = NULL)make_target_path(path, data = list(), base = NULL)
path |
Character, a file path. |
data |
List with name value pairs, the values are substituted into the path according to glue rules (with curly braces). |
base |
Character, base path, defaults to |
The path string with data values substituted.
make_target_path("bam_v5/oven/observations.parquet") make_target_path("{model}/{species}/observations.parquet", list(model = "bam_v5", species = "oven")) make_target_path("{model}/{species}/observations.parquet", list(model = "bam_v5", species = "oven"), ".")make_target_path("bam_v5/oven/observations.parquet") make_target_path("{model}/{species}/observations.parquet", list(model = "bam_v5", species = "oven")) make_target_path("{model}/{species}/observations.parquet", list(model = "bam_v5", species = "oven"), ".")
Make user database suitable for shinymanager
make_user_db()make_user_db()
A data frame with user credentials.
Prepare Material Entry
prepare_material_entry( model_id, species_id, component_id, user_id, material_settings = "[]" )prepare_material_entry( model_id, species_id, component_id, user_id, material_settings = "[]" )
model_id |
Model ID. |
species_id |
Species ID. |
component_id |
Component ID. |
user_id |
User ID. |
material_settings |
Material settings. |
prepare_material_entry("model1", "CAWA", "predictor_raster", "testuser")prepare_material_entry("model1", "CAWA", "predictor_raster", "testuser")
Read File
read_file(path, ...)read_file(path, ...)
path |
Character, a file path. |
... |
Arguments passed to the reader functions. |
Return the result from the file.
Scaffold Table
scaffold_table(table_name)scaffold_table(table_name)
table_name |
Table name. |
A data frame returned invisibly, called for the printed side effects.
scaffold_table("users") scaffold_table("materials")scaffold_table("users") scaffold_table("materials")
Package Options
sdmevaltool_options(...)sdmevaltool_options(...)
... |
Names list of options. |
(sdmevaltool_options())(sdmevaltool_options())
Handling Timestamps
timestamp_from(ms, tz = NULL, ...) timestamp_to(dt) now()timestamp_from(ms, tz = NULL, ...) timestamp_to(dt) now()
ms |
Unix time in seconds. |
tz |
Time zone, when |
... |
Other optional arguments passed to |
dt |
POSIXct coercible date/time value. |
timestamp_from returns POSIXct().
timestamp_to returns Unix time as character .
sdmevaltool_options() to set tz globally.
dt1 <- now() timestamp_to(dt1) timestamp_from(timestamp_to(dt1))dt1 <- now() timestamp_to(dt1) timestamp_from(timestamp_to(dt1))
Write File and Insert/Update Material DB Entry
upload_material( component_id, x, model_id, species_id, user_id, deployment_id = NULL, material_settings = NULL, con = NULL, update = FALSE, ... )upload_material( component_id, x, model_id, species_id, user_id, deployment_id = NULL, material_settings = NULL, con = NULL, update = FALSE, ... )
component_id |
Component ID. |
x |
Object. |
model_id |
Model ID. |
species_id |
Species ID. |
user_id |
User ID. |
deployment_id |
Deployment ID. |
material_settings |
List with the material settings. |
con |
Database connection (use |
update |
Logical. Is this a new entry ( |
... |
Arguments passed to the write function. |
Prepare Deployment Materials
prep_deployment_questions(deployment_id, x = NULL, ...) prep_deployment_settings(deployment_id, x, ...) prep_deployment_subunits( deployment_id, x = NULL, reference_raster, reference_points, n = c(20, 20), square = TRUE, ... )prep_deployment_questions(deployment_id, x = NULL, ...) prep_deployment_settings(deployment_id, x, ...) prep_deployment_subunits( deployment_id, x = NULL, reference_raster, reference_points, n = c(20, 20), square = TRUE, ... )
deployment_id |
Deployment ID. |
x |
An object to upload. |
... |
Arguments passed to the write function. |
reference_raster |
Reference raster layer. |
reference_points |
Reference spatial points object. |
n |
Number of grid cells in x and y direction. |
square |
Logical. If 'FALSEā, create hexagonal grid. |
Prepare Upload Materials
prep_predictor_raster( x, resolution = 5, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_predictor_metadata( x, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_model_metadata( x, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_spatial_prediction( x, model_id, species_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_observations( x, species, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_model_summary( x, species, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_model_fit( x, species, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... )prep_predictor_raster( x, resolution = 5, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_predictor_metadata( x, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_model_metadata( x, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_spatial_prediction( x, model_id, species_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_observations( x, species, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_model_summary( x, species, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... ) prep_model_fit( x, species, model_id, user_id, material_settings = NULL, con = NULL, update = FALSE, ... )
x |
An object to upload. |
resolution |
Raster resampling resolution |
model_id |
Model ID. |
user_id |
User ID. |
material_settings |
Material settings. |
con |
Database connection (use |
update |
Logical. Is this a new entry or an update to an existing one. |
... |
Arguments passed to the write function. |
species_id |
Species ID. |
species |
Reference species table. |
Write File
write_file(x, path, ...)write_file(x, path, ...)
x |
Object to write. |
path |
Character, a file path. |
... |
Arguments passed to the writer functions. |
Writes file as a side effect.