Title: | Auxiliary Functions to Update the n2kresult Database |
---|---|
Description: | The functions are useful to store the results from https:// github.com/inbo/n2kanalysis into a PostgreSQL database created with https:// github.com/inbo/n2kresult. |
Authors: | Thierry Onkelinx [aut, cre] , Instituut voor Natuur en Bosonderzoek (INBO) [cph] |
Maintainer: | Thierry Onkelinx <[email protected]> |
License: | GPL-3 |
Version: | 0.1.1 |
Built: | 2024-11-03 06:08:07 UTC |
Source: | https://github.com/inbo/n2kupdate |
Convert all factors in a data.frame to characters
character_df(x, ...)
character_df(x, ...)
x |
object to be coerced or tested. |
... |
further arguments passed to or from other methods. |
connect to the unit test database
connect_ut_db(host = "localhost", dbname = "n2kunittest", user = "unittest_analysis", password = "unittest", port = 5432)
connect_ut_db(host = "localhost", dbname = "n2kunittest", user = "unittest_analysis", password = "unittest", port = 5432)
host |
the hostname of the database. Defaults to "localhost". |
dbname |
the name of the unit test database. Defaults to "n2kunittest". |
user |
the name of the unit test user. Defaults to "unittest_analysis". |
password |
the password for the user. Defaults to "unittest". |
port |
The port of host. Defaults to 5432. |
store source species in the database
store_analysis(analysis, model_set, analysis_version, analysis_relation, conn, hash, clean = TRUE)
store_analysis(analysis, model_set, analysis_version, analysis_relation, conn, hash, clean = TRUE)
analysis |
a data.frame with file_fingerprint, model_set_local_id, location_group, species_group, last_year, seed, analysis_version, analysis_date, status and status_fingerprint. |
model_set |
a data.frame with the model sets. Must have variables "local_id", "description", "first_year", "last_year" and "duration". The variable "long_description" is optional. |
analysis_version |
an n2kAnalysisVersion object. See
|
analysis_relation |
an optional data.frame with analysis and source_analysis. analysis contains the file_fingerprint of the current analysis. source_analysis contains the file_fingerprint of the parent analysis |
conn |
a DBIconnection |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
store analysis and dataset in the database
store_analysis_dataset(analysis, model_set, analysis_version, dataset, analysis_dataset, clean = TRUE, hash, conn)
store_analysis_dataset(analysis, model_set, analysis_version, dataset, analysis_dataset, clean = TRUE, hash, conn)
analysis |
a data.frame with file_fingerprint, model_set_local_id, location_group, species_group, last_year, seed, analysis_version, analysis_date, status and status_fingerprint. |
model_set |
a data.frame with the model sets. Must have variables "local_id", "description", "first_year", "last_year" and "duration". The variable "long_description" is optional. |
analysis_version |
an n2kAnalysisVersion object. See
|
dataset |
a data.frame with names fingerprint, filename, datasource and import_date |
analysis_dataset |
A |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
hash |
the hash of the update session |
conn |
a DBIconnection |
Store the analysis version in the database
store_analysis_version(analysis_version, hash, clean = TRUE, conn)
store_analysis_version(analysis_version, hash, clean = TRUE, conn)
analysis_version |
an n2kAnalysisVersion object. See
|
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
conn |
a DBIconnection |
Store anomaly
store_anomaly(anomaly, anomaly_type, parameter, hash, conn, clean = TRUE)
store_anomaly(anomaly, anomaly_type, parameter, hash, conn, clean = TRUE)
anomaly |
a data.frame with variables "anomaly_type_local_id", "datafield", "analyis" and "parameter_local_id". |
anomaly_type |
a data.frame with variables "local_id", "description" and "long_description". "long_description" is optional |
parameter |
a data.frame with parameters. Must contains the variables "description", "local_id", and "parent_parameter_local_id". Other variables are ignored. |
hash |
the hash of the update session |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
Store anomaly types
store_anomaly_type(anomaly_type, hash, conn, clean = TRUE)
store_anomaly_type(anomaly_type, hash, conn, clean = TRUE)
anomaly_type |
a data.frame with variables "local_id", "description" and "long_description". "long_description" is optional |
hash |
the hash of the update session |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
store a datafield in the database
store_datafield(datafield, conn, hash, clean = TRUE)
store_datafield(datafield, conn, hash, clean = TRUE)
datafield |
a data.frame with datafield metadata. Must contain the variables local_id, datasource, table_name, primary_key and datafield_type. Other variables are ignored. |
conn |
a DBIconnection |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
Store a vector of datafield types
store_datafield_type(datafield_type, hash, conn, clean = TRUE)
store_datafield_type(datafield_type, hash, conn, clean = TRUE)
datafield_type |
the vector with datafield types. |
hash |
the hash of the update session |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
Store a dataset is the database
store_dataset(dataset, conn, clean = TRUE, hash)
store_dataset(dataset, conn, clean = TRUE, hash)
dataset |
a data.frame with names fingerprint, filename, datasource and import_date |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
hash |
the hash of the update session |
store a datasource in the database
store_datasource(datasource, conn, clean = TRUE, hash)
store_datasource(datasource, conn, clean = TRUE, hash)
datasource |
a data.frame with datasource metadata |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
hash |
the hash of the update session |
datasource must contain at least the variables description, datasource_type and connect_method.
Store a vector of datasource parameters
store_datasource_parameter(datasource_parameter, hash, conn, clean = TRUE)
store_datasource_parameter(datasource_parameter, hash, conn, clean = TRUE)
datasource_parameter |
the vector with datasource parameters. |
hash |
the hash of the update session |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
Store a vector of datasource types
store_datasource_type(datasource_type, hash, conn, clean = TRUE)
store_datasource_type(datasource_type, hash, conn, clean = TRUE)
datasource_type |
the vector with datasource types. |
hash |
the hash of the update session |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
Store language
store_language(language, hash, conn, clean = TRUE)
store_language(language, hash, conn, clean = TRUE)
language |
the data.frame with language Must contains code and description. Other variables are ignored. code and description must have unique values. |
hash |
the hash of the update session |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
store locations in the database
store_location(location, datafield, conn, hash, clean = TRUE)
store_location(location, datafield, conn, hash, clean = TRUE)
location |
a data.frame with location metadata. Must contain the following columns: local_id, description, parent_local_id, datafield_local_id and external_code. Other columns are ignored. |
datafield |
a data.frame with datafield metadata. Must contain the variables local_id, datasource, table_name, primary_key and datafield_type. Other variables are ignored. |
conn |
a DBIconnection |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
location must have variables local_id, description, parent_local_id, datafield_local_id and extranal_code. Other variables are ignored
datafield must have variables local_id, datasource, table_name, primary_key and datafield_type
all local_id variables must be unique within their data.frame
all values in location$datafield_local_id must exist in datafield$local_id
all values in location$parent_location must be either NA or exist in location$local_id
Store location groups
store_location_group(location_group, hash, conn, clean = TRUE)
store_location_group(location_group, hash, conn, clean = TRUE)
location_group |
the data.frame with location groups. Must contains local_id, description and scheme. Other variables are ignored. local_id must have unique values. |
hash |
the hash of the update session |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
store the link between locations and location groups in the database
store_location_group_location(location_group_location, location_group, location, datafield, conn, hash, clean = TRUE)
store_location_group_location(location_group_location, location_group, location, datafield, conn, hash, clean = TRUE)
location_group_location |
a data.frame with the locations per location group. Must contain location_group_local_id and location_local_id. Other columns are ignored. |
location_group |
the data.frame with location groups. Must contains local_id, description and scheme. Other variables are ignored. local_id must have unique values. |
location |
a data.frame with location metadata. Must contain the following columns: local_id, description, parent_local_id, datafield_local_id and external_code. Other columns are ignored. |
datafield |
a data.frame with datafield metadata. Must contain the variables local_id, datasource, table_name, primary_key and datafield_type. Other variables are ignored. |
conn |
a DBIconnection |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
location_group_location must have variables location_local_id and location_group_local_id.
location_group must have variables local_id, description and scheme
location must have variables local_id, description, parent_local_id, datafield_local_id and extranal_code. Other variables are ignored
datafield must have variables local_id, datasource, table_name, primary_key and datafield_type
all local_id variables must be unique within their data.frame
all values in location$datafield_local_id must exist in datafield$local_id
all values in location$parent_location must be either NA or exist in location$local_id
all values in location_group_location$location_local_id must exist in location$local_id
all values in location_group_location$location_group_local_id must exist in location_group$local_id
Store model sets in the database
store_model_set(model_set, hash, clean = TRUE, conn)
store_model_set(model_set, hash, clean = TRUE, conn)
model_set |
a data.frame with the model sets. Must have variables "local_id", "description", "first_year", "last_year" and "duration". The variable "long_description" is optional. |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
conn |
a DBIconnection |
Store model type in the database
store_model_type(model_type, hash, clean = TRUE, conn)
store_model_type(model_type, hash, clean = TRUE, conn)
model_type |
a data.frame with the modeltypes. Must have a variable "description". The variable "long_description" is optional. |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
conn |
a DBIconnection |
store an n2kImport object into the database
store_n2kImport(object, conn, hash, clean = TRUE)
store_n2kImport(object, conn, hash, clean = TRUE)
object |
a |
conn |
a DBIconnection |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
store all models from an n2kManifest
store_n2kManifest(manifest, base, project, conn, status = "converged", hash, clean = TRUE)
store_n2kManifest(manifest, base, project, conn, status = "converged", hash, clean = TRUE)
manifest |
|
base |
the base location to read the model |
project |
will be a relative path within the base location |
conn |
a DBIconnection |
status |
the status of the objects to be imported |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
extract the results from an n2kModel and stored them
store_n2kModel(x, conn, hash, clean = TRUE)
store_n2kModel(x, conn, hash, clean = TRUE)
x |
the n2kModel object |
conn |
a DBIconnection |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
store an n2kResult object into the database
store_n2kResult(object, conn, hash, clean = TRUE)
store_n2kResult(object, conn, hash, clean = TRUE)
object |
a |
conn |
a DBIconnection |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
store a datafield in the database
store_observation(datafield, observation, location, parameter, conn, hash, clean = TRUE)
store_observation(datafield, observation, location, parameter, conn, hash, clean = TRUE)
datafield |
a data.frame with datafield metadata. Must contain the variables local_id, datasource, table_name, primary_key and datafield_type. Other variables are ignored. |
observation |
a data.frame with observation metadata. Must contain the variables local_id, datafield_local_id, external_code, location_local_id, year and parameter_local_id. Other variables are ignored. datafield_local_id, external_code and parameter_local_id can be missing. |
location |
a data.frame with location metadata. Must contain the following columns: local_id, description, parent_local_id, datafield_local_id and external_code. Other columns are ignored. |
parameter |
a data.frame with parameters. Must contains the variables "description", "local_id", and "parent_parameter_local_id". Other variables are ignored. |
conn |
a DBIconnection |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
Store parameters
store_parameter(parameter, hash, conn, clean = TRUE)
store_parameter(parameter, hash, conn, clean = TRUE)
parameter |
a data.frame with parameters. Must contains the variables "description", "local_id", and "parent_parameter_local_id". Other variables are ignored. |
hash |
the hash of the update session |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
Store a vector of schemes
store_scheme(scheme, hash, conn, clean = TRUE)
store_scheme(scheme, hash, conn, clean = TRUE)
scheme |
the vector with scheme descriptions. |
hash |
the hash of the update session |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
store source species in the database
store_source_species(source_species, datafield, conn, hash, clean = TRUE)
store_source_species(source_species, datafield, conn, hash, clean = TRUE)
source_species |
a data.frame with source species metadata. Must contain local_id, description, datafield_local_id and extrenal_code. Other variables are ignored. |
datafield |
a data.frame with datafield metadata. Must contain variables local_id, datasource, table_name, primary_key and datafield_type. |
conn |
a DBIconnection |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
store source species in the database
store_source_species_species(species, language, source_species, source_species_species, datafield, conn, hash, clean = TRUE)
store_source_species_species(species, language, source_species, source_species_species, datafield, conn, hash, clean = TRUE)
species |
a data.frame with species metadata. Must contain at least 'local_id', 'scientific_name' and 'nbn_key'. Other variable names must match the values in 'language$code'. |
language |
the data.frame with language Must contains code and description. Other variables are ignored. code and description must have unique values. |
source_species |
a data.frame with source species metadata. Must contain local_id, description, datafield_local_id and extrenal_code. Other variables are ignored. |
source_species_species |
as data.frame linking the local species id to the local source_species id. Must contain species_local_id and source_species_local_id. Other variables are ignored. |
datafield |
a data.frame with datafield metadata. Must contain variables local_id, datasource, table_name, primary_key and datafield_type. |
conn |
a DBIconnection |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
store species in the database
store_species(species, language, conn, hash, clean = TRUE)
store_species(species, language, conn, hash, clean = TRUE)
species |
a data.frame with species metadata. Must contain at least 'local_id', 'scientific_name' and 'nbn_key'. Other variable names must match the values in 'language$code'. |
language |
the data.frame with language Must contains code and description. Other variables are ignored. code and description must have unique values. |
conn |
a DBIconnection |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
Store species groups
store_species_group(species_group, hash, conn, clean = TRUE)
store_species_group(species_group, hash, conn, clean = TRUE)
species_group |
the data.frame with species groups. Must contains local_id, description and scheme. Other variables are ignored. local_id must have unique values. |
hash |
the hash of the update session |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
store all species related information in the database
store_species_group_species(species, language, source_species, source_species_species, datafield, species_group, species_group_species, hash, conn, clean = TRUE)
store_species_group_species(species, language, source_species, source_species_species, datafield, species_group, species_group_species, hash, conn, clean = TRUE)
species |
a data.frame with species metadata. Must contain at least 'local_id', 'scientific_name' and 'nbn_key'. Other variable names must match the values in 'language$code'. |
language |
the data.frame with language Must contains code and description. Other variables are ignored. code and description must have unique values. |
source_species |
a data.frame with source species metadata. Must contain local_id, description, datafield_local_id and extrenal_code. Other variables are ignored. |
source_species_species |
as data.frame linking the local species id to the local source_species id. Must contain species_local_id and source_species_local_id. Other variables are ignored. |
datafield |
a data.frame with datafield metadata. Must contain variables local_id, datasource, table_name, primary_key and datafield_type. |
species_group |
the data.frame with species groups. Must contains local_id, description and scheme. Other variables are ignored. local_id must have unique values. |
species_group_species |
as data.frame linking the local species group id to the local species id. Must contain variables species_local_id and species_group_local_id. Other variables are ignored. |
hash |
the hash of the update session |
conn |
a DBIconnection |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
Store status levels in the database
store_status(status, hash, clean = TRUE, conn)
store_status(status, hash, clean = TRUE, conn)
status |
a character vector with statuses |
hash |
the hash of the update session |
clean |
perform all database operations within a transaction and clean up the staging tables. Defaults to TRUE. |
conn |
a DBIconnection |
Truncate all tables in the public schema: USE WITH CATION
truncate_public(conn)
truncate_public(conn)
conn |
a DBIconnection |