0

I have a csv export of a servicedesk but some of the data enteries (in the column 'Title') have hidden line breaks in them (or so it seems). When opening the csv file in notepad++ or excel some entries cover multiple rows

example:

Number, Title, Date, User
"1","My csv file sucks help!","01-01-1990","Albert"
"2","Sometimes my title
has a hidden linebreak","01-01-1990","Ronald"
"3","Rather annoying bug present, help!", "02-01-1990","Albert"

I have attempted to gsub() \r\n in R but it did not seem to work. Any insight into the problem would be much appreciated.

Solution preferabily easily repeatable with minimal steps. The error occurs in a weekly export.

R or SQL solution would work best.

*edit

The data is correctly loaded into R, even when removig all line breaks using gsub does the export still contain line breaks

    data <- read.table(file="rawdata.csv", sep=",")
    print(data)
    
    gsub("[\r?\n|\r]", " ", data['V3'])
    
    #data exporteren
    write.table(data, file = "result.txt", quote = TRUE, sep = ",")

Even after running this code, the result.txt still contains line breaks.

even

gsub("[^[:alnum:] ]", " ", data["V3"])

does not remove the line breaks

BramV
  • 1
  • 2
  • https://stackoverflow.com/questions/30781666/r-read-csv-how-to-ignore-carriage-return – rawr Mar 15 '22 at 11:13
  • The csv file correctly imports into R, using read.table instead of read.csv does not fix the problem when then exporting the file (write.table). The hidden line breaks remain. – BramV Mar 15 '22 at 11:24
  • See linked post, try something like: `read.table("myfile.csv", header = TRUE, allowEscapes = TRUE, sep = ",")` – zx8754 Mar 15 '22 at 11:24
  • Or try `gsub("\n", " ", data)`. – Grzegorz Sapijaszko Mar 15 '22 at 15:23
  • 1
    Are you actually saving the vector back to the data frame after using `gsub`? At least in your example, you didn't. `gsub`, like many R functions, doesn't assign in place – camille Mar 16 '22 at 18:58

0 Answers0