[R] Reading Text files from UK Met Office into R again...

Ivan Krylov
Sun, 09 Oct 2022 15:50:41 -0000

On Sun, 9 Oct 2022 12:01:27 +0100
Nick Wray <nickmwray at gmail.com> wrote:

> Error in read.table("midas_wxhrly_201501-201512.txt", fill = T) :
>   duplicate 'row.names' are not allowed

Since you don't pass the `header` argument, I think that the automatic
header detection is here at play. This is what ?read.table has to say
about row names:

>> If there is a header and the first row contains one fewer field than
>> the number of columns, the first column in the input is used for the
>> row names.  Otherwise if ?row.names? is missing, the rows are
>> numbered.

Perhaps the "one fewer field in the header than the number of columns"
condition is true for files after 2010? I'm too lazy to sign up for a
CEDA account and I'm not sure I'd be given access to hourly datasets
anyway.

If this is the reason for the failure (first column used as rownames()
and turns out to be non-unique), there's an easy way to fix that:

>> Using ?row.names = NULL? forces row numbering.

I don't see a header in your example. If there's actually no header
containing column names, passing `header = FALSE` will both prevent the
error and avoid eating the first line of the file.

--
Best regards,
Ivan