[R] detect filetype (as in unix 'file')

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Apr 4 08:06:16 CEST 2011


On Sun, 3 Apr 2011, Jeroen Ooms wrote:

> Is there a way in R (in Linux) to detect the type of a file without invoking
> a shell? E.g to do this:
>
>> system("file density.plot")
> density.plot: PDF document, version 1.4
>
> but without using system()? I tried file() and file.info(), but both do
> display the information I am looking for.

No, but what is wrong with using system()?

'file' is large and complex because it tries to be comprehensive (but 
it still does not know about some common systems, e.g. 64-bit Windows 
binaries).  There simply is no point in replicating that in R: which 
is why we chose rather to port 'file' to Windows and provide in in 
Rools.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list