Skip to contents

Returns a processed CTD table from the ctdR cache populated by import_CTD, without reaching into the .rda cache files by hand. Use this instead of load(file.path(cache_dir, "...rda")) when you need the chemical metadata or the raw interaction table in your own code.

For the chemical gene sets (the input to enrichment engines) use as_genesets_CTD instead.

Usage

ctd_cache(what = c("chemicals", "interactions"), cache_dir = .ctd_cache_dir())

Arguments

what

Which cached table to return:

"chemicals"

a data frame with one row per chemical (ChemicalID, ChemicalName).

"interactions"

the long-format interaction table (ChemicalID, EntrezID, InteractionActions).

cache_dir

Directory holding the cached CTD files. Defaults to the ctdR user cache populated by import_CTD.

Value

A data frame with the requested cached table.

See also

import_CTD to populate the cache; as_genesets_CTD for the chemical gene sets.

Examples

# Examples write to a temporary cache, so running them cannot
# disturb CTD data you have already imported. Set the same option
# yourself to keep an analysis isolated from your main cache.
options(ctdR.cache = tempfile())

sample_file <- system.file(
    "extdata", "CTD_chem_gene_ixns_sample.csv",
    package = "ctdR"
)
import_CTD(sample_file)
#> Reading CTD chemical-gene interactions from: /home/runner/work/_temp/Library/ctdR/extdata/CTD_chem_gene_ixns_sample.csv
#> Filtered to 86 human interactions
#> Mapping genes for 10 chemicals...
#> Warning: 10 ChemicalID(s) appear with more than one ChemicalName in the CTD file; only the first name per ID is retained. Affected IDs: D000082, D001564, D002104, D003907, D004958 ... (and 5 more)
#> CTD data cached successfully in: /tmp/Rtmpt9pODL/file1b1372704522
#>   10 chemicals | 17 unique genes | 0 s
#>   CTD release: Mon Jan 01 00:00:00 EST 2024
chem <- ctd_cache("chemicals")
head(chem)
#> # A tibble: 6 × 2
#>   ChemicalID ChemicalName  
#>   <chr>      <chr>         
#> 1 D000082    Acetaminophen 
#> 2 D001564    Benzo(a)pyrene
#> 3 D002104    Cadmium       
#> 4 D003907    Dexamethasone 
#> 5 D004958    Estradiol     
#> 6 D001151    Arsenic