Thierry,

I agree with you and think that computers _should_ help users.

When R tells me a package does not exist, it is almost never because I
typed an incorrect package name.

Almost always it is because:
(1) I am using an old script with a new version of R and have not yet
installed a package.
(2) I am running a current script on a different machine that does not have
a package installed.
(3) I am copying some code from the web and have not yet installed a
package.

MiKTeX does a nice job of auto-installing packages in a silent manner.
I've tried to imitate that with the function below.  I add this to
.Rprofile.  Then use "lib(pkg)" to install and attach packages
automatically.  The function is rough and needs improvement, but works
reasonably well.

Kevin


assign("lib",
       function(p=NULL, ...){
         # Why ... ?
         p <- substitute(p)
         if(!is.null(p) & !is.character(p))
           p <- deparse(substitute(p))
         print(p)
         ip <- rownames(installed.packages())
         # Should be more clever here and only install some of 'p'
         if(!(p %in% ip)) install.packages(p)

         require(p, ..., character.only=TRUE)
       }, env=startup)



On Wed, Oct 26, 2011 at 4:46 AM, ONKELINX, Thierry <thierry.onkel...@inbo.be
> wrote:

> Dear all,
>
> When one tries to load a non-installed package you get the error:
>
> Error in library(xyz) : there is no package called 'xyz'
>
> I noticed on several occasions that this puzzles beginners. Therefore I
> suggest to change the error description in:
>
> Error in library(xyz) : there is no package called 'xyz' installed on this
> machine. Check the name of the package or use install.packages("xyz") to
> install it.
>
> Best regards,
>
> Thierry
>
>
> ----------------------------------------------------------------------------
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek
> team Biometrie & Kwaliteitszorg
> Gaverstraat 4
> 9500 Geraardsbergen
> Belgium
>
> Research Institute for Nature and Forest
> team Biometrics & Quality Assurance
> Gaverstraat 4
> 9500 Geraardsbergen
> Belgium
>
> tel. + 32 54/436 185
> thierry.onkel...@inbo.be
> www.inbo.be
>
> To call in the statistician after the experiment is done may be no more
> than asking him to perform a post-mortem examination: he may be able to say
> what the experiment died of.
> ~ Sir Ronald Aylmer Fisher
>
> The plural of anecdote is not data.
> ~ Roger Brinner
>
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to