Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Using an access token

Pierrick Roger edited this page Mar 6, 2018 · 3 revisions

This page has been generated automatically from a package vignette. Please do not edit, since your modifications will later be removed.

Setting your token

As of today, two databases require an access token: ChemSpider and Peakforest.

There are four ways to set an access token in biodb:

  • Through environment variables.
  • Through the BiodbConfig class instance.
  • When creating explicitly a connector instance.
  • Directly on the database information class (BiodbDbInfo) instance.

The environment variables and biodb configuration keys you must use to set your access tokens are:

Database biodb configuration key Environment variable
PeakForest Mass peakforest.mass.token BIODB_PEAKFOREST_MASS_TOKEN
PeakForest Compound peakforest.compound.token BIODB_PEAKFOREST_COMPOUND_TOKEN
ChemSpider chemspider.token BIODB_CHEMSPIDER_TOKEN

To set your ChemSpider access token using the environment variables under UNIX/Linux systems:

export BIODB_CHEMSPIDER_TOKEN=01234567-89ab-cdef-0123-456789abcdef

The environment variable is used by the BiodbConfig class instance if available. However you can also use the BiodbConfig class instance directly:

mybiodb <- biodb::Biodb$new()
mybiodb$getConfig()$set('chemspider.token', '01234567-89ab-cdef-0123-456789abcdef')

To set the token directly on the DbInfo instance:

mybiodb <- biodb::Biodb$new()
dbsinfo <- mybiodb$getDbsInfo()
dbsinfo$get('chemspider')$setToken('01234567-89ab-cdef-0123-456789abcdef')

To set the token when instantiating the connector with the factory:

mybiodb <- biodb::Biodb$new()
factory <- mybiodb$getFactory()
conn <- factory$createConn('chemspider', token = '01234567-89ab-cdef-0123-456789abcdef')

Accessing the database

You should then be able to access the database normally.