Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why might one load a library more than once in an R script?

Tags:

r

I am trying to understand some code well enough that I can create the necessary files to make it run it for a client. I thought it was odd that it loads a library within a loop:

for (i in 1:length(ids) ){
    library(limma)

    # About 80 lines of code

}

Is there any likely reason that someone would want to reload the same library multiple times? I thought that libraries didn't do anything besides provide functions.

I searched the limma user guide for the keywords "library" and "load" and didn't find anything obvious.

I would almost think this were an accident if it weren't the very first line in the loop.

like image 557
Christopher Bottoms Avatar asked May 06 '15 19:05

Christopher Bottoms


Video Answer


1 Answers

It's a mistake. Change the library call to library(limma, verbose=TRUE) and you'll see that only the first call actually does anything (something is returned invisibly, but they're not using it because it's not being assigned).

For example:

> pkgs <- library(base, verbose=TRUE)
Warning message:
In library(base, verbose = TRUE) :
  package ‘base’ already present in search()
> pkgs
# [1] "stats"     "graphics"  "grDevices" "utils"     "datasets" 
# [6] "setwidth"  "colorout"  "methods"   "base"
like image 119
Joshua Ulrich Avatar answered Oct 20 '22 00:10

Joshua Ulrich