## R >= 2.8.0 passes package metadata to citation().
if( !exists('meta') || is.null(meta) ) meta <- packageDescription("NMF")

year <- sub(".*(2[[:digit:]]{3})-.*", "\\1", meta$Date, perl = TRUE)
vers <- paste("R package version", meta$Version)
author <- as.personList(meta$Author)
url <- sprintf("https://cran.r-project.org/package=%s", meta$Package)

citHeader(sprintf("To cite the package '%s' in publications use:", meta$Package))

citEntry(entry="Article"
		, title = "A flexible R package for nonnegative matrix factorization"
		, author = personList(as.person("Renaud Gaujoux"), as.person("Cathal Seoighe"))		
		, journal = "BMC Bioinformatics"
		, year = 2010
		, volume = 11
		, number = 1
		, pages = 367
		, url = "https://bmcbioinformatics.biomedcentral.com/articles/10.1186/1471-2105-11-367"
		, doi = "10.1186/1471-2105-11-367"
		, issn = "1471-2105"
		, textVersion =
				paste("Renaud Gaujoux, Cathal Seoighe (2010)"
					, "A flexible R package for nonnegative matrix factorization"
					, "BMC Bioinformatics 2010, 11:367"
					, "[https://bmcbioinformatics.biomedcentral.com/articles/10.1186/1471-2105-11-367]"
					, sep=". ")
)

citEntry(entry="Manual"
		, title = vign <- "Using the package NMF"
    	, author = author
    	, publisher = "CRAN"
    	, year = year
    	, note = vers
    	, url = url
    	, textVersion = sprintf("%s (%s). %s. CRAN. %s. [%s]", author, year, vign, vers, url)
    	, header = "Vignette(s):"
)

citEntry(entry="Manual"
		, title = "The package NMF: manual pages"
    	, author = author
    	, publisher = "CRAN"
    	, year = year
    	, note = vers
    	, url = url
    	, textVersion = sprintf("%s (%s). %s CRAN. %s. [%s]", author, year, meta$Title, vers, url)
    	, header = "Technical documentation:"
)
