Question: Why does requireNamespace("") load DBI and RSQLite?
gravatar for Gordon Smyth
19 months ago by
Gordon Smyth32k
Walter and Eliza Hall Institute of Medical Research, Melbourne, Australia
Gordon Smyth32k wrote:

Can anyone help me understand why requireNamespace("") 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 objects are stored as SQL databases?

Or is it perhaps not even intended?

For the sake of specificity, I've asked about, 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 name space, a number of additional name spaces appear:

> requireNamespace("")
Loading required namespace:
Loading required package: DBI

> loadedNamespaces()
 [1] ""  "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

[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]   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  


ADD COMMENTlink modified 19 months ago by Martin Morgan ♦♦ 20k • written 19 months ago by Gordon Smyth32k
gravatar for Martin Morgan
19 months ago by
Martin Morgan ♦♦ 20k
United States
Martin Morgan ♦♦ 20k wrote:

I did

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

runHook(".onLoad", env, package.lib, package)


So that 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")
    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 COMMENTlink modified 19 months ago • written 19 months ago by Martin Morgan ♦♦ 20k

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 REPLYlink modified 19 months ago • written 19 months ago by Gordon Smyth32k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 259 users visited in the last hour