[R] Using the system command

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Fri Sep 12 13:48:45 CEST 2003


Suzy Smith wrote:
> Hello, I am currently taking a statistics course and we are to do a project producing a graph using multiple input files.
>  
> In R, I'm trying to build a filelist based on a pattern.  For some reason, if I do the command interactively and not assign it to an array variable I get what I thought I should, but if I do this inside my R program it chops off some file names and thinks there are two.
>  
> I looked on the R website and found that there is an 8,096 character limit when using a character array but mine chops at 119.
>  
> Here is the command:
> filelist <- system(paste("ls ", INPUTFILES, sep=""),intern=T)
>  
> Any help would be much appreciated.
>  

  I dont know why that doesn't work - it might be specific to the files 
on your system. However, R has some functions for finding files, such as 
list.files():

 > filelist <- list.files(pattern=".dat$")
 > filelist
[1] "jobacct.dat" "winmail.dat"
 >

  Get more info by typing ?list.files

  The following functions may also be useful:

file.access(base)       Ascertain File Accessibility
file.choose(base)       Choose a File Interactively
file.info(base)         Extract File Information
file.path(base)         Construct Path to File
file.show(base)         Display One or More Files

Baz




More information about the R-help mailing list