Why does requireNamespace("org.Hs.eg.db") load DBI and RSQLite?
1
2
Entering edit mode
@gordon-smyth
Last seen 58 minutes ago
WEHI, Melbourne, Australia

Can anyone help me understand why requireNamespace("org.Hs.eg.db") not only loads the needed name spaces, but also loads DBI and RSQLite into the search space? It isn't usual practice in R that loading a name space will have a side-effect like this. For example requireNamespace("AnnotationDbi") doesn't add anything to the search path, even though AnnotationDbi uses both DBI and RSQLite.

Is loading into the search path somehow required because org.Hs.eg.db objects are stored as SQL databases?

Or is it perhaps not even intended?

For the sake of specificity, I've asked about org.Hs.eg.db, but the same question applies to GO.db and to all the organism packages.

Here's some example code. In a new R session, we have just the usual R core packages and name spaces loaded.

> loadedNamespaces()
[1] "graphics"  "utils"     "grDevices" "stats"     "datasets"  "methods"   "base"     
> search()
[1] ".GlobalEnv"        "package:stats"     "package:graphics"  "package:grDevices"
[5] "package:utils"     "package:datasets"  "package:methods"   "Autoloads"         
[9] "package:base" 

After loading the org.Hs.eg.db name space, a number of additional name spaces appear:

> requireNamespace("org.Hs.eg.db")
Loading required namespace: org.Hs.eg.db
Loading required package: DBI

> loadedNamespaces()
 [1] "org.Hs.eg.db"  "IRanges"       "graphics"      "parallel"      "DBI"           "utils"        
 [7] "grDevices"     "stats"         "Biobase"       "AnnotationDbi" "datasets"      "RSQLite"      
[13] "S4Vectors"     "methods"       "BiocGenerics"  "stats4"        "base"         

which was not unexpected, but DBI and RSQLite get added to the search path:

> search()
 [1] ".GlobalEnv"        "package:RSQLite"   "package:DBI"       "package:stats"     "package:graphics" 
 [6] "package:grDevices" "package:utils"     "package:datasets"  "package:methods"   "Autoloads"        
[11] "package:base"  

which I didn't expect.

A secondary question: why there a message telling me that DBI has been loaded but no similar message for RSQLite?

 

> sessionInfo()
R Under development (unstable) (2016-03-14 r70331)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RSQLite_1.0.0 DBI_0.3.1    

loaded via a namespace (and not attached):
[1] org.Hs.eg.db_3.3.0   IRanges_2.5.42       parallel_3.3.0       Biobase_2.31.3      
[5] AnnotationDbi_1.33.7 S4Vectors_0.9.46     BiocGenerics_0.17.4  stats4_3.3.0  

 

org.hs.eg.db DBI rsqlite • 1.6k views
ADD COMMENT
1
Entering edit mode
@martin-morgan-1513
Last seen 3 months ago
United States

I did

> debug(attachNamespace)
> requireNamespace('org.Hs.eg.db')
...
Browse[2]> ns
<environment: namespace:DBI>
Browse[2]> sys.calls()

[[1]]
requireNamespace("org.Hs.eg.db")
...
[[7]]
runHook(".onLoad", env, package.lib, package)
...
[[13]]
dbFileConnect(dbfile)

[[14]]
library(RSQLite)
...

So that org.Hs.eg.db:::.onLoad is calling AnnotationDbi:::dbFileConnect, which unfortunately attaches the RSQLite (and hence DBI) library

> AnnotationDbi:::dbFileConnect
function (dbfile) 
{
    if (!file.exists(dbfile)) 
        stop("DB file '", dbfile, "' not found")
    library(RSQLite)
    dbConnect(SQLite(), dbname = dbfile, cache_size = 64000, 
        synchronous = "off", flags = SQLITE_RO)
}
<environment: namespace:AnnotationDbi>

We'll try to correct this; superficially it seems like a simple question of importing RSQLite. I think the call also explains why only DBI is announced --

> library(RSQLite)
Loading required package: DBI
> 
ADD COMMENT
0
Entering edit mode

Thanks Martin. My naive reading of the code is that RSQLite is already imported, so that SQLite() can be replaced by RSQLite::SQLite() and library(RSQLite) is unnecessary.

ADD REPLY

Login before adding your answer.

Traffic: 436 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6