As a complement to @MikeDunlavey's answer :
Actually, both library and require check if the package is loaded. Here are some timings with microbenchmark I get:
> microbenchmark (`!` (exists ("qplot")), `!` (existsFunction ('qplot')), require ('ggplot2'), library ('ggplot2'), "package:ggplot2" %in% search ())
For comparison, loading for the first time:
> system.time (library (ggplot2)) User System verstrichen 0.284 0.016 0.300
(it's seconds!)
In the end, as long as the factor 3 = 10 ยตs between require and "package:ggplot2" %in% search() not needed, I would go with require , otherwise with %in% search () .
cbeleites
source share