0

I have a text file(df_copy) that has contains text a shown below

"list(list(a = "1909", v = "No sign", ved = "11"), 
list(a = "1908", v = "Yes sign", ved = "11"))" 

When I read this, it is returning backslash

> asf <- paste0(readLines("df_copy.txt"),collapse=" ")
Warning message:
In readLines("df_Copy.txt") : incomplete final line found on 'df_Copy.txt'
> asf
[1] "\"list(list(a = \"1909\", v = \"No sign\", ved = \"11\"),  list(a = \"1908\", v = \"Yes sign\", ved = \"11\"))\" "

Expected output

"list(list(a = "1909", v = "No sign", ved = "11"),  list(a = "1908", v = "Yes sign", ved = "11"))"
Vinod P
  • 89
  • 6
  • 1
    I think this is a duplicate of https://stackoverflow.com/questions/12775085/what-are-the-differences-between-concatenating-strings-with-cat-and-paste – MichaelChirico Sep 05 '20 at 18:08

1 Answers1

1

It is just the escape character for double quote. We can check with cat

cat('list(list(a = "1909", v = "No sign", ved = "11"),  list(a = "1908", v = "Yes sign", ved = "11"))')
akrun
  • 874,273
  • 37
  • 540
  • 662
  • Thanks. But i have a large file similar to the one in question. But I see there are double and 3 backslahes introduced while reading text file ````asd <- paste0(readLines("list.txt"),collapse=" ")````. When I do ````cat(asd)````, single backslashes are eliminated but there are still double and 3 backslashes. – Vinod P Sep 05 '20 at 18:57
  • @VinodP Not sure about the ultimate objective. If you need a double quoted string for some input, this should work. If it is for printing, then as showed with `cat`, the backslash is just an escape character – akrun Sep 05 '20 at 19:03