Can't write '\n' in an sql statement using Rmysql

Hello, i'm having trouble with Rmysql.
Here is my line of code which is not working, i want to send this request, annee_court is just a variable :
sql=paste0("REPLACE INTO TABLE donstat_fr.com_insee_revenus",annee_court,"_s CHARACTER SET 'latin1' FIELDS ESCAPED BY '\' TERMINATED BY '\t' LINES TERMINATED BY '\r\n' IGNORE 1 LINES")

When i do dbExecute or dbquery etc..., the problem is that '\r\n' and '\t' is acting like my request be :
REPLACE INTO TABLE donstat_fr.com_insee_revenus",annee_court,"_s CHARACTER SET 'latin1' FIELDS ESCAPED BY '\' TERMINATED BY ' ' LINES TERMINATED BY '
' IGNORE 1 LINES

I think i found an answer, i have to do "'","\","r","\","n","'",".
But is still got some bugs, can't we just do a verbatim of R in mysql ?

Can you try using the following string?

paste0("REPLACE INTO TABLE donstat_fr.com_insee_revenus",annee_court,"_s CHARACTER SET 'latin1' FIELDS ESCAPED BY '\' TERMINATED BY '\\t' LINES TERMINATED BY '\\r\\n' IGNORE 1 LINES")

\t, \r, and \n might be removed since \ is an escape character, so \\ will un-escape the escape.

1 Like

Just a little presition, \\ will not un-escape the escape, it is going to escape the control characters (i.e. \n : line feed, \r : carriage return and \t : horizontal tabulation).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.