Created
October 22, 2016 18:27
-
-
Save talegari/02c7888eab9211387e5487ce0fc80b44 to your computer and use it in GitHub Desktop.
Load a R library without cluttering the terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################### | |
# | |
# libraryQ ---- | |
# | |
############################################################################### | |
# | |
# author : Srikanth KS (talegari) | |
# license : GNU AGPLv3 (http://choosealicense.com/licenses/agpl-3.0/) | |
# | |
############################################################################### | |
# | |
# Description ---- | |
# | |
# The function loads a R library, if present and return an invisible TRUE. | |
# If the package is not present, it returns an invisible FALSE. | |
# No message or warning is written to the terminal. | |
# pkgName has to be a string (character vector of length 1) | |
libraryQ <- function(pkgName){ | |
stopifnot(is.character(pkgName) && length(pkgName) == 1) | |
val <- suppressMessages( | |
suppressWarnings( | |
require(pkgName, character.only = TRUE))) | |
return(invisible(val)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment