Skip to content

Instantly share code, notes, and snippets.

@talegari
Created October 22, 2016 18:27
Show Gist options
  • Save talegari/02c7888eab9211387e5487ce0fc80b44 to your computer and use it in GitHub Desktop.
Save talegari/02c7888eab9211387e5487ce0fc80b44 to your computer and use it in GitHub Desktop.
Load a R library without cluttering the terminal
###############################################################################
#
# 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