# library

0th

Percentile

library and require load add-on packages. In the masked versions of package SweaveListingUtils documented here, they also register corresponding symbols. Besides this registration, they behave identically to the original versions of package base. Hence much of this help is also just copied from the original help page. As the original may have changed in the mean time in doubt please rely on the original help page.

Keywords
utilities
##### Usage
library(package, help, pos = 2, lib.loc = NULL, character.only = FALSE, logical.return = FALSE, warn.conflicts = TRUE, quietly = FALSE, keep.source = getOption("keep.source.pkgs"), verbose = getOption("verbose"), inSweave, keywordstyles, interm.keywordstyles, overwrite, intermediate)
require(package, lib.loc = NULL, quietly = FALSE, warn.conflicts = TRUE, keep.source = getOption("keep.source.pkgs"), character.only = FALSE, save = TRUE, inSweave, keywordstyles, interm.keywordstyles, overwrite, intermediate)
##### Arguments
package, help
the name of a package, given as a name or literal character string, or a character string, depending on whether character.only is FALSE (default) or TRUE).
pos
the position on the search list at which to attach the loaded package. Note that .First.lib may attach other packages, and pos is computed after .First.lib has been run. Can also be the name of a position on the current search list as given by search().
lib.loc
a character vector describing the location of R library trees to search through, or NULL. The default value of NULL corresponds to all libraries currently known. Non-existent library trees are silently ignored.
character.only
a logical indicating whether package or help can be assumed to be character strings.
logical.return
logical. If it is TRUE, FALSE or TRUE is returned to indicate success.
warn.conflicts
logical. If TRUE, warnings are printed about conflicts from attaching the new package, unless that package contains an object .conflicts.OK. A conflict is a function masking a function, or a non-function masking a non-function.
keep.source
logical. If TRUE, functions ‘keep their source’ including comments, see argument keep.source to options. This applies only to the named package, and not to any packages or name spaces which might be loaded to satisfy dependencies or imports.

This argument does not apply to packages using lazy-loading. Whether they have kept source is determined when they are installed (and is most likely false).

verbose
a logical. If TRUE, additional diagnostics are printed.
quietly
a logical. If TRUE, no message confirming package loading is printed.
save
logical or environment. If TRUE, a call to require from the source for a package will save the name of the required package in the variable ".required", allowing function detach to warn if a required package is detached. See section ‘Packages that require other packages’ below.
inSweave
shall the command show Sweave behaviour (no startup messages; instead issuing new symbols for morekeywords tag in language definition of R in TeX package ‘listings’)? By default argument is taken from getSweaveListingOption.
keywordstyles
character or missing or NULL; added argument in masked versions of library and require of package SweaveListingUtils; if given, the keywordstyle to be used by TeX package 'listings' for the symbols attached in this package (to be found with ls()). Remember that special characters like \ have to be escaped. If missing, a special strategy is used to get sensible value (see details).
interm.keywordstyles
character or missing or NULL; added argument in masked versions of library and require of package SweaveListingUtils; if given, the keywordstyle to be used by TeX package 'listings' for the symbols to be found by automatically loaded intermediate packages (mentioned in 'depends' field of the corresponding DESCRIPTION file). This will only be used if effective argument intermediate is TRUE. Remember that special characters like \ have to be escaped. If missing, a special strategy is used to get sensible value (see details).
overwrite
logical or missing or NULL; added argument in masked versions of library and require of package SweaveListingUtils; if missing, the corresponding global option is read out by getSweaveListingOption. Let us call the corresponding possibly imputed value effective value. If this effective value is TRUE, before registering a new symbol for TeX package 'listings', we first check whether this symbol had already been registered in the original 'listings'-language definition of R in file ‘lstlang3.sty’ [which we have copied to the internal (un-exported) constant .keywordsR] and if so do not include the symbol once again; if the value is FALSE, no matter of the original language definition all symbols to be found by ls() are registered and hence typeset in the corresponding package-keywordstyle.
intermediate
logical or missing or NULL; added argument in masked versions of library and require of package SweaveListingUtils; if missing, the corresponding global option is read out by getSweaveListingOption. If the effective value is TRUE, also the symbols to be found in newly, automatically loaded packages (loaded, because the required/"library"-ed package features them in its corresponding Depends field in its DESCRIPTION file) are registered for TeX package 'listings'.
##### Details

library and require are masked versions of the original versions in package base. This masking is necessary to allow for extra arguments keywordstyles, interm.keywordstyles, overwrite, intermediate. Hence please in case of doubt see library, require.

If argument inSweave is FALSE or if argument inSweave is missing and the corresponding global option getSweaveListingOption("inSweave") is FALSE, then library and require behave exactly as the base package versions; only if the effective argument is TRUE, the corresponding startup-messages are suppressed, and the TeX code for registering all new symbols to be found with ls as morekeywords for the R language definition in TeX package ‘listings’ is issued (and hence can be used in ‘.Rnw’ files.

The strategy to fill arguments keywordstyles and interm.keywordstyles if missing is as follows: First we check whether for the corresponding package, there is an enty in the global option variable .tobeDefinedPkgs (which is a matrix residing in the package namespace with one column of package names and one column of corresponding keywordstyle format strings) and if so use its corresponding keywordstyle; else we use option Keywordstyles resp. interm.Keywordstyles (which we get by getSweaveListingOption). New entries in the global variable .tobeDefinedPkgs may be appended by setToBeDefinedPkgs.

The masked versions work as follows: first the call is written to an object and split into a base-package-part and into the extra arguments mentioned above. Then we call base:: where is either require or library. By noting the list of attached packages before and after this call we also get hand on the intermediate packages, which are automatically attached packages by dependence. After this call we register the new symbols by corresponding calls to lstsetLanguage. For use in an .Rnw file, the call to require or library should be wrapped into a corresponding Sweave chunk in the form

<< /chunkname/, results=tex, echo=TRUE>>=
require( ..... )
@

,for example
<< distrRequire, results=tex, echo=TRUE>>=
require(distr)
@

In order to unmask the original versions of library and require again after Sweave-ing your .Rnw file, at the end of your .Rnw file you should include an Sweave chunk like
<>=
@

or, if you want to keep the namespace of SweaveListingUtils loaded
<>=
SweaveListingUtils(inSweave = FALSE)
@


##### Value

library.

• library
• require
##### Examples
require(survival)

Documentation reproduced from package SweaveListingUtils, version 0.7.5, License: LGPL-3

### Community examples

Looks like there are no examples yet.