[Rd] [R] help with read.table() function

Duncan Murdoch murdoch at stats.uwo.ca
Sun Jan 29 22:35:50 CET 2006


On 1/29/2006 1:29 PM, Prof Brian Ripley wrote:
> On Sun, 29 Jan 2006, Marc Schwartz wrote:
> 
>> I would argue against this.
>>
>> If this were the default, that is requiring user interaction, it would
>> break a fair amount of code that I (and I am sure a lot of others have)
>> where automation is critical.
> 
> I don't see how.  The current default is
> 
>> read.table()
> Error in read.table() : argument "file" is missing, with no default
> 
> so the only change is that the default might do something useful.
> 
> Nor do I see the change would help, as the same people would still use a 
> character string for 'file' and not omit the argument.  (It seems very 
> unlikely that they would read any documentation that suggested things had 
> changed.)

No, but people teaching new users (or answering R-help questions) would 
have a simpler answer:  just use read.table().

> The same issue could be made over scan(), where the current default is 
> useful.

scan() is very useful for small reads, and rarely needed for reading big 
formatted files, so I wouldn't propose to change it.  The inconsistency 
with read.table would be unfortunate, but no worse than the current one.

>> A lot of the issues seem to be user errors, file permission errors,
>> hidden extensions as is pointed out below and related issues. If there
>> is a legitimate bug in R resulting in these issues, then let's patch
>> that. However, I don't think that I can recall reproducible situations
>> where a bug in R is the root cause of these problems.
> 
> Nor I.
> 
> Note that file.choose does not protect you against file permission issues 
> (actually, on a command-line Unix-alike it does nothing much useful at 
> all):
> 
>> readLines(file.choose())
> Enter file name: errs.txt

No, it's not helpful here, but again it makes things no worse, and 
there's always the possibility that someone would improve file.choose().

Duncan Murdoch

> Error in file(con, "r") : unable to open connection
> In addition: Warning message:
> cannot open file 'errs.txt', reason 'Permission denied'
> 
> but
> 
>> file.show(file.choose())
> says
> 
> NO FILE errs.txt
> 
> which is not a good idea (and I will improve).
> 
> So this would really only have any effect on GUI platforms, for people who 
> read the documentation.
> 
> 
>> Best regards,
>>
>> Marc Schwartz
>>
>> On Sun, 2006-01-29 at 12:18 -0500, Duncan Murdoch wrote:
>>> (Moved from R-help).
>>>
>>> This comes up often enough that I'm starting to think most functions
>>> that take filename arguments should have file.choose() as the default
>>> value.  Then one could do
>>>
>>> read.table()
>>>
>>> and have a dialog box pop up in Windows, or some other prompt for a
>>> filename in other platforms.  Are there any obviously bad side effects
>>> from a change like this?
>>>
>>> Duncan Murdoch
>>>
>>> On 1/29/2006 11:51 AM, Peter Dalgaard wrote:
>>>> Romain Francois <francoisromain at free.fr> writes:
>>>>
>>>>> Le 29.01.2006 16:26, oliver wee a écrit :
>>>>>
>>>>>> hello, I have just started using R for doing a project
>>>>>> in time series...
>>>>>>
>>>>>> unfortunately, I am having trouble using the
>>>>>> read.table function for use in reading my data set.
>>>>>>
>>>>>> This is what I'm getting:
>>>>>> I inputted:
>>>>>> data <-
>>>>>> read.table("D:/Oliver/Professional/Studies/Time Series
>>>>>> Analysis/spdc2693.data", header = TRUE)
>>>>>>
>>>>>> I got:
>>>>>> Error in file(file, "r") : unable to open connection
>>>>>> In addition: Warning message:
>>>>>> cannot open file 'D:/Oliver/Professional/Studies/Time
>>>>>> Series Analysis/spdc2693.data', reason 'No such file
>>>>>> or directory'
>>>>>>
>>>>>> as I am just a novice programmer, I really would
>>>>>> appreciate help from you guys. Is there a need to
>>>>>> setpath in R, like in java or something like that...
>>>>>>
>>>>>> I am using the windows version btw.
>>>>>>
>>>>>> I have also tried to put the file in the work
>>>>>> directory of R, so that I only typed
>>>>>> data <- read.table("spdc2693.data", header = TRUE)
>>>>>> Again, it won't work, with the same error message.
>>>>>>
>>>>>> I would appreciate any help. thanks again.
>>>>>>
>>>>>>
>>>>> Hi, try :
>>>>>
>>>>> read.table(file.choose(), header=TRUE)
>>>>>
>>>>> and go to your file.
>>>>> Also, you can look a ?setwd, ?getwd
>>>> Right. Or just file.choose() and see what the OS thinks your file is
>>>> really called. The most common causes for symptoms like that are
>>>>
>>>> (A) The file is "spcd2693.data"
>>>> (B) There's an extra extension which ever helpful Windows decided to
>>>> hide, as in "spdc2693.data.txt".
>>>>
>>>>
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>



More information about the R-devel mailing list