| BiodbMain | R Documentation |
The central class of the biodb package.
The central class of the biodb package.
The main class of the biodb package.
In order to use the biodb package, you need first to create an instance of
this class.
The constructor takes a single argument, autoloadExtraPkgs, to enable
(TRUE or default) or disable (FALSE) autoloading of extra
biodb packages.
Once the instance is created, some other important classes
(BiodbFactory, BiodbPersistentCache, BiodbConfig, ...)
are instantiated (just once) and their instances are later accessible through
get*() methods.
new()New instance initializer. The BiodbMain must not be instantiated directly. Instead use the newInst() global method.
BiodbMain$new(autoloadExtraPkgs = NULL)
autoloadExtraPkgsSet to TRUE to allow automatic loading of extension packages. Set to FALSE to forbid it. If left to NULL, the default, autoload.extra.pkgs configuration value will be used.
Nothing.
terminate()Closes \codeBiodbMain instance. Call this method when you are done with your \codeBiodbMain instance.
BiodbMain$terminate()
Nothing.
loadDefinitions()Loads databases and entry fields definitions from YAML file.
BiodbMain$loadDefinitions(file, package = "biodb")
fileThe path to a YAML file containing definitions for \codeBiodbMain (databases, fields or configuration keys).
packageThe package to which belong the new definitions.
Nothing.
getConfig()Returns the single instance of the \codeBiodbConfig class.
BiodbMain$getConfig()
The instance of the \codeBiodbConfig class attached to this BiodbMain instance.
getPersistentCache()Returns the single instance of the BiodbPersistentCache class.
BiodbMain$getPersistentCache()
The instance of the BiodbPersistentCache class attached to this BiodbMain instance.
getDbsInfo()Returns the single instance of the \codeBiodbDbsInfo class.
BiodbMain$getDbsInfo()
The instance of the \codeBiodbDbsInfo class attached to this BiodbMain instance.
getEntryFields()Returns the single instance of the \codeBiodbEntryFields class.
BiodbMain$getEntryFields()
The instance of the \codeBiodbEntryFields class attached to this BiodbMain instance.
getFactory()Returns the single instance of the \codeBiodbFactory class.
BiodbMain$getFactory()
The instance of the \codeBiodbFactory class attached to this BiodbMain instance.
getRequestScheduler()Returns the single instance of the \codeBiodbRequestScheduler class.
BiodbMain$getRequestScheduler()
The instance of the \codeBiodbRequestScheduler class attached to this BiodbMain instance.
addObservers()Adds new observers. Observers will be called each time an event occurs. This is the way used in biodb to get feedback about what is going inside biodb code.
BiodbMain$addObservers(observers)
observersEither an object or a list of objects.
Nothing.
getObservers()Gets the list of registered observers.
BiodbMain$getObservers()
The list or registered observers.
convertEntryIdFieldToDbClass()Gets the database class name corresponding to an entry ID field.
BiodbMain$convertEntryIdFieldToDbClass(entry.id.field)
entry.id.fieldThe name of an ID field. It must end with \".id\".
entriesFieldToVctOrLst()Extracts the value of a field from a list of entries. Returns either a vector or a list depending on the type of the field.
BiodbMain$entriesFieldToVctOrLst( entries, field, flatten = FALSE, compute = TRUE, limit = 0, withNa = TRUE )
entriesA list of \codeBiodbEntry instances.
fieldThe name of a field.
flattenIf set to \codeTRUE and the field has a cardinality greater than one, then values be converted into a vector of class character in which each entry values are collapsed.
computeIf set to \codeTRUE, computable fields will be output.
limitThe maximum number of values to retrieve for each entry. Set to 0 to get all values.
withNaIf set to TRUE, keep NA values. Otherwise filter out NAs values in vectors.
A vector if the field is atomic or flatten is set to \codeTRUE, otherwise a list.
entriesToDataframe()Converts a list of entries or a list of list of entries (\codeBiodbEntry objects) into a data frame.
BiodbMain$entriesToDataframe( entries, only.atomic = TRUE, null.to.na = TRUE, compute = TRUE, fields = NULL, limit = 0, drop = FALSE, sort.cols = FALSE, flatten = TRUE, only.card.one = FALSE, own.id = TRUE, prefix = "" )
entriesA list of \codeBiodbEntry instances or a list of list of \codeBiodbEntry instances.
only.atomicIf set to \codeTRUE, output only atomic fields, i.e.: the fields whose value type is one of integer, numeric, logical or character.
null.to.naIf set to \codeTRUE, each \codeNULL entry in the list is converted into a row of NA values.
computeIf set to \codeTRUE, computable fields will be output.
fieldsA character vector of field names to output. The data frame output will be restricted to this list of fields.
limitThe maximum number of field values to write into new columns. Used for fields that can contain more than one value. Set it to 0 to get all values.
dropIf set to \codeTRUE and the resulting data frame has only one column, a vector will be output instead of data frame.
sort.colsSort columns in alphabetical order.
flattenIf set to \codeTRUE, then each field with a cardinality greater than one, will be converted into a vector of class character whose values are collapsed.
only.card.oneOutput only fields whose cardinality is one.
own.idIf set to TRUE includes the database id field named
<database_name>.id whose values are the same as the accession field.
prefixInsert a prefix at the start of all field names.
A data frame containing the entries. Columns are named according to field names.
entryIdsToDataframe()Construct a data frame using entry IDs and field values of the corresponding entries.
BiodbMain$entryIdsToDataframe( ids, db, fields = NULL, limit = 3, prefix = "", own.id = FALSE )
idsA character vector of entry IDs or a list of character vectors of entry IDs.
dbThe biodb database name for the entry IDs, or a connector ID, as a sinle character value.
fieldsA character vector containing entry fields to add.
limitThe maximum number of field values to write into new columns. Used for fields that can contain more than one value. Set it to 0 to get all values.
prefixInsert a prefix at the start of all field names.
own.idIf set to TRUE includes the database id field named
<database_name>.id whose values are the same as the accession field.
Adata frame containing in columns the requested field
values, with one entry per line, in the same order than in ids vector.
addColsToDataframe()Add values from a database to an existing data frame using a column containing entry identifiers.
BiodbMain$addColsToDataframe(x, id.col, db, fields, limit = 3, prefix = "")
xA data frame containing at least one column with Biodb entry IDs
identified by the parameter id.col.
id.colThe name of the column containing IDs inside the input data frame.
dbThe biodb database name for the entry IDs, or a connector ID, as a single character value.
fieldsA character vector containing entry fields to add.
limitThe maximum number of field values to write into new columns. Used for fields that can contain more than one value. Set it to 0 to get all values.
prefixInsert a prefix at the start of all field names.
A data frame containing x and new columns appended for the fields
requested.
entriesToJson()Converts a list of \codeBiodbEntry objects into JSON. Returns a vector of characters.
BiodbMain$entriesToJson(entries, compute = TRUE)
entriesA list of \codeBiodbEntry instances. It may contain NULL elements.
computeIf set to \codeTRUE, computable fields will added to JSON too.
A list of JSON strings, the same length as entries list.
collapseRows()Collapses rows of a data frame, by looking for duplicated values in the
reference columns (parameter cols). The values contained in the reference
columns are supposed to be ordered inside the data frame, in the sens that
all duplicated values are supposed to directly follow the original values.
For all rows containing duplicated values, we look at values in all other
columns and concatenate values in each column containing different values.
BiodbMain$collapseRows(x, sep = "|", cols = 1L)
xA data frame.
sepThe separator to use when concatenating values in collapsed rows.
colsThe indices or the names of the columns used as reference.
A data frame, with rows collapsed."
entriesToSingleFieldValues()Extract all values of a field from a list of entries.
BiodbMain$entriesToSingleFieldValues( entries, field, sortOutput = FALSE, uniq = TRUE )
entriesA list of BiodbEntry objects.
fieldThe field for which to extract values.
sortOutputSet to TRUE to sort the values.
uniqSet to TRUE to remove duplicates.
The values of the field as a vector.
entryIdsToSingleFieldValues()Extract all values of a field from a list of entries.
BiodbMain$entryIdsToSingleFieldValues( ids, db, field, sortOutput = FALSE, uniq = TRUE )
idsA list of entry identifiers.
dbThe database ID or connector ID where to find the entries.
fieldThe field for which to extract values.
sortOutputSet to TRUE to sort the values.
uniqSet to TRUE to remove duplicates.
The values of the field as a vector.
computeFields()Computes missing fields in entries, for those fields that are comptable.
BiodbMain$computeFields(entries)
entriesA list of \codeBiodbEntry instances. It may contain NULL elements.
Nothing.
saveEntriesAsJson()Saves a list of entries in JSON format. Each entry will be saved in a separate file.
BiodbMain$saveEntriesAsJson(entries, files, compute = TRUE)
entriesA list of \codeBiodbEntry instances. It may contain NULL elements.
filesA character vector of file paths, the same length as entries list.
computeIf set to \codeTRUE, computable fields will be saved too.
Nothing.
copyDb()Copies all entries of a database into another database. The connector of the destination database must be editable.
BiodbMain$copyDb(conn.from, conn.to, limit = 0)
conn.fromThe connector of the source datababase to copy.
conn.toThe connector of the destination database.
limitThe number of entries of the source database to copy. If set to \codeNULL, copy the whole database.
Nothing.
print()Prints object information.
BiodbMain$print()
Nothing.
fieldIsAtomic()DEPRECATED method to test if a field is an atomic field. The new method is \codeBiodbEntryField :isVector()."
BiodbMain$fieldIsAtomic(field)
fieldThe name of the field.
TRUE if the field's value is atomic.
getFieldClass()DEPRECATED method to get the class of a field. The new method is
BiodbMain :getEntryFields()$get(field)$getClass().
BiodbMain$getFieldClass(field)
fieldThe name of the field.
The class of the field.
clone()The objects of this class are cloneable with this method.
BiodbMain$clone(deep = FALSE)
deepWhether to make a deep clone.
BiodbFactory, BiodbPersistentCache,
BiodbConfig, BiodbEntryFields,
BiodbDbsInfo.
# Create an instance: mybiodb <- biodb::newInst() # Get the factory instance fact <- mybiodb$getFactory() # Terminate instance. mybiodb$terminate() mybiodb <- NULL
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.