-2

Im trying to upload a dataset from .txt (tab separated file), but RStudio just do not recognize the contents.

Im wondering if it's about special encoding or something like that.

What I'm trying to upload:

enter image description here

What RSTUDIO shows:

enter image description here

library(readr)
X01172_BD03B_201902 <- read_delim("smp-22-09/01172_BD03B_201902.txt", 
    "\t", escape_double = FALSE, trim_ws = TRUE)
View(X01172_BD03B_201902)

We are using readr library.

An screenshot with console error desc:

enter image description here

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Diego Pacheco
  • 193
  • 2
  • 2
  • 10

1 Answers1

2

Use read.csv():

X01172_BD03B_201902 <- read.csv("smp-22-09/01172_BD03B_201902.txt", sep = "\t")
xwhitelight
  • 1,569
  • 1
  • 10
  • 19
  • Throw the following error: "Error in make.names(col.names, unique = TRUE) : invalid multibyte string at 'C'" – Diego Pacheco Sep 23 '20 at 04:41
  • @DiegoPacheco Save the file as UTF-8 encoding and try again. `` identify the UTF-16 encoding. R can't work with UTF-16 – xwhitelight Sep 23 '20 at 05:02
  • I've converted the file using excel/save as, but how can I automate this task? I have more than one hundred files with this little issue. – Diego Pacheco Sep 23 '20 at 05:12
  • @DiegoPacheco I don't think it's possible with R since R can't read UTF-16. You have to use another language to convert the files first. C++ can do that: use `WideCharToMultiByte()` function: https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte – xwhitelight Sep 23 '20 at 06:45