RLibrary = function( ... ) {
#\\ used to (re)load libraries conveniently
ll = unique(c(...))
pkgs = .packages(all.available = TRUE)
pkgsLoaded = .packages()
found = intersect( pkgs, ll )
if (length(found) > 0 ) {
for ( pkg in found ) {
# try( detach( paste("package", pkg, sep=":"), unload=TRUE, character.only=TRUE, force=TRUE ), silent=TRUE )
try ( suppressMessages( require( pkg, character.only = TRUE )), silent = TRUE )
}
}
notfound = setdiff( ll, pkgs )
if (length(notfound) > 0) {
print( "Missing some dependencies...")
print( notfound )
n = readline(prompt="Install them? (y/n): ")
if ( tolower(n) %in% c("y", "yes") ) {
for ( nf in notfound ) {
try( utils::install.packages( nf, dependencies=TRUE ) )
try( require( pkg, character.only = TRUE ) )
}
}
}
if ( "INLA" %in% notfound ) {
print( "To install INLA:")
print( ' install.packages("INLA", repos="https://www.math.ntnu.no/inla/R/stable") ' )
}
return( ll )
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.