From simon.urbanek at r-project.org  Thu Jan 14 21:33:30 2010
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 14 Jan 2010 15:33:30 -0500
Subject: [Rd] Wishlist: system.file(... package) throw an error if
	package not installed/path not found
In-Reply-To: <59d7961d1001141201t577e6196l24a654bea6e06136@mail.gmail.com>
References: <59d7961d1001141201t577e6196l24a654bea6e06136@mail.gmail.com>
Message-ID: <19AF295E-1BDD-49AE-9ADA-2AD24B26F75E@r-project.org>


On Jan 14, 2010, at 15:01 , Henrik Bengtsson wrote:

> Currently, system.file() on a non-existing package returns an empty  
> string:
>
> path <- system.file(package="foo");
> print(path);
> [1] ""
>
> The same goes for non-existing paths in existing package directories:
>
> path <- system.file("foo", package="base");
> print(path);
> [1] ""
>
> Is there a rationale for this, or is it just for historical reasons?
> Is the empty string "" used in R to represent a "missing" file?  (e.g.
> file.exists("") == FALSE).
>
> I would like to suggest that an error is thrown instead, so that it is
> caught as soon as possible and not down stream.
>

I cannot answer for the original author, but throwing an error is  
generally a very bad idea since it defeats the vectorization. It is  
much easier to simply use if(nzchar(system.file(...))) if you want to  
throw an error in a scalar context than to lose all results because of  
one vector entry. And, yes, file.exists("") will indeed return FALSE  
(although it is entirely unrelated).

Cheers,
Simon



[Rd] Wishlist: system.file(... package) throw an error if package not installed/path not found
Simon Urbanek