[R] require vs library ( Some basic time series questions)

Paul Gilbert pgilbert902 at gmail.com
Thu Nov 17 23:49:06 CET 2016

On 11/17/2016 04:49 PM, Jeff Newmiller wrote:
>> require(tfplot)
>> tfplot(x.ts)
> Would just like to point out that require() should not be treated as
> interchangeable with library(). The former returns a logical status
> indicating success or failure, while the latter throws an error if it
> falls.  You should reserve use of require() for cases when you are
> implementing an alternative path of execution for failure, and in
> nearly all usual cases use the library() function instead so hapless
> users of your script don't have to sift through all the subsequent
> errors to figure out the problem.
Mea culpa.  Force of habit from usually writing with an alternative path 
of execution. In this example I should have used library(), especially 
since 'tfplot' may not have been installed on the user's system and so 
the library() error message would be more explicit than the warning from 
require(). But "in nearly all usual cases" seems a bit strong. It 
implies R users don't usually program much and thus do not implement an 
alternative path of execution for failure. (Some of us consider that the 
most usual case.)


More information about the R-help mailing list