Skip to contents

A R6 object that provides a common set of methods to 1) store the metadata of data in the db, and 2) export parquet files for python to import. Not meant to be called manually.

Public fields

hash

(character())
hash of the object by rlang::hash().

pin_name

(character())
pin_name of the file in the project folder.

df

(data.frame())
the df for the hyper param grid or the transformed df.

con

(DBI::dbConnect())
a DBI::dbConnect() object, generated by rpwf_connect_db().

export_query

(glue::glue_sql())
SQL query to upload metadata of the data into the db.

queried_pin_name

(glue::glue_sql())
Queried pin_name of the object.

board

(character())
a {pins} board object.

dbname

name of the database.

seed

random seed.

Methods


Method new()

This class is the parent of RGrid and TrainDf R6 object, not meant to be called.

Usage

BaseEx$new(db_con)

Arguments

db_con

(DbCon)
a DbCon object, generated by rpwf_connect_db().


Method exec_query()

Run the query that check if the object exists in the db by checking the hash of the object in the db. Either find one unique row or no row.

Usage

BaseEx$exec_query(query)

Arguments

query

(glue::glue_sql())
SQL query for either the hyper parameter grid or the transformed df.


Method set_hash()

Pass the hash of the object to this function to set the hash attribute.

Usage

BaseEx$set_hash(val)

Arguments

val

(any)
New hash, either an integer or string.


Method set_pin_name()

Change the pin_name where the object is stored. Is NA only when no grid is provided. Have to provide a train data.

Usage

BaseEx$set_pin_name(val)

Arguments

val

(character())
Path to store the object on disk.


Method find_pin_name_in_db()

Store the results of the query from the db in a data.frame. Query have to return a df (so nrow() works) with 0 <= nrow() < 2.

Usage

BaseEx$find_pin_name_in_db(val)

Arguments

val

(data.frame())
New data frame generated by self$exec_query.


Method set_export_query()

Change the SQL query to export metadata to database.

Usage

BaseEx$set_export_query(val)

Arguments

val

(glue::glue_sql())
New SQL query to export metadata.


Method set_df()

If the hash of the new object is not found in the database, then new data is prepared. If the data is found in the metadata but not in the indicated pin_name then new data is also prepared. Otherwise, self$df is NULL and will be skipped by the BaseEx::self$export_parquet() method.

Usage

BaseEx$set_df(val)

Arguments

val

(data.frame())
Either a recipes::juice() object or a data.frame of the hyper param grid.


Method export_prep()

If the db query found no existing metadata, then an export pin_name is made. If the metadata is found but the associated data is not found, then an export pin_name is also made. Else get the pin_name from the metadata in the db.

Usage

BaseEx$export_prep(new_pin_name, new_export_query)

Arguments

new_pin_name

(character())
Path to the object.

new_export_query

(glue::glue_sql())
SQL query to export the obj metadata to the db.


Method export_db()

If the self$export_query is generated because metadata is not found in the database, then export the metadata to the db using this query. Otherwise return NULL.

Usage

BaseEx$export_db()


Method export_parquet()

If the file specified by self$pin_name is not found, then export the file as a parquet file to the location specified in the metadata.

Usage

BaseEx$export_parquet()


Method export()

Wrapper around exporting information to the db and writing the parquet file.

Usage

BaseEx$export()


Method clone()

The objects of this class are cloneable with this method.

Usage

BaseEx$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.