[R] Reading a txt file from internet
Enrico Schumann
e@ @end|ng |rom enr|co@chum@nn@net
Sat Sep 7 22:22:23 CEST 2024
On Sun, 08 Sep 2024, Christofer Bogaso writes:
> Hi,
>
> I am trying to the data from
> https://online.stat.psu.edu/onlinecourses/sites/stat501/files/ch15/employee.txt
> without any success. Below is the error I am getting:
>
>> read.delim('https://online.stat.psu.edu/onlinecourses/sites/stat501/files/ch15/employee.txt')
>
> Error in make.names(col.names, unique = TRUE) :
>
> invalid multibyte string at '<ff><fe>t'
>
> In addition: Warning messages:
>
> 1: In read.table(file = file, header = header, sep = sep, quote = quote, :
>
> line 1 appears to contain embedded nulls
>
> 2: In read.table(file = file, header = header, sep = sep, quote = quote, :
>
> line 2 appears to contain embedded nulls
>
> 3: In read.table(file = file, header = header, sep = sep, quote = quote, :
>
> line 3 appears to contain embedded nulls
>
> 4: In read.table(file = file, header = header, sep = sep, quote = quote, :
>
> line 4 appears to contain embedded nulls
>
> 5: In read.table(file = file, header = header, sep = sep, quote = quote, :
>
> line 5 appears to contain embedded nulls
>
> Is there any way to read this data directly onto R?
>
> Thanks for your time
>
The <ff><fe> looks like a byte-order mark
(https://en.wikipedia.org/wiki/Byte_order_mark).
Try this:
fn <- file('https://online.stat.psu.edu/onlinecourses/sites/stat501/files/ch15/employee.txt',
encoding = "UTF-16LE")
read.delim(fn)
--
Enrico Schumann
Lucerne, Switzerland
https://enricoschumann.net
More information about the R-help
mailing list