[Rd] Suggested Patch: Library returns matching installed packages when typo present

Marcel Ramos M@rce|@R@mo@ @end|ng |rom ro@we||p@rk@org
Fri Jun 21 03:01:05 CEST 2019

Dear R-core devs,

I hope this email finds you well.

Please see the proposed patch to R-devel below:


When loading a package using `library`, a package may not be found if the cases are not matching:

> library(ORG.Hs.eg.db)
 Error in library(ORG.Hs.eg.db) :
  there is no package called 'ORG.Hs.eg.db'

Suggested Patch:

Returns a message matching what `install.packages` returns in such situations:

> library("ORG.Hs.eg.db")
 Error in library("ORG.Hs.eg.db") :
   there is no package called 'ORG.Hs.eg.db'
 In addition: Warning message:
 Perhaps you meant 'org.Hs.eg.db' ?

This patch will be helpful with 'fat-finger' typos. It will match a package
called with `library` against installed packages.

svn diff:

Index: src/library/base/R/library.R
--- src/library/base/R/library.R    (revision 76727)
+++ src/library/base/R/library.R    (working copy)
@@ -300,8 +300,13 @@
         pkgpath <- find.package(package, lib.loc, quiet = TRUE,
                                     verbose = verbose)
             if(length(pkgpath) == 0L) {
-                if(length(lib.loc) && !logical.return)
+                if(length(lib.loc) && !logical.return) {
+                    allpkgs <- .packages(TRUE, lib.loc)
+                    if (!is.na(w <- match(tolower(package), tolower(allpkgs))))
+                        warning(sprintf("Perhaps you meant %s ?",
+                            sQuote(allpkgs[w])), call. = FALSE, domain = NA)
                     stop(packageNotFoundError(package, lib.loc, sys.call()))
+                }
                 txt <- if(length(lib.loc))
                     gettextf("there is no package called %s", sQuote(package))

Thank you!

Best regards,


Marcel Ramos
Bioconductor Core Team
Roswell Park Comprehensive Care Center
Dept. of Biostatistics & Bioinformatics
Elm & Carlton Streets
Buffalo, New York 14263

This email message may contain legally privileged and/or confidential information.  If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited.  If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you.
	[[alternative HTML version deleted]]

More information about the R-devel mailing list