Why does my code using read_fwf() not work like in the book?

Viewed 228

I study R with R Cookbook 2nd edition. in 4.6 Reading Fixed-Width Records, I typed code as written in book. but my code doesn't work like book

Fisher    R.A.      1890 1962
Pearson   Karl      1857 1936
Cox       Gertrude  1900 1978
Yates     Frank     1902 1994
Smith     Kirstine  1878 1939

save this lines as "fixed-width.fwf" and "fixed-width.txt" both

and run code

f1 = "fixed-width.fwf"
f2 = "fixed-width.txt"

t1 <- read_fwf(f1, fwf_empty(f1, col_names = c("last", "first", "birth", "death")))

t2 <- read_fwf(f2, fwf_empty(f2, col_names = c("last", "first", "birth", "death")))

t1 and t2 both print this error message

Error: `file` must be a regular file, not a connection

sorry for my low level English

0 Answers
Related