-
Notifications
You must be signed in to change notification settings - Fork 2
Initializing biodb
This page has been generated automatically from a package vignette. Please do not edit, since your modifications will later be removed.
First of all, before using biodb, you need to create an instance of the main class Biodb
. This is done by calling the constructor of the class through the new()
method. The OOP (Object Oriented Programming) system used in the biodb package is the R5 system also called Reference Classes. In this system, the created objects are not copied, but their reference are copied. This means than when you pass an instance to a function, that function is able to modify the instance.
To create an instance of the Biodb
class, call the constructor method:
mybiodb <- biodb::Biodb()
This is will create a Biodb
instance and put its reference into the mybiodb
variable. Calling new()
without any argument configures the instance with the default values.
By default, the Biodb
instance will be configured with a console logger (instance of the class BiodbLogger
), which will print all biodb messages to the console.
You can disable this default logger by setting the logger
argument to false:
mybiodb <- biodb::Biodb$new(logger = FALSE)
In this case, only the normal R warnings and errors will be printed.
You can also set your own instance of BiodbLogger
, using the observers
argument, in order for instance to redirect the output to a file:
mybiodb <- biodb::Biodb$new(logger = FALSE, observers = biodb::BiodbLogger$new(file = 'mybiodb.log'))
If you want both have the logger output written to the console and into a file, just define two instances of the BiodbLogger
class:
mybiodb <- biodb::Biodb$new(logger = FALSE, observers = list(biodb::BiodbLogger$new(), biodb::BiodbLogger$new(file = 'mybiodb2.log')))
See the documentation of the BiodbLogger
class for more details.
If you wish, you can also define your own observers that inherit from the BiodbObserver
class, and set them through the observers
argument.
It is also possible to add an observer during the life of your biodb instance:
mybiodb$addObservers( list(biodb::BiodbLogger$new(), biodb::BiodbLogger$new(file = 'mybiodb3.log')))
Here is how to obtain a list of all observers currently defined:
mybiodb$getObservers()
Several singleton classes are defined in biodb. Their instances are all accessible from the Biodb
instance you've created.
To get the factory instance:
factory <- mybiodb$getFactory()
To get the configuration instance:
config <- mybiodb$getConfig()
To get the cache system instance:
cache <- mybiodb$getCache()
To get the database information instance:
dbsinfo <- mybiodb$getDbsInfo()
To get the entry fields instance:
entry.fields <- mybiodb$getEntryFields()