
.onAttach = function(libname, pkgname) {
	version = utils::packageDescription(pkgname, fields = "Version")

  	msg = paste0("========================================
", pkgname, " version ", version, "
CRAN page: https://CRAN.R-project.org/package=pkgndep
Github page: https://github.com/jokergoo/pkgndep
Documentation: https://jokergoo.github.io/pkgndep/

If you use it in published research, please cite any of them:
Gu, Z. Pkgndep: a tool for analyzing dependency heaviness 
  of R packages. Bioinformatics 2022.
Gu, Z. On the dependency heaviness of CRAN/Bioconductor 
  ecosystem. Journal of Systems and Software 2023.

This message can be suppressed by:
  suppressPackageStartupMessages(library(pkgndep))
========================================
")	

    packageStartupMessage(msg)

}

#' Current Bioconductor Version
#' 
#' @details
#' The version information is from https://bioconductor.org/config.yaml
#' @export
current_bioc_version = function() {
	ln = readLines("https://bioconductor.org/config.yaml")
	ln = ln[grepl("^release_version", ln)]
	if(length(ln)) {
		bioc_version = gsub('release_version: "(\\d+\\.\\d+)"', "\\1", ln)
	} else {
		bioc_version = ""
	}
	bioc_version
}


.onLoad = function(libname, pkgname) {
	set_var()
	pkgndep_opt$bioc_version = current_bioc_version()
	ENV$lib = .libPaths()
}


set_var = function() {
	installed_tb = utils::installed.packages()
	BASE_PKGS = names(which(installed_tb[ ,"Priority"] == "base", ))
	RECOMMENDED_PKGS = names(which(installed_tb[ ,"Priority"] == "recommended", ))

	assign('BASE_PKGS', BASE_PKGS, envir = topenv())
	assign('RECOMMENDED_PKGS', RECOMMENDED_PKGS, envir = topenv())
}
