Description Details Fields Methods
The class Databases
handles initialising databases (eg. downloading relevant files)
and dispatching requests to each database for searching them.
Note that this class does not handle synonym-checking; this is performed by the
find_species_traits
function. This class also has a custom $new function, which
takes two arguments: directory
, which is the directory that
you want to store downloaded database files in (usually CSV or Excel files); and
database_classes
, which is a list of the databases you would like it to
manage. It defaults to \codefunctionaltraits_db_list, which includes all available databases.
If a database is causing errors or cannot connect to the server and is causing the ready() function
to fail, then you can omit it from this argument and it will not be included."
dir
character containing the path to a folder that all of the database files will be downloaded to
databases
a list with the names of the databases as the key and the value being the actual class of the database.
check_traits(traits)
This function takes one argument, traits
, and checks whether it is a validly formatted
list. The names of the list elements must correspond to the names of the databases as provided
in database_classes
to the $new function, and the elements must be vectors containing
the names of the columns selected from the database. If the list is not valid, this function
will throw an error explaining why.
columns()
This function returns a list of all columns that are available for each database, in a format suitable to be provided to $search or $check_traits. You can use it to find out what columns are available and what their names are.
drop(database_name)
This function removes a database. It can be used if a database cannot properly configure itself using the $initialise() function and consequently would not return TRUE when $ready() is called. It takes one argument, database_name, which is a string containing the name of the database that you want to remove.
initialise()
This functions initialises the databases if they are not already initialised.
ready()
This function checks whether all the databases are ready for use. If they are, it returns TRUE. If not, it returns FALSE. Each database that is not ready will print a warning message.
search(species, traits = NULL)
This function takes one argument, species
and searches the databases for those species.
It can optionally take another argument, traits
, which is a list of the traits to return
from each database. It is a list of vectors, where the name of each list element is
the name of a database and the vectors hold the names of the traits to return,
eg. list( fishbase = c( 'Weight' ) ).
It returns a list, with one element results
containing a dataframe of the results;
and another element statistics
being a dataframe with the number of matches and columns
selected from each database.
Note that duplicate species are removed from the list using unique(), so the dataframe that is returned is not guaranteed to have the same amount of rows as the number of species provided (unless you run unique() on your list of species first).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.