From jeff.horner at vanderbilt.edu  Wed Sep 13 17:31:01 2006
From: jeff.horner at vanderbilt.edu (Jeffrey Horner)
Date: Wed, 13 Sep 2006 10:31:01 -0500
Subject: [Rd] Error: package/namespace load failed for 'fortunes'
In-Reply-To: <4507C7A2.3080708@bfro.uni-lj.si>
References: <4507C7A2.3080708@bfro.uni-lj.si>
Message-ID: <45082435.2080400@vanderbilt.edu>

Gregor Gorjanc wrote:
> Hello!
> 
> I have the following R code in my .Rprofile file - just for fun.
> 
>   library(fortunes)
>   fortune()
>   detach("package:fortunes")
> 
> This works nicely in R 2.3.1, but it throws the following error under
> latest R-devel:
> 
> ...
> ...
> Type 'demo()' for some demos, 'help()' for on-line help, or
> 'help.start()' for an HTML browser interface to help.
> Type 'q()' to quit R.
> 
> Error in rbind(rval, read.table(file, header = TRUE, sep = ";", quote =
> "\"",  :
>         could not find function "read.table"
> Error: .onLoad failed in 'loadNamespace' for 'fortunes'
> Error: package/namespace load failed for 'fortunes'
> 
> If I start R-devel with empty .Rprofile I am able to issue above R code
> without problems. Is this caused by move of read.table() to utils package?

Your intuition was right. Just add library(utils) before 
library(fortunes), and it works. Your .Rprofile is executed before 
.First.sys() (which loads default packages) in base package.

?Startup explains it all.

This raises an interesting topic for me:

  In R-2.3.1, .First.sys() autloads() a few functions from the various 
default packages (utils, stats, methods, graphics) IF those packages 
weren't specified in the default packages option (or the environment 
variable R_DEFAULT_PACKAGES). For instance, if a user doesn't want the 
utils package automatically loaded, then .First.sys() does this:

     sch <- search()
     if(! "package:utils" %in% sch) {
         autoload("example", "utils")
         autoload("methods", "utils")
         autoload("str", "utils")
     }

which will automagically load utils if a call to example, methods, or 
str is made (why just those three? why not others in utils). I presume 
there was some heuristic to determine exactly which functions were 
autoloaded.

Now in R-trunk today, I see that there are no autloaded functions set up 
from .First.sys() for any of the default packages. So if R is started 
with R_DEFAULT_PACKAGES=NULL, then no default packages will be loaded 
and no functions will be set up via autoload(). Why?

Jeff
-- 
http://biostat.mc.vanderbilt.edu/JeffreyHorner




[Rd] Error: package/namespace load failed for 'fortunes'
Jeffrey Horner