0

I am trying to export parts of dataframe in r into .txt file, using rio::export the exported part is a text string that contains some characters as >, ≥ and ", some of these show in the text file as < " or > which is not what I need ( I want them to transfer into the text as greater than or less than, etc...). when I looked these up online, I found these to be "html special characters" but I could not find a solution. I believe it has something to do with the encoding. is there a way to fix that by adding arguments to rio::export or do you suggest using other package?

I am using the code:

rio::export(df, "df.txt")

I also tried the following from this question but still gives the same problem How to save R output data to a text file

cat(df$text, file = "myfile.txt") where df$text is the column that has the items I want to export.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Bahi8482
  • 489
  • 5
  • 15
  • I created the following tibble and it worked just fine with me. It exported them the way they are written. I am using a Mac.`df <- tibble( text_1 = "hello there, 5 > 4", text_2 = "print 5 if 5 ≥ value" ) rio::export(df,"1.txt")` – Moh Oct 28 '20 at 04:30
  • @Moh thanks for replying. I tried to make a reproducible example but I found that it worded too. but I still have problems with my data, for example "(24.8 vs 31.7 and 52.4 minutes, respectively; P < 0.001)." exports as "(24.8 vs 31.7 and 52.4 minutes, respectively; P < 0.001). " – Bahi8482 Oct 28 '20 at 04:37
  • hello @ Bahi8482. I tried the text you have just shared and it worked just fine with me. No `&lt` in the output. Have you tried to read the file back to R and see how it looks. also, have you tried to open the exported text file with different text editors. – Moh Oct 28 '20 at 07:24
  • @Moh The error still happens when I import the file to r and export again! actually I was working on rstudio cloud but when I tried on the installed version, I do not see the error anymore! – Bahi8482 Oct 30 '20 at 01:56

0 Answers0