0

I am having trouble reading a .txt file with the delimiter of "xqz", using read_file or read_delim returns back "invalid 'sep' value: must be one byte".

Is this "xqz" a known delimiter that I am just unfamiliar with? This is a very large data set, and I think uses "," "." "/" " " in the data itself, I so I understand why those were not used as delimiters.

Any tips for either reading multibyte delimiters or converting to single byte delimiter?

Read_file and Read_delim with sep = "xqz"

The data has sensitive information in it so I have made a fake version:

NAMExqzPLACExqzCOLORxqzTIMExqzDIRECTIONxqzSERVICE
JIM     xqz1101xqzREDxqz1200xqzWESTxqzSurgery
RALPH   xqz2201xqzBLUxqz1201xqzNORTxqzObservation
JEAN    xqz3301xqzGRExqz1202xqzSOUTxqzMedical
slwt86
  • 1
  • 1
  • is this your issue? https://stackoverflow.com/questions/20075135/multiple-separators-for-the-same-file-input-r – mjr Apr 11 '23 at 19:31
  • Welcome to Stack Overflow. Can you please include a few rows of your data so we can understand what it looks like. – Cloudberry Apr 11 '23 at 19:31
  • 1
    you can use `strsplit` to split string by multple character separators. Can you share a few lines of data? – Ric Apr 11 '23 at 19:33
  • 1
    Can you please provide a sample of the data that can be used for testing possible solutions? – MrFlick Apr 11 '23 at 20:16

1 Answers1

0

You can consider the following approach :

library(stringr)

vec_Text <- c("NAMExqzPLACExqzCOLORxqzTIMExqzDIRECTIONxqzSERVICE",
              "JIM     xqz1101xqzREDxqz1200xqzWESTxqzSurgery",
              "RALPH   xqz2201xqzBLUxqz1201xqzNORTxqzObservation",
              "JEAN    xqz3301xqzGRExqz1202xqzSOUTxqzMedical")


fileConn <- file("output.csv")
writeLines(vec_Text, fileConn)
close(fileConn)

text <- readLines("output.csv")
text <- stringr::str_replace_all(text, "xqz", ";")

fileConn <- file("output_Mod.csv")
writeLines(text, fileConn)
close(fileConn)

text

[1] "NAME;PLACE;COLOR;TIME;DIRECTION;SERVICE" "JIM     ;1101;RED;1200;WEST;Surgery"    
[3] "RALPH   ;2201;BLU;1201;NORT;Observation" "JEAN    ;3301;GRE;1202;SOUT;Medical"
Emmanuel Hamel
  • 1,769
  • 7
  • 19